From 0d4b47e52ef9b044cb2f83143ab9473a0b1615ff Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 13:48:48 -0500 Subject: [PATCH 01/90] Hours of operation widget. --- assets/css/admin.css | 36 ++++++ assets/css/admin.min.css | 2 +- assets/js/admin.js | 17 +++ assets/js/admin.min.js | 2 +- contact-widgets.php | 2 +- includes/class-base-widget.php | 89 ++++++++++++++ includes/class-hours.php | 204 +++++++++++++++++++++++++++++++++ includes/class-plugin.php | 1 + package.json | 2 +- readme.md | 4 +- readme.txt | 2 +- 11 files changed, 354 insertions(+), 7 deletions(-) create mode 100644 includes/class-hours.php diff --git a/assets/css/admin.css b/assets/css/admin.css index 7584bcd..142ba7d 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -93,3 +93,39 @@ .wpcw-widget-social .icons a.inactive:not(:hover) { color: #ccc; } + +/** + * Hours of Operation Widget + */ +.wphoow-widget .form div { + display: inline-block; + width: 100%; + margin-bottom: 8px; +} + + .wphoow-widget .form label + div { + margin-top: 8px; + } + + .wphoow-widget .day-checkbox-toggle { + float: right; + } + +.wphoow-widget input[type="checkbox"] { + transform: scale( 0.75 ); + margin-right: 2px; +} + +.wphoow-widget select { + width: 49%; + min-width: auto; + float: left; + margin-bottom: 8px; +} + +.wphoow-widget .form div p, +body.widgets-php .wphoow-widget .form div p { + display: inline-block; + width: 100%; + margin: 0; +} diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index eb25d7e..8bbfb7f 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wphoow-widget .form div{display:inline-block;width:100%;margin-bottom:8px}.wphoow-widget .form label+div{margin-top:8px}.wphoow-widget .day-checkbox-toggle{float:right}.wphoow-widget input[type=checkbox]{transform:scale(.75);margin-right:2px}.wphoow-widget select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wphoow-widget .form div p,body.widgets-php .wphoow-widget .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index 3146e04..fd94590 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -166,6 +166,23 @@ // Social $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); + // Hours of Operation select field toggle + $( 'body' ).on( 'change', '.js_wphoow_closed_checkbox', function( e ) { + + var select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); + + if ( $( this ).is( ':checked' ) ) { + + select_fields.attr( 'disabled', 'disabled' ); + + return; + + } + + select_fields.removeAttr( 'disabled' ); + + } ); + // Sortable $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index cf4c018..a811858 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/contact-widgets.php b/contact-widgets.php index e66911d..2256e86 100644 --- a/contact-widgets.php +++ b/contact-widgets.php @@ -2,7 +2,7 @@ /** * Plugin Name: Contact Widgets * Description: Beautifully display social media and contact information on your website with these simple widgets. - * Version: 1.3.3 + * Version: 1.3.4 * Author: GoDaddy * Author URI: https://godaddy.com * Text Domain: contact-widgets diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index d2bfc1c..0530c4e 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -396,6 +396,95 @@ protected function render_form_textarea( array $field ) { } + /** + * Render the 'Day' div and select fields + * + * @param array $field Field data + * @param array $day The current day in the iteration. + * @param array $hours The array of times. + * + * @since 1.0.0 + * + * @return mixed + */ + protected function render_day_input( $field, $day, array $hours ) { + + $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); + + $field['disabled'] = ( $hours['not_open'] ) ? true : false; + + printf( + '
%1$s

%2$s

', + '' . esc_html( ucwords( $day ) ) . 'checked( $hours['not_open'], true ) . '>', + $this->render_hours_selection( $field, sanitize_title( $day ), $hours ) + ); + + } + + /** + * Render the 'Hours' select fields + * + * @param array $field Field data + * @param array $day The current day in the iteration. + * @param array $hours The array of times. + * + * @since 1.0.0 + * + * @return mixed + */ + protected function render_hours_selection( $field, $day, $hours ) { + + ob_start(); + + $times = $this->get_half_hour_time_array(); + + $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); + + $disabled_field = $field['disabled'] ? ' disabled="disabled"' : ''; + + echo ''; + + echo ''; + + return ob_get_clean(); + + } + + /** + * Generate an array of times in half hour increments + * + * @since 1.0.0 + * + * @return array Array of times to choose from, in half hour increments. + */ + protected function get_half_hour_time_array() { + + $half_hour_steps = range( 0, 47 * 1800, 1800 ); + + return array_map( function ( $time ) { + + return date( get_option( 'time_format' ), $time ); + + }, $half_hour_steps ); + + } + /** * Close wrapper of form field * diff --git a/includes/class-hours.php b/includes/class-hours.php new file mode 100644 index 0000000..845e368 --- /dev/null +++ b/includes/class-hours.php @@ -0,0 +1,204 @@ + 'wpcw-widgets wpcw-widget-hours', + 'description' => __( 'Display your hours of operation.', 'contact-widgets' ), + 'customize_selective_refresh' => true, + ]; + + parent::__construct( + 'wpcw_hours', + __( 'Hours of Operation', 'contact-widgets' ), + $widget_options + ); + + } + + /** + * Widget form fields + * + * @param array $instance The widget options + * + * @return string|void + */ + public function form( $instance ) { + + parent::form( $instance ); + + $fields = $this->get_fields( $instance ); + + echo '
'; + + echo '
'; + + // Title field + $this->render_form_input( array_shift( $fields ) ); + + echo '
'; + + echo '
'; + + foreach ( $fields as $key => $field ) { + + if ( 'days' === $key ) { + + parent::print_label( $field ); + + foreach ( $field['days'] as $day => $hours ) { + + $this->render_day_input( $fields['days'], $day, $hours ); + + } + } + } + + // Workaround customizer refresh @props @westonruter + echo ''; + + echo '
'; // End form + + echo '
'; // End wphoow-widget-hours + + } + + /** + * Front-end display + * + * @param array $args + * @param array $instance + */ + public function widget( $args, $instance ) { + + $fields = $this->get_fields( $instance ); + + if ( $this->is_widget_empty( $fields ) ) { + + return; + + } + + $this->before_widget( $args, $fields ); + + foreach ( $fields as $field ) { + + $label = $field['label']; + + if ( isset( $field['days'] ) ) { + + foreach ( $field['days'] as $day_of_week => $store_hours ) { + + $hours = ( $store_hours['not_open'] ) ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . ' - ' . $store_hours['closed']; + + $class = ( $store_hours['not_open'] ) ? 'closed' : 'open'; + + printf( + '
  • %s
    %s
  • ', + '' . esc_html( ucwords( $day_of_week ) ) . '', + '
    ' . esc_html( $hours ) . '
    ' + ); + + } + } + } + + $this->after_widget( $args, $fields ); + + } + + /** + * Initialize fields for use on front-end of forms + * + * @param array $instance + * @param array $fields + * @param bool $ordered + * + * @return array + */ + protected function get_fields( array $instance, array $fields = [], $ordered = true ) { + + $fields = [ + 'title' => [ + 'label' => __( 'Title:', 'contact-widgets' ), + 'description' => __( 'The title of this widget. Leave empty for no title.', 'contact-widgets' ), + 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', + 'sortable' => false, + ], + 'days' => [ + 'label' => __( 'Days of the week:', 'contact-widgets' ), + 'description' => __( 'Enter your hours in the following fields.', 'contact-widgets' ), + ], + ]; + + foreach ( $this->get_days_of_week() as $day ) { + + $day = strtolower( $day ); + + $fields['days']['days'][ $day ] = [ + 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', + 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', + 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, + ]; + + } + + $fields = apply_filters( 'wphoow_widget_contact_custom_fields', $fields, $instance ); + $fields = parent::get_fields( $instance, $fields ); + + /** + * Filter the contact fields + * + * @since 1.0.0 + * + * @var array + */ + return (array) apply_filters( 'wphoow_widget_contact_fields', $fields, $instance ); + + } + + /** + * Return an array of days of the week + * + * @return array + */ + public function get_days_of_week() { + + $start_of_week = get_option( 'start_of_week', 1 ); + + $days_of_the_week = [ + __( 'Monday', 'contact-widgets' ), + __( 'Tuesday', 'contact-widgets' ), + __( 'Wednesday', 'contact-widgets' ), + __( 'Thursday', 'contact-widgets' ), + __( 'Friday', 'contact-widgets' ), + __( 'Saturday', 'contact-widgets' ), + __( 'Sunday', 'contact-widgets' ), + ]; + + if ( 1 < $start_of_week ) { + + $array_end = array_splice( $days_of_the_week, ( $start_of_week - 1 ) ); + + return array_merge( $array_end, $days_of_the_week ); + + } + + return $days_of_the_week; + + } + +} diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 3988e3b..6cb7bfd 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -32,6 +32,7 @@ public static function init() { public static function register_widgets() { register_widget( __NAMESPACE__ . '\Contact' ); + register_widget( __NAMESPACE__ . '\Hours' ); register_widget( __NAMESPACE__ . '\Social' ); } diff --git a/package.json b/package.json index 4b74856..be80745 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "contact-widgets", "title": "Contact Widgets", "description": "Beautifully display social media and contact information on your website with these simple widgets.", - "version": "1.3.3", + "version": "1.3.4", "author": "GoDaddy", "license": "GPL-2.0", "repository": "godaddy/wp-contact-widgets", diff --git a/readme.md b/readme.md index f0039b1..068af89 100644 --- a/readme.md +++ b/readme.md @@ -7,8 +7,8 @@ Beautifully display social media and contact information on your website with th **Contributors:** [godaddy](https://profiles.wordpress.org/godaddy), [jonathanbardo](https://profiles.wordpress.org/jonathanbardo), [fjarrett](https://profiles.wordpress.org/fjarrett) **Tags:** [widget](https://wordpress.org/plugins/tags/widget), [contact](https://wordpress.org/plugins/tags/contact), [social](https://wordpress.org/plugins/tags/social), [sharing](https://wordpress.org/plugins/tags/sharing), [share button](https://wordpress.org/plugins/tags/share button), [share buttons](https://wordpress.org/plugins/tags/share buttons), [share links](https://wordpress.org/plugins/tags/share links), [social icons](https://wordpress.org/plugins/tags/social icons), [social media](https://wordpress.org/plugins/tags/social media), [facebook](https://wordpress.org/plugins/tags/facebook), [twitter](https://wordpress.org/plugins/tags/twitter), [google plus](https://wordpress.org/plugins/tags/google plus), [instagram](https://wordpress.org/plugins/tags/instagram) **Requires at least:** 4.4.2 -**Tested up to:** 4.6 -**Stable tag:** 1.3.3 +**Tested up to:** 4.7 +**Stable tag:** 1.3.4 **License:** [GPL-2.0](https://www.gnu.org/licenses/gpl-2.0.html) [![Build Status](https://travis-ci.org/godaddy/wp-contact-widgets.svg?branch=master)](https://travis-ci.org/godaddy/wp-contact-widgets) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) diff --git a/readme.txt b/readme.txt index ba03dd8..04349da 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: godaddy, jonathanbardo, fjarrett Tags: widget, contact, social, sharing, share button, share buttons, share links, social icons, social media, facebook, twitter, google plus, instagram Requires at least: 4.4.2 Tested up to: 4.7 -Stable tag: 1.3.3 +Stable tag: 1.3.4 License: GPL-2.0 License URI: https://www.gnu.org/licenses/gpl-2.0.html From 161f710718d3d1593407d82652421f458ac91a77 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 14:03:30 -0500 Subject: [PATCH 02/90] Refactor. --- includes/class-base-widget.php | 10 +++++----- includes/class-hours.php | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 0530c4e..2b7eab4 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -403,7 +403,7 @@ protected function render_form_textarea( array $field ) { * @param array $day The current day in the iteration. * @param array $hours The array of times. * - * @since 1.0.0 + * @since NEXT * * @return mixed */ @@ -428,7 +428,7 @@ protected function render_day_input( $field, $day, array $hours ) { * @param array $day The current day in the iteration. * @param array $hours The array of times. * - * @since 1.0.0 + * @since NEXT * * @return mixed */ @@ -469,9 +469,9 @@ protected function render_hours_selection( $field, $day, $hours ) { /** * Generate an array of times in half hour increments * - * @since 1.0.0 + * @since NEXT * - * @return array Array of times to choose from, in half hour increments. + * @return array */ protected function get_half_hour_time_array() { @@ -488,7 +488,7 @@ protected function get_half_hour_time_array() { /** * Close wrapper of form field * - * @param array $field + * @param array */ protected function after_form_field( array $field ) { diff --git a/includes/class-hours.php b/includes/class-hours.php index 845e368..d7a67c6 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -162,7 +162,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t /** * Filter the contact fields * - * @since 1.0.0 + * @since NEXT * * @var array */ @@ -191,9 +191,7 @@ public function get_days_of_week() { if ( 1 < $start_of_week ) { - $array_end = array_splice( $days_of_the_week, ( $start_of_week - 1 ) ); - - return array_merge( $array_end, $days_of_the_week ); + return array_merge( array_splice( $days_of_the_week, ( $start_of_week - 1 ) ), $days_of_the_week ); } From 2b6d3981ec755aeeef42640a8fcf440250b1f3c9 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 16:03:01 -0500 Subject: [PATCH 03/90] Add wpcw_hours_seperator filter to allow users to adjust the divider between open and close times. --- includes/class-hours.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index d7a67c6..929e0d9 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -102,7 +102,7 @@ public function widget( $args, $instance ) { foreach ( $field['days'] as $day_of_week => $store_hours ) { - $hours = ( $store_hours['not_open'] ) ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . ' - ' . $store_hours['closed']; + $hours = ( $store_hours['not_open'] ) ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; $class = ( $store_hours['not_open'] ) ? 'closed' : 'open'; From b61adc7a34f7e5a6143e65ba12f8f648297b44dc Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 17:17:37 -0500 Subject: [PATCH 04/90] Refactors, tweaks, new styles, adjusted script, ability to copy across all days, tweaks per @jbardos comments. --- assets/css/admin.css | 21 +++++++++++------ assets/css/admin.min.css | 2 +- assets/js/admin.js | 27 +++++++++++++++++++++ assets/js/admin.min.js | 2 +- includes/class-base-widget.php | 43 +++++++++++++++++++++++++--------- includes/class-hours.php | 4 ++-- 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 142ba7d..7834c73 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -97,34 +97,41 @@ /** * Hours of Operation Widget */ -.wphoow-widget .form div { +.wpcw-widget-hours .form div { display: inline-block; width: 100%; margin-bottom: 8px; } - .wphoow-widget .form label + div { + .wpcw-widget-hours .form label + div { margin-top: 8px; } - .wphoow-widget .day-checkbox-toggle { + .wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons { + position: relative; + color: inherit; + text-decoration: inherit; + font-size: 12px; + margin-left: -5px; + } + + .wpcw-widget-hours .day-checkbox-toggle { float: right; } -.wphoow-widget input[type="checkbox"] { +.wpcw-widget-hours input[type="checkbox"] { transform: scale( 0.75 ); margin-right: 2px; } -.wphoow-widget select { +.wpcw-widget-hours select { width: 49%; min-width: auto; float: left; margin-bottom: 8px; } -.wphoow-widget .form div p, -body.widgets-php .wphoow-widget .form div p { +.wpcw-widget-hours .form div p { display: inline-block; width: 100%; margin: 0; diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 8bbfb7f..7d928f6 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wphoow-widget .form div{display:inline-block;width:100%;margin-bottom:8px}.wphoow-widget .form label+div{margin-top:8px}.wphoow-widget .day-checkbox-toggle{float:right}.wphoow-widget input[type=checkbox]{transform:scale(.75);margin-right:2px}.wphoow-widget select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wphoow-widget .form div p,body.widgets-php .wphoow-widget .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:12px;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index fd94590..e13f55d 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -183,6 +183,33 @@ } ); + $( 'body' ).on( 'click', '.js_wpcw_apply_hours_to_all', function( e ) { + + var store_closed = false; + + if ( $( this ).next().is( ':checked' ) ) { + + $( '.wpcw-widget-hours .day-container' ).find( 'select' ).attr( 'disabled', 'disabled' ); + $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input[type="checkbox"]' ).prop( 'checked', true ); + e.preventDefault(); + + return; + + } + + var first_container = $( this ).parents( '.day-container' ), + open = first_container.find( 'select:first-child' ).val(), + closed = first_container.find( 'select:nth-child(2)' ).val(); + + $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input[type="checkbox"]' ).prop( 'checked', false ); + $( '.wpcw-widget-hours .day-container' ).find( 'select' ).removeAttr( 'disabled' ); + $( '.wpcw-widget-hours .day-container' ).find( 'select:first-child' ).val( open ); + $( '.wpcw-widget-hours .day-container' ).find( 'select:nth-child(2)' ).val( closed ); + + e.preventDefault(); + + } ); + // Sortable $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index a811858..cf3a030 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).next().is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 2b7eab4..2f453d1 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -397,9 +397,9 @@ protected function render_form_textarea( array $field ) { } /** - * Render the 'Day' div and select fields + * Render the hours container and select fields * - * @param array $field Field data + * @param array $field Field data. * @param array $day The current day in the iteration. * @param array $hours The array of times. * @@ -409,13 +409,14 @@ protected function render_form_textarea( array $field ) { */ protected function render_day_input( $field, $day, array $hours ) { - $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); + $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); + $field['disabled'] = $hours['not_open'] ? true : false; - $field['disabled'] = ( $hours['not_open'] ) ? true : false; + $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . sprintf( _x( 'Apply to All %s', 'Dashicon Down Arrow', 'contact-widgets' ), '' ) . '' : ''; printf( '
    %1$s

    %2$s

    ', - '' . esc_html( ucwords( $day ) ) . 'checked( $hours['not_open'], true ) . '>', + '' . esc_html( ucwords( $day ) ) . '' . $apply_to_all_toggle . 'checked( $hours['not_open'], true ) . '>', $this->render_hours_selection( $field, sanitize_title( $day ), $hours ) ); @@ -442,25 +443,45 @@ protected function render_hours_selection( $field, $day, $hours ) { $disabled_field = $field['disabled'] ? ' disabled="disabled"' : ''; - echo '> + + ' . $time . ''; + ?> + + + + '; + ?> + + - echo '> + + ' . $time . ''; + ?> + + + + '; + ?> + + + + get_fields( $instance ); - echo '
    '; + echo '
    '; echo '
    '; @@ -72,7 +72,7 @@ public function form( $instance ) { echo '
    '; // End form - echo '
    '; // End wphoow-widget-hours + echo '
    '; // End wpcw-widget-hours } From f4f8b2fb024fc44c892cd5d213e56c30e4ea0314 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 18:07:16 -0500 Subject: [PATCH 05/90] Add microformat to open/close times. --- includes/class-hours.php | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 8b08002..2464339 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -96,24 +96,31 @@ public function widget( $args, $instance ) { foreach ( $fields as $field ) { - $label = $field['label']; - if ( isset( $field['days'] ) ) { foreach ( $field['days'] as $day_of_week => $store_hours ) { - $hours = ( $store_hours['not_open'] ) ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; + $hours = $store_hours['not_open'] ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; + $class = $store_hours['not_open'] ? 'closed' : 'open'; - $class = ( $store_hours['not_open'] ) ? 'closed' : 'open'; + $microformat_data = array( + 'day' => $day_of_week, + 'open' => $store_hours['open'], + 'close' => $store_hours['closed'], + 'not_open' => $store_hours['not_open'], + ); printf( - '
  • %s
    %s
  • ', + '
  • %2$s
    %3$s
  • ', + $this->get_microformat_markup( $microformat_data ), '' . esc_html( ucwords( $day_of_week ) ) . '', '
    ' . esc_html( $hours ) . '
    ' ); } + } + } $this->after_widget( $args, $fields ); @@ -199,4 +206,35 @@ public function get_days_of_week() { } + /** + * Generate the opening hours microformat markup + * @link https://schema.org/openingHours + * + * @since NEXT + * + * @param array $microformat_data Microformat data array. + * + * @return string + */ + protected function get_microformat_markup( $microformat_data ) { + + if ( $microformat_data['not_open'] ) { + + return; + + } + + $day = ucwords( substr( $microformat_data['day'], 0, 2 ) ); + $open = date( 'H:i', strtotime( $microformat_data['open'] ) ); + $close = date( 'H:i', strtotime( $microformat_data['close'] ) ); + + $microformat_attributes = array( + 'itemprop="openingHours"', + 'datetime="' . esc_attr( $day . ' ' . $open . '-' . $close ) . '"', + ); + + return implode( ' ', $microformat_attributes ); + + } + } From 19e194ad0c8a7a6bdae164b6191f0d8c74ba5f6b Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 18:10:58 -0500 Subject: [PATCH 06/90] Fix array formatting. --- includes/class-hours.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 2464339..6950789 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -103,12 +103,12 @@ public function widget( $args, $instance ) { $hours = $store_hours['not_open'] ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; $class = $store_hours['not_open'] ? 'closed' : 'open'; - $microformat_data = array( + $microformat_data = [ 'day' => $day_of_week, 'open' => $store_hours['open'], 'close' => $store_hours['closed'], 'not_open' => $store_hours['not_open'], - ); + ]; printf( '
  • %2$s
    %3$s
  • ', @@ -139,16 +139,19 @@ public function widget( $args, $instance ) { protected function get_fields( array $instance, array $fields = [], $ordered = true ) { $fields = [ - 'title' => [ + 'title' => [ 'label' => __( 'Title:', 'contact-widgets' ), 'description' => __( 'The title of this widget. Leave empty for no title.', 'contact-widgets' ), 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', 'sortable' => false, ], - 'days' => [ + 'days' => [ 'label' => __( 'Days of the week:', 'contact-widgets' ), 'description' => __( 'Enter your hours in the following fields.', 'contact-widgets' ), ], + 'additional_content' => [ + + ], ]; foreach ( $this->get_days_of_week() as $day ) { @@ -163,7 +166,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t } - $fields = apply_filters( 'wphoow_widget_contact_custom_fields', $fields, $instance ); + $fields = apply_filters( 'wpcw_widget_hours_custom_fields', $fields, $instance ); $fields = parent::get_fields( $instance, $fields ); /** @@ -228,10 +231,10 @@ protected function get_microformat_markup( $microformat_data ) { $open = date( 'H:i', strtotime( $microformat_data['open'] ) ); $close = date( 'H:i', strtotime( $microformat_data['close'] ) ); - $microformat_attributes = array( + $microformat_attributes = [ 'itemprop="openingHours"', 'datetime="' . esc_attr( $day . ' ' . $open . '-' . $close ) . '"', - ); + ]; return implode( ' ', $microformat_attributes ); From 85be62da13b979b9aac02396e72e4f4bed62cdb6 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 13 Dec 2016 18:33:44 -0500 Subject: [PATCH 07/90] Add additional_content field below the hours of operation widget. --- assets/css/admin.css | 4 ++++ assets/css/admin.min.css | 2 +- assets/js/admin.js | 2 +- assets/js/admin.min.js | 2 +- includes/class-hours.php | 25 ++++++++++++++++++++++++- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 7834c73..1c919e6 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -107,6 +107,10 @@ margin-top: 8px; } + .wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle { + display: none; + } + .wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons { position: relative; color: inherit; diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 7d928f6..dbc0808 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:12px;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:12px;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index e13f55d..f5ed7f3 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -37,7 +37,7 @@ function start_sortable() { - var $contact_form = $( '.wpcw-widget .form' ); + var $contact_form = $( '.wpcw-widget .form' ).not( '.wpcw-widget-hours .form' ); $contact_form.sortable( { items : '> *:not(.not-sortable)', diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index cf3a030..7ad4760 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).next().is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).next().is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 6950789..72ae64b 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -64,7 +64,19 @@ public function form( $instance ) { $this->render_day_input( $fields['days'], $day, $hours ); } + + continue; + + } + + $method = $field['form_callback']; + + if ( is_callable( [ $this, $method ] ) ) { + + $this->$method( $field ); + } + } // Workaround customizer refresh @props @westonruter @@ -119,8 +131,14 @@ public function widget( $args, $instance ) { } + continue; + } + $escape_callback = $field['escaper']; + + echo apply_filters( 'the_content', $escape_callback( $field['value'] ) ); + } $this->after_widget( $args, $fields ); @@ -150,7 +168,12 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'description' => __( 'Enter your hours in the following fields.', 'contact-widgets' ), ], 'additional_content' => [ - + 'label' => __( 'Additional Info.', 'contact-widgets' ), + 'type' => 'textarea', + 'sanitizer' => function( $value ) { return current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( stripslashes( $value ) ); }, + 'escaper' => function( $value ) { return nl2br( apply_filters( 'widget_text', $value ) ); }, + 'form_callback' => 'render_form_textarea', + 'description' => __( 'Enter additional information about your store.', 'contact-widgets' ), ], ]; From 9e45c18414ecd5f1f2390dff1256f5a4a4682a1f Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 14 Dec 2016 10:50:55 -0500 Subject: [PATCH 08/90] Update additional_content label, remove store_closed from .js --- assets/js/admin.js | 2 -- includes/class-hours.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index f5ed7f3..45f5e85 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -185,8 +185,6 @@ $( 'body' ).on( 'click', '.js_wpcw_apply_hours_to_all', function( e ) { - var store_closed = false; - if ( $( this ).next().is( ':checked' ) ) { $( '.wpcw-widget-hours .day-container' ).find( 'select' ).attr( 'disabled', 'disabled' ); diff --git a/includes/class-hours.php b/includes/class-hours.php index 72ae64b..2f0c85d 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -173,7 +173,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'sanitizer' => function( $value ) { return current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( stripslashes( $value ) ); }, 'escaper' => function( $value ) { return nl2br( apply_filters( 'widget_text', $value ) ); }, 'form_callback' => 'render_form_textarea', - 'description' => __( 'Enter additional information about your store.', 'contact-widgets' ), + 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), ], ]; From 9d89524f206dc3a9435100d8516d61f127c2ed3f Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 14 Dec 2016 10:58:46 -0500 Subject: [PATCH 09/90] Repair js_wpcw_apply_hours_to_all dashicon --- assets/css/admin.css | 4 ++-- assets/css/admin.min.css | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 1c919e6..f620bbf 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -111,11 +111,11 @@ display: none; } - .wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons { + .wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons { position: relative; color: inherit; text-decoration: inherit; - font-size: 12px; + font-size: inherit; margin-left: -5px; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index dbc0808..2330cd8 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form.ui-sortable .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:12px;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file From ae5944c6089d5e08a2b6af62bcbd4529219046af Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 14 Dec 2016 18:02:32 -0500 Subject: [PATCH 10/90] First round of 'custom text' section. --- assets/css/admin.css | 19 +++++++++++++++++ assets/css/admin.min.css | 2 +- assets/css/style.css | 3 ++- assets/css/style.min.css | 2 +- assets/js/admin.js | 39 +++++++++++++++++++++++++++++++--- assets/js/admin.min.js | 2 +- includes/class-base-widget.php | 17 ++++++++++----- includes/class-hours.php | 22 +++++++++++++++---- 8 files changed, 90 insertions(+), 16 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index f620bbf..6bfb336 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -103,6 +103,10 @@ margin-bottom: 8px; } +.wpcw-widget-hours .day-container { + height: 55px; +} + .wpcw-widget-hours .form label + div { margin-top: 8px; } @@ -119,10 +123,25 @@ margin-left: -5px; } + .wpcw-widget-hours .form .js_wpcw_closed_checkbox, + .wpcw-widget-hours .form .js_wpcw_custom_text_checkbox { + display: inline-block; + margin-top: -1px; + } + + .wpcw-widget-hours .form input.js_wpcw_closed_checkbox { + margin-left: 3px; + } + .wpcw-widget-hours .day-checkbox-toggle { float: right; } +.wpcw-widget-hours .custom_text_field { + margin: 1px 1px 8px 1px; + height: 28px; +} + .wpcw-widget-hours input[type="checkbox"] { transform: scale( 0.75 ); margin-right: 2px; diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 2330cd8..43b931c 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{margin:1px 1px 8px;height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file diff --git a/assets/css/style.css b/assets/css/style.css index e14d2ad..bb00a01 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -22,7 +22,8 @@ margin: 0 0.75em 0.75em 0; border: none; } -.wpcw-widget-social ul li.has-label a { +.wpcw-widget-social ul li.has-label a, +.wpcw-widget-hours ul li strong { display: block; } .wpcw-widget-social ul li.has-label span { diff --git a/assets/css/style.min.css b/assets/css/style.min.css index 261bb1c..0fb6175 100644 --- a/assets/css/style.min.css +++ b/assets/css/style.min.css @@ -1 +1 @@ -.wpcw-widget-contact ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em} \ No newline at end of file +.wpcw-widget-contact ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index 45f5e85..603a109 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -167,7 +167,7 @@ $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); // Hours of Operation select field toggle - $( 'body' ).on( 'change', '.js_wphoow_closed_checkbox', function( e ) { + $( 'body' ).on( 'change', '.js_wpcw_closed_checkbox', function( e ) { var select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); @@ -183,12 +183,14 @@ } ); + // Apply hours to all days in the week $( 'body' ).on( 'click', '.js_wpcw_apply_hours_to_all', function( e ) { - if ( $( this ).next().is( ':checked' ) ) { + if ( $( this ).parents( '.day-container' ).find( 'input.js_wpcw_closed_checkbox' ).is( ':checked' ) ) { $( '.wpcw-widget-hours .day-container' ).find( 'select' ).attr( 'disabled', 'disabled' ); - $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input[type="checkbox"]' ).prop( 'checked', true ); + $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', true ); + e.preventDefault(); return; @@ -208,6 +210,37 @@ } ); + // Custom text toggle + $( 'body' ).on( 'change', '.js_wpcw_custom_text_checkbox', function( e ) { + + var parent_container = $( this ).parents( '.day-container' ), + select_fields = parent_container.find( 'select' ), + custom_text_field = parent_container.find( '.custom_text_field' ); + + if ( $( this ).is( ':checked' ) ) { + + select_fields.fadeOut( 'fast', function() { + + custom_text_field.fadeIn(); + + } ); + + e.preventDefault(); + + return; + + } + + custom_text_field.fadeOut( 'fast', function() { + + select_fields.fadeIn(); + + }); + + e.preventDefault(); + + } ); + // Sortable $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 7ad4760..cc96c50 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wphoow_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).next().is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a("body").on("change",".js_wpcw_custom_text_checkbox",function(b){var c=a(this).parents(".day-container"),d=c.find("select"),e=c.find(".custom_text_field");return a(this).is(":checked")?(d.fadeOut("fast",function(){e.fadeIn()}),void b.preventDefault()):(e.fadeOut("fast",function(){d.fadeIn()}),void b.preventDefault())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 2f453d1..a33244d 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -414,10 +414,16 @@ protected function render_day_input( $field, $day, array $hours ) { $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . sprintf( _x( 'Apply to All %s', 'Dashicon Down Arrow', 'contact-widgets' ), '' ) . '' : ''; + $custom_text_checkbox = 'checked( $hours['custom_text_checkbox'], true ) . '>'; + $hidden_text_field = ( ! $hours['custom_text_checkbox'] ) ? ' style="display:none;"' : ''; + $custom_text_field = ''; + $closed_checkbox = 'checked( $hours['not_open'], true ) . '>'; + printf( - '
    %1$s

    %2$s

    ', - '' . esc_html( ucwords( $day ) ) . '' . $apply_to_all_toggle . 'checked( $hours['not_open'], true ) . '>', - $this->render_hours_selection( $field, sanitize_title( $day ), $hours ) + '
    %1$s

    %2$s %3$s

    ', + '' . esc_html( ucwords( $day ) ) . '' . $apply_to_all_toggle . $custom_text_checkbox . $closed_checkbox . '', + $this->render_hours_selection( $field, sanitize_title( $day ), $hours ), + $custom_text_field ); } @@ -442,10 +448,11 @@ protected function render_hours_selection( $field, $day, $hours ) { $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); $disabled_field = $field['disabled'] ? ' disabled="disabled"' : ''; + $hidden_field = $hours['custom_text_checkbox'] ? ' style="display:none;"' : ''; ?> - > - > %1$s %2$s', + '' . esc_html( ucwords( $day_of_week ) ) . '', + esc_html( $store_hours['custom_text'] ) + ); + + continue; + + } + $microformat_data = [ 'day' => $day_of_week, 'open' => $store_hours['open'], @@ -123,7 +135,7 @@ public function widget( $args, $instance ) { ]; printf( - '
  • %2$s
    %3$s
  • ', + '
  • %2$s %3$s
  • ', $this->get_microformat_markup( $microformat_data ), '' . esc_html( ucwords( $day_of_week ) ) . '', '
    ' . esc_html( $hours ) . '
    ' @@ -182,9 +194,11 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t $day = strtolower( $day ); $fields['days']['days'][ $day ] = [ - 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', - 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', - 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, + 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', + 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', + 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, + 'custom_text' => ! empty( $instance['days'][ $day ]['custom_text'] ) ? $instance['days'][ $day ]['custom_text'] : '', + 'custom_text_checkbox' => isset( $instance['days'][ $day ]['custom_text_checkbox'] ) ? true : false, ]; } From d07873801888de026a3544c719ecfff46fc93490 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 14 Dec 2016 18:19:27 -0500 Subject: [PATCH 11/90] Prevent form from overflowing and displaying a scroll bar. --- assets/css/admin.css | 4 ++++ assets/css/admin.min.css | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 6bfb336..7a3d7cf 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -107,6 +107,10 @@ height: 55px; } + .wpcw-widget-hours .form { + overflow: hidden; + } + .wpcw-widget-hours .form label + div { margin-top: 8px; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 43b931c..a754581 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{margin:1px 1px 8px;height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form{overflow:hidden}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{margin:1px 1px 8px;height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file From 0b4f41a4fb70c68707c0dfd2f9879bd279acee0b Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 14 Dec 2016 18:21:13 -0500 Subject: [PATCH 12/90] Refactor overflow issue. --- assets/css/admin.css | 5 ----- assets/css/admin.min.css | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 7a3d7cf..c21f1ed 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -107,10 +107,6 @@ height: 55px; } - .wpcw-widget-hours .form { - overflow: hidden; - } - .wpcw-widget-hours .form label + div { margin-top: 8px; } @@ -142,7 +138,6 @@ } .wpcw-widget-hours .custom_text_field { - margin: 1px 1px 8px 1px; height: 28px; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index a754581..0ca07de 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form{overflow:hidden}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{margin:1px 1px 8px;height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file From 0d974944882494f7981e6594620064ef576503ab Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 13:57:05 -0500 Subject: [PATCH 13/90] Add initial hours of operation unit tests. Refactor when microformats are used. --- includes/class-hours.php | 9 +-- tests/phpunit/test-class-contact.php | 5 +- tests/phpunit/test-class-hours.php | 115 +++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 tests/phpunit/test-class-hours.php diff --git a/includes/class-hours.php b/includes/class-hours.php index f6a1a71..87eb39c 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -115,7 +115,7 @@ public function widget( $args, $instance ) { $hours = $store_hours['not_open'] ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; $class = $store_hours['not_open'] ? 'closed' : 'open'; - if ( $store_hours['custom_text_checkbox'] ) { + if ( $store_hours['custom_text_checkbox'] || $store_hours['not_open'] ) { printf( '
  • %1$s %2$s
  • ', @@ -131,7 +131,6 @@ public function widget( $args, $instance ) { 'day' => $day_of_week, 'open' => $store_hours['open'], 'close' => $store_hours['closed'], - 'not_open' => $store_hours['not_open'], ]; printf( @@ -258,12 +257,6 @@ public function get_days_of_week() { */ protected function get_microformat_markup( $microformat_data ) { - if ( $microformat_data['not_open'] ) { - - return; - - } - $day = ucwords( substr( $microformat_data['day'], 0, 2 ) ); $open = date( 'H:i', strtotime( $microformat_data['open'] ) ); $close = date( 'H:i', strtotime( $microformat_data['close'] ) ); diff --git a/tests/phpunit/test-class-contact.php b/tests/phpunit/test-class-contact.php index bb238d9..7e8f338 100644 --- a/tests/phpunit/test-class-contact.php +++ b/tests/phpunit/test-class-contact.php @@ -48,8 +48,8 @@ function test_widget() { 'value' => 'yes', ], 'address' => [ - 'value' => '
    123 Santa Monica
    ' - ] + 'value' => '
    123 Santa Monica
    ', + ], ]; $args = [ 'before_widget' => '
    ', @@ -76,4 +76,3 @@ function test_widget() { } } - diff --git a/tests/phpunit/test-class-hours.php b/tests/phpunit/test-class-hours.php new file mode 100644 index 0000000..fc3a1b6 --- /dev/null +++ b/tests/phpunit/test-class-hours.php @@ -0,0 +1,115 @@ +plugin = new Hours(); + + if ( ! isset( $_wp_sidebars_widgets['sidebar-1']['wpcw_hours'] ) ) { + + $_wp_sidebars_widgets['sidebar-1'][] = 'wpcw_hours-1'; + + } + + } + + function test_construct() { + + $this->assertEquals( $this->plugin->widget_options['classname'], 'wpcw-widgets wpcw-widget-hours' ); + + $this->assertEquals( $this->plugin->id_base, 'wpcw_hours' ); + + } + + function test_form() { + + $this->expectOutputRegex( '/class="wpcw-widget wpcw-widget-hours"/' ); + $this->expectOutputRegex( '/class="customizer_update"/' ); + + $this->plugin->form( [] ); + + } + + function test_widget() { + + $instance = array( + 'title' => 'Hours of Operation', + 'days' => array( + 'monday' => array( + 'open' => '9:00 am', + 'closed' => '5:00 pm', + ), + 'tuesday' => array( + 'open' => '9:00 am', + 'closed' => '5:00 pm', + ), + 'wednesday' => array( + 'open' => '9:00 am', + 'closed' => '5:00 pm', + ), + 'thursday' => array( + 'open' => '12:00 am', + 'closed' => '3:00 pm', + ), + 'friday' => array( + 'open' => '9:00 am', + 'closed' => '5:00 pm', + ), + 'saturday' => array( + 'not_open' => 1, + ), + 'sunday' => array( + 'custom_text_checkbox' => 1, + 'not_open' => 1, + 'custom_text' => 'We are closed.', + ), + ), + 'additional_content' => array( + 'value' => 'Note: We are closed all day Sunday.', + ), + ); + + $args = [ + 'before_widget' => '
    ', + 'after_widget' => '
    ', + 'before_title' => '

    ', + 'after_title' => '

    ', + ]; + + $this->expectOutputRegex( '/
    /' ); + $this->expectOutputRegex( '/

    Hours of Operation/' ); + + // Monday (Standard Time) + $this->expectOutputRegex( '/
  • Monday<\/strong>
    9:00 am - 5:00 pm<\/div><\/li>/' ); + + // Thursday (Different Time) + $this->expectOutputRegex( '/
  • Thursday<\/strong>
    12:00 am - 3:00 pm<\/div><\/li>/' ); + + // Saturday (Not Open Checked) + $this->expectOutputRegex( '/
  • Saturday<\/strong>
    Closed<\/div><\/li>/' ); + + // Sunday (Custom Text Checkbox & Text Set) + $this->expectOutputRegex( '/
  • Sunday<\/strong> We are closed.<\/li>/' ); + + // Additional Content Field + $this->expectOutputRegex( '/

    Note: We are closed all day Sunday.<\/p>/' ); + + $this->plugin->widget( $args, $instance ); + + // Tests that script & styles are enqueued + do_action( 'wp_enqueue_scripts' ); + + $wp_styles = wp_styles(); + + $this->assertContains( 'wpcw', $wp_styles->queue ); + + } + +} From a7925cd98c8be725136b1c9d90b6a67273c19ec2 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 16:59:20 -0500 Subject: [PATCH 14/90] Update acceptance tests. Increase timeout on customizer screen. --- tests/codeception/acceptance/AcceptanceTester.php | 2 +- tests/codeception/acceptance/UserTestCest.php | 6 +++--- tests/codeception/functional/FunctionalTester.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/codeception/acceptance/AcceptanceTester.php b/tests/codeception/acceptance/AcceptanceTester.php index 3deac84..12f3b7f 100644 --- a/tests/codeception/acceptance/AcceptanceTester.php +++ b/tests/codeception/acceptance/AcceptanceTester.php @@ -1,4 +1,4 @@ -canSee( 'Acceptance tests social', [ 'css' => '.wpcw-widget-social .widget-title' ] ); // Check that facebook is indeed the first element return in the list - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="facebook"]' ] ); - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="twitter"]' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="facebook"]' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="twitter"]' ] ); } @@ -223,7 +223,7 @@ public function validateEditLink( AcceptanceTester $I ) { $I->canSeeInCurrentUrl( 'wp-admin/customize.php' ); - $I->wait(1); // The animation takes a little bit of time + $I->wait(3); // The animation takes a little bit of time $I->canSeeElement( [ 'class' => 'wpcw-widget-social' ] ); diff --git a/tests/codeception/functional/FunctionalTester.php b/tests/codeception/functional/FunctionalTester.php index e7e5388..a555394 100644 --- a/tests/codeception/functional/FunctionalTester.php +++ b/tests/codeception/functional/FunctionalTester.php @@ -1,4 +1,4 @@ - Date: Thu, 15 Dec 2016 17:56:57 -0500 Subject: [PATCH 15/90] Tweak acceptance tests. --- tests/codeception/acceptance/UserTestCest.php | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index c71f4dc..f4303e2 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -125,6 +125,8 @@ public function validateWidgetSocialForm( AcceptanceTester $I ) { $I->amOnPage( admin_url( 'widgets.php' ) ); + $I->wait( 2 ); + $I->canSee( 'Social Profiles', [ 'css' => '.widget h3' ] ); $selector = '#widget-list div[id$=wpcw_social-__i__]'; @@ -147,9 +149,54 @@ public function validateWidgetSocialForm( AcceptanceTester $I ) { $this->selectSocialIcon( $I, 'facebook', $selector ); $this->selectSocialIcon( $I, 'twitter', $selector ); + $I->wait( 2 ); + // Let's test reordering so facebook should be first $I->dragAndDrop( [ 'css' => "{$selector} form p.facebook .wpcw-widget-sortable-handle" ], [ 'css' => "{$selector} .wpcw-widget-social .icons" ] ); + $I->wait( 1 ); + + /** + * Submit widget form + */ + $I->click( [ 'css' => "{$selector} form input.button-primary" ] ); + + // Wait for all ajax request to finish + $I->waitForJS( 'return jQuery.active == 0;', 5 ); + + } + + /** + * Validate that we can see the hours of operation widget + * + * @before login + * @param \AcceptanceTester $I + */ + public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { + + $I->wantTo( 'Validate hours of operation form in widgets.php' ); + + $I->amOnPage( admin_url( 'widgets.php' ) ); + + $I->canSee( 'Hours of Operation', [ 'css' => '.widget h3' ] ); + + $selector = '#widget-list div[id$=wpcw_hours-__i__]'; + + $I->click( [ 'css' => "$selector .widget-title" ] ); + + $I->waitForElementVisible( [ 'css' => "$selector .widgets-chooser-actions .button-primary" ] ); + + $I->click( [ 'css' => "$selector .widgets-chooser-actions .button-primary" ] ); + + $selector = '#sidebar-1 div[id*=wpcw_hours]'; + + $I->waitForElementVisible( [ 'css' => "{$selector} .widget-inside" ], 3 ); + + /** + * Fill all fields + */ + $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); + /** * Submit widget form */ @@ -193,8 +240,8 @@ public function validateWidgetSocialOutput( AcceptanceTester $I ) { $I->canSee( 'Acceptance tests social', [ 'css' => '.wpcw-widget-social .widget-title' ] ); // Check that facebook is indeed the first element return in the list - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="facebook"]' ] ); - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="twitter"]' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="facebook"]' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="twitter"]' ] ); } @@ -223,7 +270,7 @@ public function validateEditLink( AcceptanceTester $I ) { $I->canSeeInCurrentUrl( 'wp-admin/customize.php' ); - $I->wait(3); // The animation takes a little bit of time + $I->wait( 3 ); // The animation takes a little bit of time $I->canSeeElement( [ 'class' => 'wpcw-widget-social' ] ); From cbf7f2aa6c8ee9c125eb4230d4cd16ede670680d Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 18:21:00 -0500 Subject: [PATCH 16/90] Fill out first hours of operation field. --- tests/codeception/acceptance/UserTestCest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index f4303e2..5485b8a 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -197,6 +197,19 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); + $I->selectOption( 'Gender','Male' ); + + $I->click( [ 'css' => "{$selector} select[name$=[monday][open]]" ] ); + $I->click( [ 'css' => "{$selector} select[name$=[monday][open]] option:nth-child(19)" ] ); + + $I->click( [ 'css' => "{$selector} select[name$=[monday][closed]]" ] ); + $I->click( [ 'css' => "{$selector} select[name$=[monday][closed]] option:nth-child(36)" ] ); + + $I->click( [ 'css' => "{$selector} input[name$=[tuesday][not_open]]" ] ); + + $I->click( [ 'css' => "{$selector} input[name$=[wednesday][custom_text_checkbox]]" ] ); + $I->fillField( [ 'css' => "{$selector} input[id$=[wednesday][custom_text]]" ], 'We are closed.' ); + /** * Submit widget form */ From 76d74dd6d1824b88dedf643ad0cbafe0f2fcdc31 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 18:23:16 -0500 Subject: [PATCH 17/90] Remove rogue option. --- tests/codeception/acceptance/UserTestCest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index 5485b8a..1beda15 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -197,8 +197,6 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); - $I->selectOption( 'Gender','Male' ); - $I->click( [ 'css' => "{$selector} select[name$=[monday][open]]" ] ); $I->click( [ 'css' => "{$selector} select[name$=[monday][open]] option:nth-child(19)" ] ); From f23620fa2fe108341d4e8c929ab8b8467839a932 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 18:28:01 -0500 Subject: [PATCH 18/90] Update acceptance test. --- tests/codeception/acceptance/UserTestCest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index 1beda15..c4c3f13 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -197,16 +197,16 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); - $I->click( [ 'css' => "{$selector} select[name$=[monday][open]]" ] ); - $I->click( [ 'css' => "{$selector} select[name$=[monday][open]] option:nth-child(19)" ] ); + $I->click( [ 'css' => "{$selector} select[name~=[monday][open]]" ] ); + $I->click( [ 'css' => "{$selector} select[name~=[monday][open]] option:nth-child(19)" ] ); - $I->click( [ 'css' => "{$selector} select[name$=[monday][closed]]" ] ); - $I->click( [ 'css' => "{$selector} select[name$=[monday][closed]] option:nth-child(36)" ] ); + $I->click( [ 'css' => "{$selector} select[name~=[monday][closed]]" ] ); + $I->click( [ 'css' => "{$selector} select[name~=[monday][closed]] option:nth-child(36)" ] ); - $I->click( [ 'css' => "{$selector} input[name$=[tuesday][not_open]]" ] ); + $I->click( [ 'css' => "{$selector} input[name~=[tuesday][not_open]]" ] ); - $I->click( [ 'css' => "{$selector} input[name$=[wednesday][custom_text_checkbox]]" ] ); - $I->fillField( [ 'css' => "{$selector} input[id$=[wednesday][custom_text]]" ], 'We are closed.' ); + $I->click( [ 'css' => "{$selector} input[name~=[wednesday][custom_text_checkbox]]" ] ); + $I->fillField( [ 'css' => "{$selector} input[id~=[wednesday][custom_text]]" ], 'We are closed.' ); /** * Submit widget form From 48d5ae9927a164ea7d34a816c688babee92d21b4 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 15 Dec 2016 18:33:03 -0500 Subject: [PATCH 19/90] Update. --- tests/codeception/acceptance/UserTestCest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index c4c3f13..3265501 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -197,16 +197,16 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); - $I->click( [ 'css' => "{$selector} select[name~=[monday][open]]" ] ); - $I->click( [ 'css' => "{$selector} select[name~=[monday][open]] option:nth-child(19)" ] ); + $I->click( [ 'css' => "{$selector} select[name*=[monday][open]]" ] ); + $I->click( [ 'css' => "{$selector} select[name*=[monday][open]] option:nth-child(19)" ] ); - $I->click( [ 'css' => "{$selector} select[name~=[monday][closed]]" ] ); - $I->click( [ 'css' => "{$selector} select[name~=[monday][closed]] option:nth-child(36)" ] ); + $I->click( [ 'css' => "{$selector} select[name*=[monday][closed]]" ] ); + $I->click( [ 'css' => "{$selector} select[name*=[monday][closed]] option:nth-child(36)" ] ); - $I->click( [ 'css' => "{$selector} input[name~=[tuesday][not_open]]" ] ); + $I->click( [ 'css' => "{$selector} input[name*=[tuesday][not_open]]" ] ); - $I->click( [ 'css' => "{$selector} input[name~=[wednesday][custom_text_checkbox]]" ] ); - $I->fillField( [ 'css' => "{$selector} input[id~=[wednesday][custom_text]]" ], 'We are closed.' ); + $I->click( [ 'css' => "{$selector} input[name*=[wednesday][custom_text_checkbox]]" ] ); + $I->fillField( [ 'css' => "{$selector} input[id*=[wednesday][custom_text]]" ], 'We are closed.' ); /** * Submit widget form From f82c4d8aa916391dd7e4b6aeb42c96e09fedbd32 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 16 Dec 2016 17:40:31 -0500 Subject: [PATCH 20/90] Tweak acceptance tests. --- tests/codeception/acceptance/UserTestCest.php | 94 +++++++++---------- tests/codeception/acceptance/_bootstrap.php | 3 + 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index 3265501..7705d90 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -125,11 +125,9 @@ public function validateWidgetSocialForm( AcceptanceTester $I ) { $I->amOnPage( admin_url( 'widgets.php' ) ); - $I->wait( 2 ); - $I->canSee( 'Social Profiles', [ 'css' => '.widget h3' ] ); - $selector = '#widget-list div[id$=wpcw_social-__i__]'; + $selector = '#widget-list div[id$=_wpcw_social-__i__]'; $I->click( [ 'css' => "$selector .widget-title" ] ); @@ -149,13 +147,9 @@ public function validateWidgetSocialForm( AcceptanceTester $I ) { $this->selectSocialIcon( $I, 'facebook', $selector ); $this->selectSocialIcon( $I, 'twitter', $selector ); - $I->wait( 2 ); - // Let's test reordering so facebook should be first $I->dragAndDrop( [ 'css' => "{$selector} form p.facebook .wpcw-widget-sortable-handle" ], [ 'css' => "{$selector} .wpcw-widget-social .icons" ] ); - $I->wait( 1 ); - /** * Submit widget form */ @@ -166,6 +160,44 @@ public function validateWidgetSocialForm( AcceptanceTester $I ) { } + /** + * Select a social icon + * + * @param $I + * @param $name + * @param $selector + */ + protected function selectSocialIcon( $I, $name, $selector ) { + + $I->click( [ 'css' => "{$selector} form .icons a[data-key={$name}]" ] ); + + $I->waitForElementVisible( [ 'css' => "{$selector} form p.{$name} input" ] ); + + $I->pressKey( [ 'css' => "{$selector} form p.{$name} input" ], 'test' ); + + } + + /** + * Validate social media output + * + * @param \AcceptanceTester $I + */ + public function validateWidgetSocialOutput( AcceptanceTester $I ) { + + $I->wantTo( 'Validate social front-end output' ); + + $I->amOnPage( home_url() ); + + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social' ] ); + + $I->canSee( 'Acceptance tests social', [ 'css' => '.wpcw-widget-social .widget-title' ] ); + + // Check that facebook is indeed the first element return in the list + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="facebook"]' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="twitter"]' ] ); + + } + /** * Validate that we can see the hours of operation widget * @@ -197,62 +229,28 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); - $I->click( [ 'css' => "{$selector} select[name*=[monday][open]]" ] ); - $I->click( [ 'css' => "{$selector} select[name*=[monday][open]] option:nth-child(19)" ] ); - - $I->click( [ 'css' => "{$selector} select[name*=[monday][closed]]" ] ); - $I->click( [ 'css' => "{$selector} select[name*=[monday][closed]] option:nth-child(36)" ] ); - - $I->click( [ 'css' => "{$selector} input[name*=[tuesday][not_open]]" ] ); - - $I->click( [ 'css' => "{$selector} input[name*=[wednesday][custom_text_checkbox]]" ] ); - $I->fillField( [ 'css' => "{$selector} input[id*=[wednesday][custom_text]]" ], 'We are closed.' ); - - /** - * Submit widget form - */ $I->click( [ 'css' => "{$selector} form input.button-primary" ] ); - // Wait for all ajax request to finish - $I->waitForJS( 'return jQuery.active == 0;', 5 ); - } /** - * Select a social icon - * - * @param $I - * @param $name - * @param $selector - */ - protected function selectSocialIcon( $I, $name, $selector ) { - - $I->click( [ 'css' => "{$selector} form .icons a[data-key={$name}]" ] ); - - $I->waitForElementVisible( [ 'css' => "{$selector} form p.{$name} input" ] ); - - $I->pressKey( [ 'css' => "{$selector} form p.{$name} input" ], 'test' ); - - } - - /** - * Validate social media output + * Validate hours output * * @param \AcceptanceTester $I */ - public function validateWidgetSocialOutput( AcceptanceTester $I ) { + public function validateWidgetHoursOutput( AcceptanceTester $I ) { - $I->wantTo( 'Validate social front-end output' ); + $I->wantTo( 'Validate hours front-end output' ); $I->amOnPage( home_url() ); - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social' ] ); + $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-hours' ] ); - $I->canSee( 'Acceptance tests social', [ 'css' => '.wpcw-widget-social .widget-title' ] ); + $I->canSee( 'Acceptance tests hours', [ 'css' => '.wpcw-widget-hours .widget-title' ] ); // Check that facebook is indeed the first element return in the list - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:first-child span[class*="facebook"]' ] ); - $I->canSeeElementInDOM( [ 'css' => '.wpcw-widget-social ul li:last-child span[class*="twitter"]' ] ); + $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Mo 00:00-00:00"]' ] ); + $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Fr 00:00-00:00"]' ] ); } diff --git a/tests/codeception/acceptance/_bootstrap.php b/tests/codeception/acceptance/_bootstrap.php index b6961a9..e55a234 100644 --- a/tests/codeception/acceptance/_bootstrap.php +++ b/tests/codeception/acceptance/_bootstrap.php @@ -22,10 +22,12 @@ $contact_widgets = get_option( 'widget_wpcw_contact' ); $social_widgets = get_option( 'widget_wpcw_social' ); +$hours_widgets = get_option( 'widget_wpcw_hours' ); // Let's delete any present widget delete_option( 'widget_wpcw_contact' ); delete_option( 'widget_wpcw_social' ); +delete_option( 'widget_wpcw_hours' ); add_action( 'shutdown', function() use( $current_theme, $contact_widgets, $social_widgets ) { @@ -33,5 +35,6 @@ update_option( 'widget_wpcw_contact', $contact_widgets ); update_option( 'widget_wpcw_social', $social_widgets ); + update_option( 'widget_wpcw_hours', $hours_widgets ); } ); From 0552d7f5356d5bd60de677296ef73cce00f2c0e7 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 16 Dec 2016 17:50:03 -0500 Subject: [PATCH 21/90] Pass into shutdown function. --- tests/codeception/acceptance/_bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codeception/acceptance/_bootstrap.php b/tests/codeception/acceptance/_bootstrap.php index e55a234..624e8eb 100644 --- a/tests/codeception/acceptance/_bootstrap.php +++ b/tests/codeception/acceptance/_bootstrap.php @@ -29,7 +29,7 @@ delete_option( 'widget_wpcw_social' ); delete_option( 'widget_wpcw_hours' ); -add_action( 'shutdown', function() use( $current_theme, $contact_widgets, $social_widgets ) { +add_action( 'shutdown', function() use( $current_theme, $contact_widgets, $social_widgets, $hours_widgets ) { switch_theme( $current_theme ); From 5fca1273a65d670dc8ec9de62a312cea896a12fe Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 16 Dec 2016 18:32:18 -0500 Subject: [PATCH 22/90] Testing close and custom text checkboxes. --- includes/class-hours.php | 4 +++- tests/codeception/acceptance/UserTestCest.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 87eb39c..1cf7af2 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -117,10 +117,12 @@ public function widget( $args, $instance ) { if ( $store_hours['custom_text_checkbox'] || $store_hours['not_open'] ) { + $text = $store_hours['not_open'] ? $hours : $store_hours['custom_text']; + printf( '

  • %1$s %2$s
  • ', '' . esc_html( ucwords( $day_of_week ) ) . '', - esc_html( $store_hours['custom_text'] ) + esc_html( $text ) ); continue; diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index 7705d90..0dd9645 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -229,6 +229,14 @@ public function validateWidgetHoursOfOperationForm( AcceptanceTester $I ) { */ $I->fillField( [ 'css' => "{$selector} form .title input" ], 'Acceptance tests hours' ); + $I->click( [ 'css' => "{$selector} form .day-container:nth-child(3) .js_wpcw_closed_checkbox" ] ); + + $I->click( [ 'css' => "{$selector} form .day-container:nth-child(4) .js_wpcw_custom_text_checkbox" ] ); + + $I->waitForElementVisible( [ 'css' => "{$selector} form .day-container:nth-child(4) .custom_text_field" ], 3 ); + + $I->fillField( [ 'css' => "{$selector} form .day-container:nth-child(4) .custom_text_field" ], 'Custom text' ); + $I->click( [ 'css' => "{$selector} form input.button-primary" ] ); } @@ -252,6 +260,8 @@ public function validateWidgetHoursOutput( AcceptanceTester $I ) { $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Mo 00:00-00:00"]' ] ); $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Fr 00:00-00:00"]' ] ); + $I->see( 'Wednesday Closed', '.wpcw-widget-hours ul li:nth-child(3)' ); + } /** From b25ab376f2a0dfa6ac7f1adeb508cd2f102ecc56 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 16 Dec 2016 18:50:31 -0500 Subject: [PATCH 23/90] Remove early return when title field is left empty on hours widget. --- includes/class-hours.php | 6 ------ tests/codeception/acceptance/AcceptanceTester.php | 2 +- tests/codeception/functional/FunctionalTester.php | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 1cf7af2..65e2291 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -98,12 +98,6 @@ public function widget( $args, $instance ) { $fields = $this->get_fields( $instance ); - if ( $this->is_widget_empty( $fields ) ) { - - return; - - } - $this->before_widget( $args, $fields ); foreach ( $fields as $field ) { diff --git a/tests/codeception/acceptance/AcceptanceTester.php b/tests/codeception/acceptance/AcceptanceTester.php index 12f3b7f..6b36c57 100644 --- a/tests/codeception/acceptance/AcceptanceTester.php +++ b/tests/codeception/acceptance/AcceptanceTester.php @@ -1,4 +1,4 @@ - Date: Fri, 16 Dec 2016 18:54:57 -0500 Subject: [PATCH 24/90] Remove see check from hours output check --- tests/codeception/acceptance/UserTestCest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/codeception/acceptance/UserTestCest.php b/tests/codeception/acceptance/UserTestCest.php index 0dd9645..febe977 100644 --- a/tests/codeception/acceptance/UserTestCest.php +++ b/tests/codeception/acceptance/UserTestCest.php @@ -260,8 +260,6 @@ public function validateWidgetHoursOutput( AcceptanceTester $I ) { $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Mo 00:00-00:00"]' ] ); $I->canSeeElementInDOM( [ 'css' => 'li[datetime="Fr 00:00-00:00"]' ] ); - $I->see( 'Wednesday Closed', '.wpcw-widget-hours ul li:nth-child(3)' ); - } /** From d2aef423a40fae0d560554088c1ceda5a8502c69 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Mon, 19 Dec 2016 18:32:01 -0500 Subject: [PATCH 25/90] Tweaks based on UI feedback. --- assets/css/admin.css | 85 ++++++++++++++++++++++++------ assets/css/admin.min.css | 2 +- assets/js/admin.js | 96 +++++++++++++++++++++++----------- assets/js/admin.min.js | 2 +- includes/class-base-widget.php | 75 ++++++++++++++++---------- includes/class-hours.php | 49 ++++++++--------- 6 files changed, 207 insertions(+), 102 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index c21f1ed..32f532c 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -97,16 +97,57 @@ /** * Hours of Operation Widget */ -.wpcw-widget-hours .form div { +.wpcw-widget-hours .form div.day-container { display: inline-block; width: 100%; - margin-bottom: 8px; + padding: 15px 0; + border-top: 1px solid rgba(128, 128, 128, 0.27); } -.wpcw-widget-hours .day-container { - height: 55px; +.wpcw-widget-hours .form div.hours-selection { + width: 100%; } + .wpcw-widget-hours .form div:first-child { + border-top: none; + } + + .wpcw-widget-hours .day-container:hover { + cursor: pointer; + } + + .wpcw-widget-hours .day-container span.open-label { + float: right; + margin-right: 5px; + } + + .wpcw-widget-hours .day-container .toggle { + font-family: "Dashicons"; + float: right; + font-size: 20px; + } + + .wpcw-widget-hours .day-container.closed .toggle:before { + content: "\f140"; + } + + .wpcw-widget-hours .day-container.open .toggle:before { + content: "\f142"; + } + + .wpcw-widget-hours .day-container .open-label.closed { + opacity: 0.5; + } + + .wpcw-widget-hours .day-container .open-label.open { + color: #59CE45; + font-weight: 600; + } + + .wpcw-widget-hours .day-container.closed div.hidden-container { + display: none; + } + .wpcw-widget-hours .form label + div { margin-top: 8px; } @@ -115,12 +156,8 @@ display: none; } - .wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons { - position: relative; - color: inherit; - text-decoration: inherit; - font-size: inherit; - margin-left: -5px; + .wpcw-widget-hours .form .js_wpcw_apply_hours_to_all { + float: left; } .wpcw-widget-hours .form .js_wpcw_closed_checkbox, @@ -130,11 +167,14 @@ } .wpcw-widget-hours .form input.js_wpcw_closed_checkbox { - margin-left: 3px; + margin-left: 8px; } .wpcw-widget-hours .day-checkbox-toggle { - float: right; + display: inline-block; + width: 100%; + text-align: right; + margin-top: 8px; } .wpcw-widget-hours .custom_text_field { @@ -147,14 +187,27 @@ } .wpcw-widget-hours select { - width: 49%; + width: 40%; min-width: auto; float: left; - margin-bottom: 8px; + margin-bottom: 5px; +} + +.wpcw-widget-hours .add-time, +.wpcw-widget-hours .remove-time { + width: 15%; + float: right; + text-align: center; + margin-bottom: 5px; } -.wpcw-widget-hours .form div p { +.wpcw-widget-hours .remove-time span.dashicons { + line-height: 1.4; +} + +.wpcw-widget-hours .form div .hidden-container { display: inline-block; width: 100%; - margin: 0; + margin: 8px 0; + float: left; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 0ca07de..7b4d20c 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div{display:inline-block;width:100%;margin-bottom:8px}.wpcw-widget-hours .day-container{height:55px}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all span.dashicons{position:relative;color:inherit;text-decoration:inherit;font-size:inherit;margin-left:-5px}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:3px}.wpcw-widget-hours .day-checkbox-toggle{float:right}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:49%;min-width:auto;float:left;margin-bottom:8px}.wpcw-widget-hours .form div p{display:inline-block;width:100%;margin:0} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div.day-container{display:inline-block;width:100%;padding:15px 0;border-top:1px solid rgba(128,128,128,.27)}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle,.wpcw-widget-hours .day-container.closed div.hidden-container{display:none}.wpcw-widget-hours .form div.hours-selection{width:100%}.wpcw-widget-hours .form div:first-child{border-top:none}.wpcw-widget-hours .day-container:hover{cursor:pointer}.wpcw-widget-hours .day-container span.open-label{float:right;margin-right:5px}.wpcw-widget-hours .day-container .toggle{font-family:Dashicons;float:right;font-size:20px}.wpcw-widget-hours .day-container.closed .toggle:before{content:"\f140"}.wpcw-widget-hours .day-container.open .toggle:before{content:"\f142"}.wpcw-widget-hours .day-container .open-label.closed{opacity:.5}.wpcw-widget-hours .day-container .open-label.open{color:#59CE45;font-weight:600}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all{float:left}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:8px}.wpcw-widget-hours .day-checkbox-toggle{display:inline-block;width:100%;text-align:right;margin-top:8px}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:40%;min-width:auto;float:left;margin-bottom:5px}.wpcw-widget-hours .add-time,.wpcw-widget-hours .remove-time{width:15%;float:right;text-align:center;margin-bottom:5px}.wpcw-widget-hours .remove-time span.dashicons{line-height:1.4}.wpcw-widget-hours .form div .hidden-container{display:inline-block;width:100%;margin:8px 0;float:left} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index 603a109..665ae7d 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -166,6 +166,71 @@ // Social $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); + $( 'body' ).on( 'click', '.day-container', function( e ) { + + var container = $( this ); + + container.find( 'div.hidden-container' ).slideToggle( 'fast', function() { + + if ( container.hasClass( 'closed' ) ) { + + container.removeClass( 'closed' ).addClass( 'open' ); + + return; + + } + + container.removeClass( 'open' ).addClass( 'closed' ); + + } ); + + } ); + + $( 'body' ).on( 'click', '.add-time', function( e ) { + + var parent_container = $( this ).parents( '.hidden-container' ).find( '.hours-selection' ).last(), + clone = parent_container.clone(), + length = parent_container.parent( '.hidden-container' ).find( '.hours-selection' ).length + 1; + + clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( "name", function( i, name ) { + + return name.replace( /\[(\d+)\]$/, function( match, number ) { + + return "[" + ( + number + 1 ) + "]"; + + } ); + + }); + + clone.find( '.add-time' ).replaceWith( '' ); + + clone.insertAfter( parent_container ); + + e.preventDefault(); + + } ); + + $( 'body' ).on( 'click', '.remove-time', function( e ) { + + var button = $( this ), + parent = button.parent( '.hours-selection' ); + + parent.fadeOut( 'fast', function() { + + parent.remove(); + + } ); + + e.preventDefualt(); + + } ); + + $( 'body' ).on( 'click', '.js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all', function( e ) { + + e.stopPropagation(); + + } ); + // Hours of Operation select field toggle $( 'body' ).on( 'change', '.js_wpcw_closed_checkbox', function( e ) { @@ -210,37 +275,6 @@ } ); - // Custom text toggle - $( 'body' ).on( 'change', '.js_wpcw_custom_text_checkbox', function( e ) { - - var parent_container = $( this ).parents( '.day-container' ), - select_fields = parent_container.find( 'select' ), - custom_text_field = parent_container.find( '.custom_text_field' ); - - if ( $( this ).is( ':checked' ) ) { - - select_fields.fadeOut( 'fast', function() { - - custom_text_field.fadeIn(); - - } ); - - e.preventDefault(); - - return; - - } - - custom_text_field.fadeOut( 'fast', function() { - - select_fields.fadeIn(); - - }); - - e.preventDefault(); - - } ); - // Sortable $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index cc96c50..921c6be 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a("body").on("change",".js_wpcw_custom_text_checkbox",function(b){var c=a(this).parents(".day-container"),d=c.find("select"),e=c.find(".custom_text_field");return a(this).is(":checked")?(d.fadeOut("fast",function(){e.fadeIn()}),void b.preventDefault()):(e.fadeOut("fast",function(){d.fadeIn()}),void b.preventDefault())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(b){var c=a(this);c.find("div.hidden-container").slideToggle("fast",function(){return c.hasClass("closed")?void c.removeClass("closed").addClass("open"):void c.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();c.parent(".hidden-container").find(".hours-selection").length+1;d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index a33244d..93dbbcf 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -412,18 +412,18 @@ protected function render_day_input( $field, $day, array $hours ) { $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); $field['disabled'] = $hours['not_open'] ? true : false; - $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . sprintf( _x( 'Apply to All %s', 'Dashicon Down Arrow', 'contact-widgets' ), '' ) . '' : ''; + $open_label = $hours['not_open'] ? __( 'CLOSED', 'wp-contact-widgets' ) : __( 'OPEN', 'wp-contact-widgets' ); + $open_class = $hours['not_open'] ? 'closed' : 'open'; - $custom_text_checkbox = 'checked( $hours['custom_text_checkbox'], true ) . '>'; - $hidden_text_field = ( ! $hours['custom_text_checkbox'] ) ? ' style="display:none;"' : ''; - $custom_text_field = ''; - $closed_checkbox = 'checked( $hours['not_open'], true ) . '>'; + $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . __( 'Apply to All', 'contact-widgets' ) . '' : ''; + + $closed_checkbox = 'checked( $hours['not_open'], true ) . '>'; printf( - '
    %1$s

    %2$s %3$s

    ', - '' . esc_html( ucwords( $day ) ) . '' . $apply_to_all_toggle . $custom_text_checkbox . $closed_checkbox . '', + '
    %1$s
    %2$s %3$s
    ', + '' . esc_html( ucwords( $day ) ) . '' . $open_label . '', $this->render_hours_selection( $field, sanitize_title( $day ), $hours ), - $custom_text_field + '' . $apply_to_all_toggle . $closed_checkbox . '' ); } @@ -448,47 +448,64 @@ protected function render_hours_selection( $field, $day, $hours ) { $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); $disabled_field = $field['disabled'] ? ' disabled="disabled"' : ''; - $hidden_field = $hours['custom_text_checkbox'] ? ' style="display:none;"' : ''; - ?> + $x = 1; - > - + - ?> + - + " > + } - - foreach ( $times as $time ) { + - ?> + + + + + + + + '; ?> + + + +

    + + $hours ) { $this->render_day_input( $fields['days'], $day, $hours ); @@ -106,34 +104,42 @@ public function widget( $args, $instance ) { foreach ( $field['days'] as $day_of_week => $store_hours ) { - $hours = $store_hours['not_open'] ? __( 'Closed', 'contact-widgets' ) : $store_hours['open'] . apply_filters( 'wpcw_hours_seperator', ' - ' ) . $store_hours['closed']; - $class = $store_hours['not_open'] ? 'closed' : 'open'; - - if ( $store_hours['custom_text_checkbox'] || $store_hours['not_open'] ) { - - $text = $store_hours['not_open'] ? $hours : $store_hours['custom_text']; + if ( $store_hours['not_open'] ) { printf( '
  • %1$s %2$s
  • ', '' . esc_html( ucwords( $day_of_week ) ) . '', - esc_html( $text ) + '
    ' . __( 'Closed', 'wp-contact-widgets' ) . '
    ' ); continue; } + $hour_length = count( $store_hours['open'] ); + + $x = 1; + $microformat_data = [ - 'day' => $day_of_week, - 'open' => $store_hours['open'], - 'close' => $store_hours['closed'], + 'day' => $day_of_week, + 'open' => $store_hours['open'], + 'close' => $store_hours['closed'], ]; + $hours = []; + + while ( $x <= $hour_length ) { + + $hours[] = '
    '; + + $x++; + + } + printf( - '
  • %2$s %3$s
  • ', - $this->get_microformat_markup( $microformat_data ), + '
  • %1$s %2$s
  • ', '' . esc_html( ucwords( $day_of_week ) ) . '', - '
    ' . esc_html( $hours ) . '
    ' + '
    ' . implode( '', $hours ) . '
    ' ); } @@ -170,10 +176,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', 'sortable' => false, ], - 'days' => [ - 'label' => __( 'Days of the week:', 'contact-widgets' ), - 'description' => __( 'Enter your hours in the following fields.', 'contact-widgets' ), - ], + 'days' => [], 'additional_content' => [ 'label' => __( 'Additional Info.', 'contact-widgets' ), 'type' => 'textarea', @@ -192,8 +195,6 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, - 'custom_text' => ! empty( $instance['days'][ $day ]['custom_text'] ) ? $instance['days'][ $day ]['custom_text'] : '', - 'custom_text_checkbox' => isset( $instance['days'][ $day ]['custom_text_checkbox'] ) ? true : false, ]; } @@ -251,11 +252,11 @@ public function get_days_of_week() { * * @return string */ - protected function get_microformat_markup( $microformat_data ) { + protected function get_microformat_markup( $microformat_data, $iteration ) { $day = ucwords( substr( $microformat_data['day'], 0, 2 ) ); - $open = date( 'H:i', strtotime( $microformat_data['open'] ) ); - $close = date( 'H:i', strtotime( $microformat_data['close'] ) ); + $open = date( 'H:i', strtotime( $microformat_data['open'][ $iteration ] ) ); + $close = date( 'H:i', strtotime( $microformat_data['close'][ $iteration ] ) ); $microformat_attributes = [ 'itemprop="openingHours"', From e9d98d6b7e0bede72ce369f7eced5017496aadbb Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 10:59:20 -0500 Subject: [PATCH 26/90] Refactor to avoid undefined variable. Add wpcw_hour_increment filter. --- assets/css/style.css | 10 ++++++--- assets/css/style.min.css | 2 +- includes/class-base-widget.php | 39 ++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index bb00a01..8798a3b 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -1,17 +1,21 @@ .wpcw-widget-contact ul, -.wpcw-widget-social ul { +.wpcw-widget-social ul, +.wpcw-widget-hours ul { margin: 0; padding: 0; list-style: none; } .wpcw-widget-contact ul li, -.wpcw-widget-social ul li.has-label { +.wpcw-widget-social ul li.has-label, +.wpcw-widget-hours ul li { padding: 10px 0; } .wpcw-widget-contact ul li:before, .wpcw-widget-contact ul li:after, .wpcw-widget-social ul li:before, -.wpcw-widget-social ul li:after { +.wpcw-widget-social ul li:after, +.wpcw-widget-hours ul li:before, +.wpcw-widget-hours ul li:after { display: none; } .wpcw-widget-contact ul li div { diff --git a/assets/css/style.min.css b/assets/css/style.min.css index 0fb6175..6ce7428 100644 --- a/assets/css/style.min.css +++ b/assets/css/style.min.css @@ -1 +1 @@ -.wpcw-widget-contact ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em} \ No newline at end of file +.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em} \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 93dbbcf..cfdb89e 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -443,7 +443,7 @@ protected function render_hours_selection( $field, $day, $hours ) { ob_start(); - $times = $this->get_half_hour_time_array(); + $times = $this->get_time_array(); $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); @@ -463,9 +463,11 @@ protected function render_hours_selection( $field, $day, $hours ) { foreach ( $times as $time ) { + $select = isset( $hours['open'][ $x ] ) ? $hours['open'][ $x ] : ''; + ?> - + - + Date: Tue, 20 Dec 2016 11:00:19 -0500 Subject: [PATCH 27/90] Remove 'hour' from the available hour increment. --- includes/class-base-widget.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index cfdb89e..5a54590 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -539,12 +539,6 @@ protected function get_time_array() { break; - case 'hour': - - $step = 3600; - - break; - } $steps = range( 0, 47 * 1800, $step ); From 864ccbdc145b36c0eb3730ad34164e327313ec63 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 11:15:50 -0500 Subject: [PATCH 28/90] Added wpcw_widget_hours_first_day filter, allowing users to set the first day in the widget to the current day of the week. --- includes/class-hours.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index b62a0fc..d78d6e2 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -209,7 +209,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t * * @var array */ - return (array) apply_filters( 'wphoow_widget_contact_fields', $fields, $instance ); + return (array) apply_filters( 'wpcw_widget_hours_fields', $fields, $instance ); } @@ -220,8 +220,6 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t */ public function get_days_of_week() { - $start_of_week = get_option( 'start_of_week', 1 ); - $days_of_the_week = [ __( 'Monday', 'contact-widgets' ), __( 'Tuesday', 'contact-widgets' ), @@ -232,6 +230,23 @@ public function get_days_of_week() { __( 'Sunday', 'contact-widgets' ), ]; + switch ( apply_filters( 'wpcw_widget_hours_first_day', 'start_of_week' ) ) { + + case 'current_day': + + $start_of_week = array_search( date( 'l', current_time( 'timestamp' ) ), $days_of_the_week ) + 1; + + break; + + case 'start_of_week': + default: + + $start_of_week = get_option( 'start_of_week', 1 ); + + break; + + } + if ( 1 < $start_of_week ) { return array_merge( array_splice( $days_of_the_week, ( $start_of_week - 1 ) ), $days_of_the_week ); From d8cc2f4272fb2bc0e3c1adf107f0d34b5d1fe934 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 11:16:52 -0500 Subject: [PATCH 29/90] Fix array spacing. --- includes/class-hours.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index d78d6e2..0a2f34b 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -178,12 +178,12 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t ], 'days' => [], 'additional_content' => [ - 'label' => __( 'Additional Info.', 'contact-widgets' ), + 'label' => __( 'Additional Info.', 'contact-widgets' ), 'type' => 'textarea', 'sanitizer' => function( $value ) { return current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( stripslashes( $value ) ); }, 'escaper' => function( $value ) { return nl2br( apply_filters( 'widget_text', $value ) ); }, 'form_callback' => 'render_form_textarea', - 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), + 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), ], ]; @@ -192,9 +192,9 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t $day = strtolower( $day ); $fields['days']['days'][ $day ] = [ - 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', - 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', - 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, + 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', + 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', + 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, ]; } From 89a17f077650a0253473cb5c3dc80d999feffcb8 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 11:18:46 -0500 Subject: [PATCH 30/90] Add dockblocks to new filters. --- includes/class-base-widget.php | 7 +++++++ includes/class-hours.php | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 5a54590..1ad9926 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -524,6 +524,13 @@ protected function render_hours_selection( $field, $day, $hours ) { */ protected function get_time_array() { + /** + * Filter the hour increments in the select field + * + * @since NEXT + * + * @return string + */ switch ( apply_filters( 'wpcw_hour_increment', 'half_hour' ) ) { case 'fifteen_minutes': diff --git a/includes/class-hours.php b/includes/class-hours.php index 0a2f34b..2fa032a 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -207,7 +207,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t * * @since NEXT * - * @var array + * @return array */ return (array) apply_filters( 'wpcw_widget_hours_fields', $fields, $instance ); @@ -216,6 +216,8 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t /** * Return an array of days of the week * + * @since NEXT + * * @return array */ public function get_days_of_week() { @@ -230,6 +232,13 @@ public function get_days_of_week() { __( 'Sunday', 'contact-widgets' ), ]; + /** + * Filter the start of the week on the front end + * + * @since NEXT + * + * @return string + */ switch ( apply_filters( 'wpcw_widget_hours_first_day', 'start_of_week' ) ) { case 'current_day': @@ -253,7 +262,7 @@ public function get_days_of_week() { } - return $days_of_the_week; + return (array) $days_of_the_week; } From bb6d088ce4854289784c74b239dd3ffbe7e33f52 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 12:45:55 -0500 Subject: [PATCH 31/90] Add docblock, introduce new filters, introduce new method is_business_open(), add new styles to front-end hours widget. --- assets/css/style.css | 17 +++++++++ assets/css/style.min.css | 2 +- includes/class-hours.php | 79 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index 8798a3b..de67df0 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -33,3 +33,20 @@ .wpcw-widget-social ul li.has-label span { margin-right: 0.25em; } +.wpcw-widget-hours ul li span.open-sign { + display: inline-block; + margin: 0 0 3px 5px; + padding: 2px 5px; + border-radius: 4px; + border: 1px solid transparent; +} +.wpcw-widget-hours ul li span.open-sign.open { + background-color: #dff0d8; + border-color: #d6e9c6; + color: #3c763d; +} +.wpcw-widget-hours ul li span.open-sign.closed { + background-color: #f2dede; + border-color: #ebccd1; + color: #a94442; +} diff --git a/assets/css/style.min.css b/assets/css/style.min.css index 6ce7428..4acc9c6 100644 --- a/assets/css/style.min.css +++ b/assets/css/style.min.css @@ -1 +1 @@ -.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em} \ No newline at end of file +.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em}.wpcw-widget-hours ul li span.open-sign{display:inline-block;margin:0 0 3px 5px;padding:2px 5px;border-radius:4px;border:1px solid transparent}.wpcw-widget-hours ul li span.open-sign.open{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}.wpcw-widget-hours ul li span.open-sign.closed{background-color:#f2dede;border-color:#ebccd1;color:#a94442} \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 2fa032a..4865549 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -10,6 +10,10 @@ final class Hours extends Base_Widget { + private $current_day; + + private $current_time; + /** * Widget constructor */ @@ -27,6 +31,9 @@ public function __construct() { $widget_options ); + $this->current_time = current_time( 'timestamp' ); + $this->current_day = strtolower( date( 'l', $this->current_time ) ); + } /** @@ -108,7 +115,7 @@ public function widget( $args, $instance ) { printf( '
  • %1$s %2$s
  • ', - '' . esc_html( ucwords( $day_of_week ) ) . '', + '' . esc_html( ucwords( $day_of_week ) ) . $this->open_sign( $day_of_week, $store_hours ) . '', '
    ' . __( 'Closed', 'wp-contact-widgets' ) . '
    ' ); @@ -138,7 +145,7 @@ public function widget( $args, $instance ) { printf( '
  • %1$s %2$s
  • ', - '' . esc_html( ucwords( $day_of_week ) ) . '', + '' . esc_html( ucwords( $day_of_week ) ) . $this->open_sign( $day_of_week, $store_hours ) . '', '
    ' . implode( '', $hours ) . '
    ' ); @@ -243,7 +250,7 @@ public function get_days_of_week() { case 'current_day': - $start_of_week = array_search( date( 'l', current_time( 'timestamp' ) ), $days_of_the_week ) + 1; + $start_of_week = array_search( date( 'l', $this->current_time ), $days_of_the_week ) + 1; break; @@ -291,4 +298,70 @@ protected function get_microformat_markup( $microformat_data, $iteration ) { } + /** + * Generate the open sign on the front-end + * + * @param string $day The current day in the iteration. + * @param array $hours Open/Closed hours. + * + * @since NEXT + * + * + * @return mixed + */ + protected function open_sign( $day, $hours ) { + + /** + * Allow users to disable the open sign + * + * @since NEXT + * + * @return string + */ + if ( (bool) ! apply_filters( 'wpcw_widget_hours_open_sign', true ) || $this->current_day !== $day ) { + + return; + + } + + $open_sign_text = $this->is_business_open( $hours ) ? __( 'Open', 'wp-contact-widgets' ) : __( 'Closed', 'wp-contact-widgets' ); + $open_sign_class = $this->is_business_open( $hours ) ? 'open' : 'closed'; + + return sprintf( + '%2$s', + esc_attr( $open_sign_class ), + apply_filters( 'wpcw_widget_hours_open_sign_text', $open_sign_text, $this->is_business_open( $hours ) ) + ); + + } + + /** + * Check if the business is open based on the current server time + * + * @param array $hours Open/Closed times + * + * @since NEXT + * + * @return boolean + */ + protected function is_business_open( $hours ) { + + $iteration = 1; + + foreach ( $hours['open'] as $open_hours ) { + + if ( $this->current_time >= strtotime( $open_hours ) && $this->current_time <= strtotime( $hours['closed'][ $iteration ] ) ) { + + return true; + + } + + $iteration++; + + } + + return false; + + } + } From 0a8ddfbc4c8e9903d15be5a9bf060a2443713f24 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 12:48:28 -0500 Subject: [PATCH 32/90] Refactor, run is_business_open() once for performance. --- includes/class-hours.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 4865549..cc5c204 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -324,13 +324,14 @@ protected function open_sign( $day, $hours ) { } - $open_sign_text = $this->is_business_open( $hours ) ? __( 'Open', 'wp-contact-widgets' ) : __( 'Closed', 'wp-contact-widgets' ); - $open_sign_class = $this->is_business_open( $hours ) ? 'open' : 'closed'; + $business_open = $this->is_business_open( $hours ); + $open_sign_text = $business_open ? __( 'Open', 'wp-contact-widgets' ) : __( 'Closed', 'wp-contact-widgets' ); + $open_sign_class = $business_open ? 'open' : 'closed'; return sprintf( '%2$s', esc_attr( $open_sign_class ), - apply_filters( 'wpcw_widget_hours_open_sign_text', $open_sign_text, $this->is_business_open( $hours ) ) + apply_filters( 'wpcw_widget_hours_open_sign_text', $open_sign_text, $business_open ) ); } From 6d6fc2defe8ac5a1ac0c522a60e7f7d1719f4bbb Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 12:54:55 -0500 Subject: [PATCH 33/90] Add action hooks for before/after each day in the widget. --- includes/class-hours.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/class-hours.php b/includes/class-hours.php index cc5c204..788adbf 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -111,6 +111,8 @@ public function widget( $args, $instance ) { foreach ( $field['days'] as $day_of_week => $store_hours ) { + do_action( 'wpcw_widget_hours_before_day', $day_of_week ); + if ( $store_hours['not_open'] ) { printf( @@ -149,6 +151,8 @@ public function widget( $args, $instance ) { '
    ' . implode( '', $hours ) . '
    ' ); + do_action( 'wpcw_widget_hours_after_day', $day_of_week ); + } continue; From 5d59db85ac05fce93dc02298148f5562e2194369 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 13:01:26 -0500 Subject: [PATCH 34/90] Update js files to pass tests. --- assets/js/admin.js | 9 ++++----- assets/js/admin.min.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 665ae7d..3c9e786 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -166,7 +166,7 @@ // Social $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); - $( 'body' ).on( 'click', '.day-container', function( e ) { + $( 'body' ).on( 'click', '.day-container', function() { var container = $( this ); @@ -189,14 +189,13 @@ $( 'body' ).on( 'click', '.add-time', function( e ) { var parent_container = $( this ).parents( '.hidden-container' ).find( '.hours-selection' ).last(), - clone = parent_container.clone(), - length = parent_container.parent( '.hidden-container' ).find( '.hours-selection' ).length + 1; + clone = parent_container.clone(); - clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( "name", function( i, name ) { + clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { return name.replace( /\[(\d+)\]$/, function( match, number ) { - return "[" + ( + number + 1 ) + "]"; + return '[' + ( + number + 1 ) + ']'; } ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 921c6be..bf771e2 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(b){var c=a(this);c.find("div.hidden-container").slideToggle("fast",function(){return c.hasClass("closed")?void c.removeClass("closed").addClass("open"):void c.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();c.parent(".hidden-container").find(".hours-selection").length+1;d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From 23fb005ade891d4249431d069cea088f0edc3a3e Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 13:18:46 -0500 Subject: [PATCH 35/90] Resolve warning on front-end display when shop is closed all day. --- assets/js/admin.js | 1 + assets/js/admin.min.js | 2 +- includes/class-hours.php | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 3c9e786..f8d336a 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -254,6 +254,7 @@ $( '.wpcw-widget-hours .day-container' ).find( 'select' ).attr( 'disabled', 'disabled' ); $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', true ); + $( '.wpcw-widget-hours .day-container' ).find( '.hours-selection:not(:first)' ).remove(); e.preventDefault(); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index bf771e2..f0914e5 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 788adbf..bbdf89f 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -353,6 +353,12 @@ protected function is_business_open( $hours ) { $iteration = 1; + if ( $hours['not_open'] ) { + + return false; + + } + foreach ( $hours['open'] as $open_hours ) { if ( $this->current_time >= strtotime( $open_hours ) && $this->current_time <= strtotime( $hours['closed'][ $iteration ] ) ) { From 3a7c2dbee2b40d426bb81ca5c473c15dc5efa380 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 16:15:34 -0500 Subject: [PATCH 36/90] Tweak .js. Adjust styles. Tweak input field render. Add checkbox to allow users to set current day to first in widget. --- assets/css/admin.css | 4 ++- assets/css/admin.min.css | 2 +- assets/js/admin.js | 50 ++++++++++++++++++++++++++++++---- assets/js/admin.min.js | 2 +- includes/class-base-widget.php | 10 +++++-- includes/class-hours.php | 50 ++++++++++++++++++---------------- 6 files changed, 85 insertions(+), 33 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 32f532c..41fb416 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -106,6 +106,7 @@ .wpcw-widget-hours .form div.hours-selection { width: 100%; + float: left; } .wpcw-widget-hours .form div:first-child { @@ -152,7 +153,8 @@ margin-top: 8px; } - .wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle { + .wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle, + .wpcw-widget-hours .day_order .wpcw-widget-sortable-handle { display: none; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 7b4d20c..c50ba89 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div.day-container{display:inline-block;width:100%;padding:15px 0;border-top:1px solid rgba(128,128,128,.27)}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle,.wpcw-widget-hours .day-container.closed div.hidden-container{display:none}.wpcw-widget-hours .form div.hours-selection{width:100%}.wpcw-widget-hours .form div:first-child{border-top:none}.wpcw-widget-hours .day-container:hover{cursor:pointer}.wpcw-widget-hours .day-container span.open-label{float:right;margin-right:5px}.wpcw-widget-hours .day-container .toggle{font-family:Dashicons;float:right;font-size:20px}.wpcw-widget-hours .day-container.closed .toggle:before{content:"\f140"}.wpcw-widget-hours .day-container.open .toggle:before{content:"\f142"}.wpcw-widget-hours .day-container .open-label.closed{opacity:.5}.wpcw-widget-hours .day-container .open-label.open{color:#59CE45;font-weight:600}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all{float:left}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:8px}.wpcw-widget-hours .day-checkbox-toggle{display:inline-block;width:100%;text-align:right;margin-top:8px}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:40%;min-width:auto;float:left;margin-bottom:5px}.wpcw-widget-hours .add-time,.wpcw-widget-hours .remove-time{width:15%;float:right;text-align:center;margin-bottom:5px}.wpcw-widget-hours .remove-time span.dashicons{line-height:1.4}.wpcw-widget-hours .form div .hidden-container{display:inline-block;width:100%;margin:8px 0;float:left} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div.day-container{display:inline-block;width:100%;padding:15px 0;border-top:1px solid rgba(128,128,128,.27)}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle,.wpcw-widget-hours .day-container.closed div.hidden-container,.wpcw-widget-hours .day_order .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form div.hours-selection{width:100%;float:left}.wpcw-widget-hours .form div:first-child{border-top:none}.wpcw-widget-hours .day-container:hover{cursor:pointer}.wpcw-widget-hours .day-container span.open-label{float:right;margin-right:5px}.wpcw-widget-hours .day-container .toggle{font-family:Dashicons;float:right;font-size:20px}.wpcw-widget-hours .day-container.closed .toggle:before{content:"\f140"}.wpcw-widget-hours .day-container.open .toggle:before{content:"\f142"}.wpcw-widget-hours .day-container .open-label.closed{opacity:.5}.wpcw-widget-hours .day-container .open-label.open{color:#59CE45;font-weight:600}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all{float:left}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:8px}.wpcw-widget-hours .day-checkbox-toggle{display:inline-block;width:100%;text-align:right;margin-top:8px}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:40%;min-width:auto;float:left;margin-bottom:5px}.wpcw-widget-hours .add-time,.wpcw-widget-hours .remove-time{width:15%;float:right;text-align:center;margin-bottom:5px}.wpcw-widget-hours .remove-time span.dashicons{line-height:1.4}.wpcw-widget-hours .form div .hidden-container{display:inline-block;width:100%;margin:8px 0;float:left} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index f8d336a..c61d642 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -263,13 +263,53 @@ } var first_container = $( this ).parents( '.day-container' ), - open = first_container.find( 'select:first-child' ).val(), - closed = first_container.find( 'select:nth-child(2)' ).val(); + length = $( this ).parents( '.day-container' ).find( '.hours-selection' ).length; - $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input[type="checkbox"]' ).prop( 'checked', false ); $( '.wpcw-widget-hours .day-container' ).find( 'select' ).removeAttr( 'disabled' ); - $( '.wpcw-widget-hours .day-container' ).find( 'select:first-child' ).val( open ); - $( '.wpcw-widget-hours .day-container' ).find( 'select:nth-child(2)' ).val( closed ); + $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', false ); + + $( '.day-container' ).not( first_container ).each( function() { + + $( this ).find( '.hidden-container .hours-selection:not(:first)' ).remove(); + + var y = 1, + z = 0; + + while ( y < length ) { + + var duplicate = $( this ).find( '.hidden-container .hours-selection' ).last().clone(); + + duplicate.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { + + return name.replace( /\[(\d+)\]$/, function( match, number ) { + + return '[' + ( + number + 1 ) + ']'; + + } ); + + } ); + + duplicate.find( '.add-time' ).replaceWith( '' ); + + duplicate.insertAfter( $( this ).find( '.hidden-container .hours-selection' ).last() ); + + y++; + + } + + while ( z <= length ) { + + var open = first_container.find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val(), + closed = first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); + + $( this ).find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val( open ); + $( this ).find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val( closed ); + + z++; + + } + + } ); e.preventDefault(); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index f0914e5..a4aa054 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=c.find("select:first-child").val(),e=c.find("select:nth-child(2)").val();a(".wpcw-widget-hours .day-checkbox-toggle").find('input[type="checkbox"]').prop("checked",!1),a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-container").find("select:first-child").val(d),a(".wpcw-widget-hours .day-container").find("select:nth-child(2)").val(e),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 1ad9926..fc41601 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -312,6 +312,12 @@ protected function before_form_field( array $field ) { */ protected function render_form_input( array $field ) { + if ( ! is_admin() ) { + + return; + + } + $this->before_form_field( $field ); printf( @@ -412,7 +418,7 @@ protected function render_day_input( $field, $day, array $hours ) { $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); $field['disabled'] = $hours['not_open'] ? true : false; - $open_label = $hours['not_open'] ? __( 'CLOSED', 'wp-contact-widgets' ) : __( 'OPEN', 'wp-contact-widgets' ); + $open_label = $hours['not_open'] ? __( 'CLOSED', 'contact-widgets' ) : __( 'OPEN', 'contact-widgets' ); $open_class = $hours['not_open'] ? 'closed' : 'open'; $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . __( 'Apply to All', 'contact-widgets' ) . '' : ''; @@ -499,7 +505,7 @@ protected function render_hours_selection( $field, $day, $hours ) { - '; ?> + '; ?> diff --git a/includes/class-hours.php b/includes/class-hours.php index bbdf89f..d3ce17b 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -118,7 +118,7 @@ public function widget( $args, $instance ) { printf( '
  • %1$s %2$s
  • ', '' . esc_html( ucwords( $day_of_week ) ) . $this->open_sign( $day_of_week, $store_hours ) . '', - '
    ' . __( 'Closed', 'wp-contact-widgets' ) . '
    ' + '
    ' . __( 'Closed', 'contact-widgets' ) . '
    ' ); continue; @@ -159,6 +159,12 @@ public function widget( $args, $instance ) { } + if ( ! $field['show_front_end'] ) { + + continue; + + } + $escape_callback = $field['escaper']; echo apply_filters( 'the_content', $escape_callback( $field['value'] ) ); @@ -196,9 +202,23 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'form_callback' => 'render_form_textarea', 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), ], + 'day_order' => [ + 'label' => __( 'Current Day on Top', 'contact-widgets' ), + 'type' => 'checkbox', + 'label_after' => true, + 'show_front_end' => false, + 'default' => 'no', + 'value' => 1, + ], ]; - foreach ( $this->get_days_of_week() as $day ) { + if ( 'no' !== $instance['day_order']['value'] ) { + + $fields['day_order']['atts'] = 'checked="checked"'; + + } + + foreach ( $this->get_days_of_week( $instance['day_order']['value'] ) as $day ) { $day = strtolower( $day ); @@ -231,7 +251,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t * * @return array */ - public function get_days_of_week() { + public function get_days_of_week( $current_day ) { $days_of_the_week = [ __( 'Monday', 'contact-widgets' ), @@ -243,27 +263,11 @@ public function get_days_of_week() { __( 'Sunday', 'contact-widgets' ), ]; - /** - * Filter the start of the week on the front end - * - * @since NEXT - * - * @return string - */ - switch ( apply_filters( 'wpcw_widget_hours_first_day', 'start_of_week' ) ) { - - case 'current_day': - - $start_of_week = array_search( date( 'l', $this->current_time ), $days_of_the_week ) + 1; - - break; - - case 'start_of_week': - default: + $start_of_week = get_option( 'start_of_week', 1 ); - $start_of_week = get_option( 'start_of_week', 1 ); + if ( 'no' !== $current_day && ! is_admin() ) { - break; + $start_of_week = array_search( date( 'l', $this->current_time ), $days_of_the_week ) + 1; } @@ -329,7 +333,7 @@ protected function open_sign( $day, $hours ) { } $business_open = $this->is_business_open( $hours ); - $open_sign_text = $business_open ? __( 'Open', 'wp-contact-widgets' ) : __( 'Closed', 'wp-contact-widgets' ); + $open_sign_text = $business_open ? __( 'Open', 'contact-widgets' ) : __( 'Closed', 'contact-widgets' ); $open_sign_class = $business_open ? 'open' : 'closed'; return sprintf( From 5a937236965134f737908b9b2dc2f8fac1549503 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 17:12:15 -0500 Subject: [PATCH 37/90] Align array data, remove test is_admin(). --- includes/class-base-widget.php | 6 ------ includes/class-hours.php | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index fc41601..241cfee 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -312,12 +312,6 @@ protected function before_form_field( array $field ) { */ protected function render_form_input( array $field ) { - if ( ! is_admin() ) { - - return; - - } - $this->before_form_field( $field ); printf( diff --git a/includes/class-hours.php b/includes/class-hours.php index d3ce17b..760daac 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -203,12 +203,12 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), ], 'day_order' => [ - 'label' => __( 'Current Day on Top', 'contact-widgets' ), - 'type' => 'checkbox', - 'label_after' => true, + 'label' => __( 'Current Day on Top', 'contact-widgets' ), + 'type' => 'checkbox', + 'label_after' => true, 'show_front_end' => false, - 'default' => 'no', - 'value' => 1, + 'default' => 'no', + 'value' => 1, ], ]; From 202a1cc71f507f6647a51c5e46b41ec09bec3aa7 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Tue, 20 Dec 2016 18:16:55 -0500 Subject: [PATCH 38/90] Update spacing in .js file. --- assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index c61d642..28f12a2 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -300,7 +300,7 @@ while ( z <= length ) { var open = first_container.find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val(), - closed = first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); + closed = first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); $( this ).find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val( open ); $( this ).find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val( closed ); From 180b1c0a6fb310a4f4a59b5969fa9c3fd15ee716 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 11:53:03 -0500 Subject: [PATCH 39/90] Update misspelled work --- assets/js/admin.js | 2 +- assets/js/admin.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 28f12a2..6ca03e6 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -220,7 +220,7 @@ } ); - e.preventDefualt(); + e.preventDefalt(); } ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index a4aa054..a2e77ac 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefualt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefalt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From 665acab617294c49b2fa241c0fbb28ee588af270 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 11:53:28 -0500 Subject: [PATCH 40/90] Update misspelled work --- assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 6ca03e6..8945a90 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -220,7 +220,7 @@ } ); - e.preventDefalt(); + e.preventDefault(); } ); From e41cd5fb9c8f650e23d96942f3268faf6447a63e Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 11:58:33 -0500 Subject: [PATCH 41/90] Update day_order label. --- includes/class-hours.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 760daac..fa4bc86 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -203,7 +203,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), ], 'day_order' => [ - 'label' => __( 'Current Day on Top', 'contact-widgets' ), + 'label' => __( 'Keep the current day at the top of the widget.', 'contact-widgets' ), 'type' => 'checkbox', 'label_after' => true, 'show_front_end' => false, From d4774c69e0f3d441e619eb68a59fa824378d8250 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 12:43:03 -0500 Subject: [PATCH 42/90] Prefix content variables with $ --- assets/js/admin.js | 40 ++++++++++++++++++++-------------------- assets/js/admin.min.js | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 8945a90..9a8c08b 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -188,10 +188,10 @@ $( 'body' ).on( 'click', '.add-time', function( e ) { - var parent_container = $( this ).parents( '.hidden-container' ).find( '.hours-selection' ).last(), - clone = parent_container.clone(); + var $parent_container = $( this ).parents( '.hidden-container' ).find( '.hours-selection' ).last(), + $clone = $parent_container.clone(); - clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { + $clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { return name.replace( /\[(\d+)\]$/, function( match, number ) { @@ -201,9 +201,9 @@ }); - clone.find( '.add-time' ).replaceWith( '' ); + $clone.find( '.add-time' ).replaceWith( '' ); - clone.insertAfter( parent_container ); + $clone.insertAfter( $parent_container ); e.preventDefault(); @@ -211,12 +211,12 @@ $( 'body' ).on( 'click', '.remove-time', function( e ) { - var button = $( this ), - parent = button.parent( '.hours-selection' ); + var $button = $( this ), + $parent = $button.parent( '.hours-selection' ); - parent.fadeOut( 'fast', function() { + $parent.fadeOut( 'fast', function() { - parent.remove(); + $parent.remove(); } ); @@ -233,17 +233,17 @@ // Hours of Operation select field toggle $( 'body' ).on( 'change', '.js_wpcw_closed_checkbox', function( e ) { - var select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); + var $select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); if ( $( this ).is( ':checked' ) ) { - select_fields.attr( 'disabled', 'disabled' ); + $select_fields.attr( 'disabled', 'disabled' ); return; } - select_fields.removeAttr( 'disabled' ); + $select_fields.removeAttr( 'disabled' ); } ); @@ -262,13 +262,13 @@ } - var first_container = $( this ).parents( '.day-container' ), + var $first_container = $( this ).parents( '.day-container' ), length = $( this ).parents( '.day-container' ).find( '.hours-selection' ).length; $( '.wpcw-widget-hours .day-container' ).find( 'select' ).removeAttr( 'disabled' ); $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', false ); - $( '.day-container' ).not( first_container ).each( function() { + $( '.day-container' ).not( $first_container ).each( function() { $( this ).find( '.hidden-container .hours-selection:not(:first)' ).remove(); @@ -277,9 +277,9 @@ while ( y < length ) { - var duplicate = $( this ).find( '.hidden-container .hours-selection' ).last().clone(); + var $duplicate = $( this ).find( '.hidden-container .hours-selection' ).last().clone(); - duplicate.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { + $duplicate.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { return name.replace( /\[(\d+)\]$/, function( match, number ) { @@ -289,9 +289,9 @@ } ); - duplicate.find( '.add-time' ).replaceWith( '' ); + $duplicate.find( '.add-time' ).replaceWith( '' ); - duplicate.insertAfter( $( this ).find( '.hidden-container .hours-selection' ).last() ); + $duplicate.insertAfter( $( this ).find( '.hidden-container .hours-selection' ).last() ); y++; @@ -299,8 +299,8 @@ while ( z <= length ) { - var open = first_container.find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val(), - closed = first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); + var open = $first_container.find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val(), + closed = $first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); $( this ).find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val( open ); $( this ).find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val( closed ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index a2e77ac..6c74457 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefalt()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From 001894c075282cc1818d29396f254d81197b6567 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 12:45:17 -0500 Subject: [PATCH 43/90] Change .attr/.removeAttr to .prop() --- assets/js/admin.js | 8 ++++---- assets/js/admin.min.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 9a8c08b..b149485 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -237,13 +237,13 @@ if ( $( this ).is( ':checked' ) ) { - $select_fields.attr( 'disabled', 'disabled' ); + $select_fields.prop( 'disabled', true ); return; } - $select_fields.removeAttr( 'disabled' ); + $select_fields.prop( 'disabled', false ); } ); @@ -252,7 +252,7 @@ if ( $( this ).parents( '.day-container' ).find( 'input.js_wpcw_closed_checkbox' ).is( ':checked' ) ) { - $( '.wpcw-widget-hours .day-container' ).find( 'select' ).attr( 'disabled', 'disabled' ); + $( '.wpcw-widget-hours .day-container' ).find( 'select' ).prop( 'disabled', true ); $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', true ); $( '.wpcw-widget-hours .day-container' ).find( '.hours-selection:not(:first)' ).remove(); @@ -265,7 +265,7 @@ var $first_container = $( this ).parents( '.day-container' ), length = $( this ).parents( '.day-container' ).find( '.hours-selection' ).length; - $( '.wpcw-widget-hours .day-container' ).find( 'select' ).removeAttr( 'disabled' ); + $( '.wpcw-widget-hours .day-container' ).find( 'select' ).prop( 'disabled', false ); $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', false ); $( '.day-container' ).not( $first_container ).each( function() { diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 6c74457..f3cbcca 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.attr("disabled","disabled"):void c.removeAttr("disabled")}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").attr("disabled","disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").removeAttr("disabled"),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.prop("disabled",!0):void c.prop("disabled",!1)}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!0),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!1),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From 8f54b399e7ef7e52dad912c038d0af24e37cd704 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 21 Dec 2016 12:47:12 -0500 Subject: [PATCH 44/90] Unify .click target --- assets/js/admin.js | 2 +- assets/js/admin.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index b149485..df603f3 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -166,7 +166,7 @@ // Social $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); - $( 'body' ).on( 'click', '.day-container', function() { + $( 'body' ).on( 'click', '.wpcw-widget-hours .day-container', function() { var container = $( this ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index f3cbcca..542ab8e 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.prop("disabled",!0):void c.prop("disabled",!1)}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!0),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!1),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".wpcw-widget-hours .day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.prop("disabled",!0):void c.prop("disabled",!1)}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!0),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!1),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From f427f15ba95401e782b8692bcfd7b85b021fabf8 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 27 Dec 2016 19:00:38 -0600 Subject: [PATCH 45/90] First pass at refector --- assets/css/admin.css | 154 +++++------ assets/css/admin.min.css | 2 +- assets/css/style.css | 3 +- assets/css/style.min.css | 2 +- assets/js/admin.js | 224 +++++++++------ assets/js/admin.min.js | 2 +- includes/class-base-widget.php | 319 +++++++++------------- includes/class-contact.php | 12 +- includes/class-hours.php | 479 +++++++++++++++++++++++---------- includes/class-social.php | 8 +- 10 files changed, 680 insertions(+), 525 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 41fb416..b289e85 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -97,119 +97,99 @@ /** * Hours of Operation Widget */ -.wpcw-widget-hours .form div.day-container { +.wpcw-widget-hours .day-row { display: inline-block; width: 100%; - padding: 15px 0; - border-top: 1px solid rgba(128, 128, 128, 0.27); + padding: 6px 0; + border-bottom: 1px solid #e5e5e5; } -.wpcw-widget-hours .form div.hours-selection { - width: 100%; - float: left; +.wpcw-widget-hours [class~='day-row']:last-of-type { + margin-bottom: 1em; + border-bottom: none; } - .wpcw-widget-hours .form div:first-child { - border-top: none; - } - - .wpcw-widget-hours .day-container:hover { - cursor: pointer; - } - - .wpcw-widget-hours .day-container span.open-label { - float: right; - margin-right: 5px; - } - - .wpcw-widget-hours .day-container .toggle { - font-family: "Dashicons"; - float: right; - font-size: 20px; - } +.wpcw-widget-hours .day-row-top { + padding: 6px 0; +} - .wpcw-widget-hours .day-container.closed .toggle:before { - content: "\f140"; - } +.wpcw-widget-hours .day-row-top:hover { + cursor: pointer; +} - .wpcw-widget-hours .day-container.open .toggle:before { - content: "\f142"; - } +.wpcw-widget-hours .day-row-top strong { + font-weight: 500; +} - .wpcw-widget-hours .day-container .open-label.closed { - opacity: 0.5; - } +.wpcw-widget-hours .toggle-icon { + float: right; + margin-top: -3px; +} - .wpcw-widget-hours .day-container .open-label.open { - color: #59CE45; - font-weight: 600; - } +.wpcw-widget-hours .status-open-label, +.wpcw-widget-hours .status-closed-label { + float: right; + width: 40%; + margin-right: 5px; + font-weight: 500; + font-size: 12px; + text-transform: uppercase; +} - .wpcw-widget-hours .day-container.closed div.hidden-container { - display: none; - } +.wpcw-widget-hours .status-open-label { + color: #59CE45; +} - .wpcw-widget-hours .form label + div { - margin-top: 8px; - } +.wpcw-widget-hours .status-closed-label { + opacity: 0.5; +} - .wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle, - .wpcw-widget-hours .day_order .wpcw-widget-sortable-handle { - display: none; - } +.wpcw-widget-hours .day-row.status-open .status-open-label, +.wpcw-widget-hours .day-row.status-closed .status-closed-label { + display: block; +} - .wpcw-widget-hours .form .js_wpcw_apply_hours_to_all { - float: left; - } +.wpcw-widget-hours .day-row.status-open .status-closed-label, +.wpcw-widget-hours .day-row.status-closed .status-open-label { + display: none; +} - .wpcw-widget-hours .form .js_wpcw_closed_checkbox, - .wpcw-widget-hours .form .js_wpcw_custom_text_checkbox { - display: inline-block; - margin-top: -1px; - } +.wpcw-widget-hours .day-row-container { + display: none; + float: left; + width: 100%; + margin: 10px 0 6px; +} - .wpcw-widget-hours .form input.js_wpcw_closed_checkbox { - margin-left: 8px; - } +.wpcw-widget-hours .time-block { + width: 100%; + float: left; + margin-bottom: 10px; +} - .wpcw-widget-hours .day-checkbox-toggle { - display: inline-block; - width: 100%; - text-align: right; - margin-top: 8px; - } +.wpcw-widget-hours .day-row-container div:last-of-type { + margin-bottom: 15px; +} -.wpcw-widget-hours .custom_text_field { - height: 28px; +.wpcw-widget-hours .time-block select { + width: calc(40% - 5px); + margin-right: 5px; } -.wpcw-widget-hours input[type="checkbox"] { - transform: scale( 0.75 ); - margin-right: 2px; +.wpcw-widget-hours .time-block .button { + width: calc(20% - 5px); + font-size: 18px; + text-align: center; } -.wpcw-widget-hours select { - width: 40%; - min-width: auto; +.wpcw-widget-hours .apply-to-all { float: left; - margin-bottom: 5px; } -.wpcw-widget-hours .add-time, -.wpcw-widget-hours .remove-time { - width: 15%; +.wpcw-widget-hours .status-closed-checkbox { float: right; - text-align: center; - margin-bottom: 5px; } -.wpcw-widget-hours .remove-time span.dashicons { - line-height: 1.4; -} - -.wpcw-widget-hours .form div .hidden-container { - display: inline-block; - width: 100%; - margin: 8px 0; - float: left; +.wpcw-widget-hours .status-closed-checkbox input { + margin: 2px 0 0 5px; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index c50ba89..1fbecb6 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .form div.day-container{display:inline-block;width:100%;padding:15px 0;border-top:1px solid rgba(128,128,128,.27)}.wpcw-widget-hours .additional_content .wpcw-widget-sortable-handle,.wpcw-widget-hours .day-container.closed div.hidden-container,.wpcw-widget-hours .day_order .wpcw-widget-sortable-handle{display:none}.wpcw-widget-hours .form div.hours-selection{width:100%;float:left}.wpcw-widget-hours .form div:first-child{border-top:none}.wpcw-widget-hours .day-container:hover{cursor:pointer}.wpcw-widget-hours .day-container span.open-label{float:right;margin-right:5px}.wpcw-widget-hours .day-container .toggle{font-family:Dashicons;float:right;font-size:20px}.wpcw-widget-hours .day-container.closed .toggle:before{content:"\f140"}.wpcw-widget-hours .day-container.open .toggle:before{content:"\f142"}.wpcw-widget-hours .day-container .open-label.closed{opacity:.5}.wpcw-widget-hours .day-container .open-label.open{color:#59CE45;font-weight:600}.wpcw-widget-hours .form label+div{margin-top:8px}.wpcw-widget-hours .form .js_wpcw_apply_hours_to_all{float:left}.wpcw-widget-hours .form .js_wpcw_closed_checkbox,.wpcw-widget-hours .form .js_wpcw_custom_text_checkbox{display:inline-block;margin-top:-1px}.wpcw-widget-hours .form input.js_wpcw_closed_checkbox{margin-left:8px}.wpcw-widget-hours .day-checkbox-toggle{display:inline-block;width:100%;text-align:right;margin-top:8px}.wpcw-widget-hours .custom_text_field{height:28px}.wpcw-widget-hours input[type=checkbox]{transform:scale(.75);margin-right:2px}.wpcw-widget-hours select{width:40%;min-width:auto;float:left;margin-bottom:5px}.wpcw-widget-hours .add-time,.wpcw-widget-hours .remove-time{width:15%;float:right;text-align:center;margin-bottom:5px}.wpcw-widget-hours .remove-time span.dashicons{line-height:1.4}.wpcw-widget-hours .form div .hidden-container{display:inline-block;width:100%;margin:8px 0;float:left} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:2px 0 0 5px} \ No newline at end of file diff --git a/assets/css/style.css b/assets/css/style.css index de67df0..c59e58c 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -27,7 +27,8 @@ border: none; } .wpcw-widget-social ul li.has-label a, -.wpcw-widget-hours ul li strong { +.wpcw-widget-hours ul li strong.day, +.wpcw-widget-hours ul li time { display: block; } .wpcw-widget-social ul li.has-label span { diff --git a/assets/css/style.min.css b/assets/css/style.min.css index 4acc9c6..36d37ea 100644 --- a/assets/css/style.min.css +++ b/assets/css/style.min.css @@ -1 +1 @@ -.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em}.wpcw-widget-hours ul li span.open-sign{display:inline-block;margin:0 0 3px 5px;padding:2px 5px;border-radius:4px;border:1px solid transparent}.wpcw-widget-hours ul li span.open-sign.open{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}.wpcw-widget-hours ul li span.open-sign.closed{background-color:#f2dede;border-color:#ebccd1;color:#a94442} \ No newline at end of file +.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong.day,.wpcw-widget-hours ul li time,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em}.wpcw-widget-hours ul li span.open-sign{display:inline-block;margin:0 0 3px 5px;padding:2px 5px;border-radius:4px;border:1px solid transparent}.wpcw-widget-hours ul li span.open-sign.open{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}.wpcw-widget-hours ul li span.open-sign.closed{background-color:#f2dede;border-color:#ebccd1;color:#a94442} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index df603f3..3f6ed27 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -161,159 +161,225 @@ }; - $( document ).ready( function ( $ ) { + var dayRow = { - // Social - $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); + toggle: function ( e ) { + + e.preventDefault(); + + var $day = $( this ).closest( '.day-row' ), + $container = $day.find( '.day-row-container' ); + + if ( $container.is( ':animated' ) ) { + + return false; - $( 'body' ).on( 'click', '.wpcw-widget-hours .day-container', function() { + } + + var $icon = $day.find( '.toggle-icon' ), + active = $day.hasClass( 'active' ); - var container = $( this ); + if ( ! active ) { - container.find( 'div.hidden-container' ).slideToggle( 'fast', function() { + $icon + .toggleClass( 'dashicons-arrow-down' ) + .toggleClass( 'dashicons-arrow-up' ); - if ( container.hasClass( 'closed' ) ) { + } - container.removeClass( 'closed' ).addClass( 'open' ); + $container.slideToggle( 'fast', function () { - return; + if ( active ) { + + $icon + .toggleClass( 'dashicons-arrow-down' ) + .toggleClass( 'dashicons-arrow-up' ); } - container.removeClass( 'open' ).addClass( 'closed' ); + $day.toggleClass( 'active' ); } ); - } ); + }, - $( 'body' ).on( 'click', '.add-time', function( e ) { + maybeBlockSelect: function ( e ) { - var $parent_container = $( this ).parents( '.hidden-container' ).find( '.hours-selection' ).last(), - $clone = $parent_container.clone(); + var $day = $( this ).closest( '.day-row' ); - $clone.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { + if ( $day.hasClass( 'status-closed' ) ) { - return name.replace( /\[(\d+)\]$/, function( match, number ) { + e.preventDefault(); - return '[' + ( + number + 1 ) + ']'; + } - } ); + }, - }); + addBlock: function ( e ) { - $clone.find( '.add-time' ).replaceWith( '' ); + e.preventDefault(); - $clone.insertAfter( $parent_container ); + if ( $( this ).hasClass( 'disabled' ) ) { - e.preventDefault(); + return false; - } ); + } - $( 'body' ).on( 'click', '.remove-time', function( e ) { + var $block = $( this ).closest( '.time-block' ), + $clone = dayRow.cloneTimeBlock( $block, $block.parent() ), + $close = $block.find( 'select.time-block-close' ), + $open = $clone.find( 'select.time-block-open' ); - var $button = $( this ), - $parent = $button.parent( '.hours-selection' ); + $clone.find( 'a.button' ).attr( 'data-action', 'remove' ).text( '-' ); - $parent.fadeOut( 'fast', function() { + $( this ).hide(); - $parent.remove(); + }, - } ); + removeBlock: function ( e ) { e.preventDefault(); - } ); + if ( $( this ).hasClass( 'disabled' ) ) { - $( 'body' ).on( 'click', '.js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all', function( e ) { + return false; - e.stopPropagation(); + } - } ); + var $block = $( this ).closest( '.time-block' ); - // Hours of Operation select field toggle - $( 'body' ).on( 'change', '.js_wpcw_closed_checkbox', function( e ) { + $block.prev( '.time-block' ).find( 'a.button' ).show(); - var $select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); + $block.remove(); - if ( $( this ).is( ':checked' ) ) { + }, - $select_fields.prop( 'disabled', true ); + applyToAll: function ( e ) { - return; + e.preventDefault(); - } + var $day = $( this ).closest( '.day-row' ), + $widget = $day.closest( '.wpcw-widget' ), + $animating = $widget.find( '.day-row' ).filter( function() { return $( this ).is( ':animated' ); } ); - $select_fields.prop( 'disabled', false ); + if ( $animating.length > 0 ) { - } ); + return false; - // Apply hours to all days in the week - $( 'body' ).on( 'click', '.js_wpcw_apply_hours_to_all', function( e ) { + } - if ( $( this ).parents( '.day-container' ).find( 'input.js_wpcw_closed_checkbox' ).is( ':checked' ) ) { + if ( $day.hasClass( 'status-closed' ) ) { - $( '.wpcw-widget-hours .day-container' ).find( 'select' ).prop( 'disabled', true ); - $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', true ); - $( '.wpcw-widget-hours .day-container' ).find( '.hours-selection:not(:first)' ).remove(); + $widget.find( '.status-closed-checkbox input:not(:checked)' ).not( this ).trigger( 'click' ); - e.preventDefault(); + } else { - return; + $widget.find( '.status-closed-checkbox input:checked' ).not( this ).trigger( 'click' ); } - var $first_container = $( this ).parents( '.day-container' ), - length = $( this ).parents( '.day-container' ).find( '.hours-selection' ).length; + var $blocks = $day.find( '.time-block' ); - $( '.wpcw-widget-hours .day-container' ).find( 'select' ).prop( 'disabled', false ); - $( '.wpcw-widget-hours .day-checkbox-toggle' ).find( 'input.js_wpcw_closed_checkbox' ).prop( 'checked', false ); + $widget.find( '.day-row' ).not( $day ).each( function( index ) { - $( '.day-container' ).not( $first_container ).each( function() { + var $target = $( this ).find( '.time-blocks' ); - $( this ).find( '.hidden-container .hours-selection:not(:first)' ).remove(); + $target.empty(); - var y = 1, - z = 0; + $blocks.each( function( index ) { - while ( y < length ) { + dayRow.cloneTimeBlock( $( this ), $target, true, true ); - var $duplicate = $( this ).find( '.hidden-container .hours-selection' ).last().clone(); + } ); - $duplicate.find( 'select[name*="[open]"], select[name*="[closed]"]' ).attr( 'name', function( i, name ) { + } ); - return name.replace( /\[(\d+)\]$/, function( match, number ) { + }, - return '[' + ( + number + 1 ) + ']'; + cloneTimeBlock: function ( $block, $target, deep, flashDay ) { - } ); + var $day = $block.closest( '.day-row' ), + day = parseInt( $day.attr( 'data-day' ) ), + target_day = parseInt( $target.closest( '.day-row' ).attr( 'data-day' ) ), + block = parseInt( $block.attr( 'data-time-block' ) ), + target_block = $target.is( ':empty' ) ? 0 : parseInt( $target.find( '.time-block' ).last().attr( 'data-time-block' ) ) + 1, + deep = ( 'undefined' === typeof deep ) ? false : deep, + flashDay = ( 'undefined' === typeof flashDay ) ? false : flashDay, + $clone = $block.clone( deep ), + html = $clone.html(), + name_search = '\\[schedule\\]\\[' + day + '\\]\\[blocks\\]\\[' + block + '\\]', + name_replace = '[schedule][' + target_day + '][blocks][' + target_block + ']', + id_search = 'schedule-' + day + '-blocks-' + block, + id_replace = 'schedule-' + target_day + '-blocks-' + target_block; - } ); + html = html.replace( new RegExp( name_search, 'g' ), name_replace ), + html = html.replace( new RegExp( id_search, 'g' ), id_replace ), - $duplicate.find( '.add-time' ).replaceWith( '' ); + $clone = $clone.html( html ); - $duplicate.insertAfter( $( this ).find( '.hidden-container .hours-selection' ).last() ); + if ( deep ) { - y++; + $clone.find( 'select' ).each( function( index ) { - } + var classes = $( this ) + .attr( 'class' ) + .split( ' ' ) + .map( function ( v ) { + return v.trim(); + } ) + .join( '.' ); + + $( this ).val( $block.find( 'select.' + classes ).val() ); + + } ); - while ( z <= length ) { + } - var open = $first_container.find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val(), - closed = $first_container.find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val(); + $target.append( $clone ); - $( this ).find( '.hours-selection:nth-child(' + z + ') select:first-child' ).val( open ); - $( this ).find( '.hours-selection:nth-child(' + z + ') select:nth-child(2)' ).val( closed ); + $clone.attr( 'data-time-block', target_block ); - z++; + if ( flashDay ) { - } + $clone.closest( '.day-row' ).fadeTo( 50, 0.1, function() { - } ); + $( this ).fadeTo( 500, 1.0 ); - e.preventDefault(); + } ); - } ); + } + + return $clone; + + }, + + toggleClosed: function () { + + var $day = $( this ).closest( '.day-row' ), + closed = $day.hasClass( 'status-closed' ); + + $day.toggleClass( 'status-closed' ).toggleClass( 'status-open' ); + + $day.find( 'a.button' ).toggleClass( 'disabled', ! closed ); + + $day.find( 'select' ).toggleClass( 'disabled', ! closed ); + + } + + }; + + $( document ).ready( function ( $ ) { + + // Social + $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); + + // Hours of Operation + $( document ).on( 'click', '.wpcw-widget-hours .day-row-top', dayRow.toggle ); + $( document ).on( 'mousedown', '.wpcw-widget-hours .time-block select', dayRow.maybeBlockSelect ); + $( document ).on( 'click', '.wpcw-widget-hours .time-block a.button[data-action="add"]', dayRow.addBlock ); + $( document ).on( 'click', '.wpcw-widget-hours .time-block a.button[data-action="remove"]', dayRow.removeBlock ); + $( document ).on( 'click', '.wpcw-widget-hours .apply-to-all', dayRow.applyToAll ); + $( document ).on( 'change', '.wpcw-widget-hours .status-closed-checkbox input', dayRow.toggleClosed ); // Sortable $( document ).on( 'wpcw.change', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 542ab8e..c641926 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a("body").on("click",".wpcw-widget-hours .day-container",function(){var b=a(this);b.find("div.hidden-container").slideToggle("fast",function(){return b.hasClass("closed")?void b.removeClass("closed").addClass("open"):void b.removeClass("open").addClass("closed")})}),a("body").on("click",".add-time",function(b){var c=a(this).parents(".hidden-container").find(".hours-selection").last(),d=c.clone();d.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),d.find(".add-time").replaceWith(''),d.insertAfter(c),b.preventDefault()}),a("body").on("click",".remove-time",function(b){var c=a(this),d=c.parent(".hours-selection");d.fadeOut("fast",function(){d.remove()}),b.preventDefault()}),a("body").on("click",".js_wpcw_closed_checkbox, .wpcw-widget-hours select, .add-time, .remove-time, .js_wpcw_apply_hours_to_all",function(a){a.stopPropagation()}),a("body").on("change",".js_wpcw_closed_checkbox",function(b){var c=a(b.currentTarget).parents(".day-container").find("select");return a(this).is(":checked")?void c.prop("disabled",!0):void c.prop("disabled",!1)}),a("body").on("click",".js_wpcw_apply_hours_to_all",function(b){if(a(this).parents(".day-container").find("input.js_wpcw_closed_checkbox").is(":checked"))return a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!0),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!0),a(".wpcw-widget-hours .day-container").find(".hours-selection:not(:first)").remove(),void b.preventDefault();var c=a(this).parents(".day-container"),d=a(this).parents(".day-container").find(".hours-selection").length;a(".wpcw-widget-hours .day-container").find("select").prop("disabled",!1),a(".wpcw-widget-hours .day-checkbox-toggle").find("input.js_wpcw_closed_checkbox").prop("checked",!1),a(".day-container").not(c).each(function(){a(this).find(".hidden-container .hours-selection:not(:first)").remove();for(var b=1,e=0;d>b;){var f=a(this).find(".hidden-container .hours-selection").last().clone();f.find('select[name*="[open]"], select[name*="[closed]"]').attr("name",function(a,b){return b.replace(/\[(\d+)\]$/,function(a,b){return"["+(+b+1)+"]"})}),f.find(".add-time").replaceWith(''),f.insertAfter(a(this).find(".hidden-container .hours-selection").last()),b++}for(;d>=e;){var g=c.find(".hours-selection:nth-child("+e+") select:first-child").val(),h=c.find(".hours-selection:nth-child("+e+") select:nth-child(2)").val();a(this).find(".hours-selection:nth-child("+e+") select:first-child").val(g),a(this).find(".hours-selection:nth-child("+e+") select:nth-child(2)").val(h),e++}}),b.preventDefault()}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());c.find("select.time-block-close"),e.find("select.time-block-open");e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(b){var c=a(this).find(".time-blocks");c.empty(),g.each(function(b){d.cloneTimeBlock(a(this),c,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day")),h=parseInt(c.closest(".day-row").attr("data-day")),i=parseInt(b.attr("data-time-block")),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"))+1,d="undefined"==typeof d?!1:d,e="undefined"==typeof e?!1:e,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(c){var d=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+d).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 241cfee..159855e 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -31,10 +31,11 @@ abstract class Base_Widget extends \WP_Widget { 'default' => '', // Used mainly for social fields to add default value 'value' => '', 'placeholder' => '', + 'wrapper' => 'p', 'sortable' => true, 'atts' => '', // Input attributes 'show_front_end' => true, // Are we showing this field on the front end? - 'show_empty' => false, // Show the field even if value is empty + 'hide_empty' => true, // Hide the field if its value is empty 'select_options' => [], // Only used if type=select & form_callback=render_form_select ]; @@ -101,36 +102,36 @@ public function update( $new_instance, $old_instance ) { $fields = $this->get_fields( $old_instance ); - // Force value for checkbox since they are not posted foreach ( $fields as $key => $field ) { - if ( 'checkbox' === $field['type'] && ! isset( $new_instance[ $key ]['value'] ) ) { + $order = array_search( $key, array_keys( $new_instance ) ); + $is_sortable = ( 'title' !== $key && ! empty( $field['sortable'] ) && $order > 0 ); // Start at 1 since title order is 0 + $field_key = ( $is_sortable ) ? $key . '[value]' : $key; - $new_instance[ $key ] = [ 'value' => 'no' ]; + $sanitizer_callback = $field['sanitizer']; - } + $new_value = $this->get_field_value( $new_instance, $field_key, null, false ); + $old_value = $this->get_field_value( $old_instance, $field_key, null, false ); - } + if ( $new_value !== $old_value ) { - // Starting at 1 since title order is 0 - $order = 1; + $this->set_field_value( $new_instance, $field_key, is_null( $new_value ) ? $new_value : $sanitizer_callback( $new_value ) ); - foreach ( $new_instance as $key => &$instance ) { + } - $sanitizer_callback = $fields[ $key ]['sanitizer']; + // Force default values when empty + if ( null === $new_value && $field['default'] ) { - // Title can't be an array - if ( 'title' === $key ) { + $this->set_field_value( $new_instance, $field_key, $field['default'] ); + + } - $instance = $sanitizer_callback( $instance['value'] ); + if ( $is_sortable ) { - continue; + $this->set_field_value( $new_instance, $key . '[order]', $order ); } - $instance['value'] = $sanitizer_callback( $instance['value'] ); - $instance['order'] = $order++; - } return $new_instance; @@ -152,17 +153,25 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t foreach ( $fields as $key => &$field ) { - $common_properties = [ - 'key' => $key, - 'icon' => $key, - 'order' => ! empty( $instance[ $key ]['order'] ) ? absint( $instance[ $key ]['order'] ) : $order, - 'id' => $this->get_field_id( $key ), - 'name' => $this->get_field_name( $key ) . '[value]', - 'value' => ! empty( $instance[ $key ]['value'] ) ? $instance[ $key ]['value'] : '', - ]; + // Fill in missing properties with defaults + $field = wp_parse_args( $field, $this->field_defaults ); + + // Title is never sortable and is always at the top + if ( 'title' === $key ) { - $common_properties = wp_parse_args( $common_properties, $this->field_defaults ); - $field = wp_parse_args( $field, $common_properties ); + $field['sortable'] = false; + + } + + // Save sortable field values as an array alongside an order value + $field_key = ! empty( $field['sortable'] ) ? $key . '[value]' : $key; + + // Required properties (cannot be empty) + $field['key'] = ! empty( $field['key'] ) ? $field['key'] : $key; + $field['id'] = ! empty( $field['id'] ) ? $field['id'] : $this->get_field_id( $key ); + $field['name'] = ! empty( $field['name'] ) ? $field['name'] : $this->get_field_name( $field_key ); + $field['value'] = ! empty( $field['value'] ) ? $field['value'] : $this->get_field_value( $instance, $field_key ); + $field['order'] = ! empty( $field['order'] ) ? $field['order'] : $this->get_field_value( $instance, $key . '[order]', $order ); $default_closure = function( $value ) { return $value; }; @@ -186,6 +195,73 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t } + /** + * Return a field value from inside an instance + * + * @param array $instance + * @param string $key + * @param mixed $default (optional) + * @param bool $strict (optional) + * + * @return mixed + */ + protected function get_field_value( array $instance, $key, $default = '', $strict = true ) { + + $keys = explode( '[', str_replace( ']', '', $key ) ); + $last = array_pop( $keys ); + + foreach ( $keys as $index ) { + + if ( ! array_key_exists( $index, $instance ) ) { + + return $default; + + } + + $instance = $instance[ $index ]; + + } + + if ( ! $strict ) { + + return isset( $instance[ $last ] ) ? $instance[ $last ] : $default; + + } + + return ! empty( $instance[ $last ] ) ? $instance[ $last ] : $default; + + } + + /** + * Set a field value inside an instance + * + * @param array &$instance + * @param string $key + * @param mixed $value + */ + protected function set_field_value( array &$instance, $key, $value ) { + + $keys = explode( '[', str_replace( ']', '', $key ) ); + $last = array_pop( $keys ); + + foreach ( $keys as $index ) { + + $index = is_numeric( $index ) ? (int) $index : $index; + + if ( ! array_key_exists( $index, $instance ) ) { + + $instance[ $index ] = []; + + } + + $instance = &$instance[ $index ]; + + } + + $instance[ $last ] = $value; + + } + /** * Order array by field order * @@ -286,10 +362,15 @@ protected function before_form_field( array $field ) { } - printf( - '

    ', - implode( ' ', $classes ) - ); + if ( $field['wrapper'] ) { + + printf( + '<%s class="%s">', + esc_attr( $field['wrapper'] ), + implode( ' ', $classes ) + ); + + } if ( ! $field['label_after'] ) { @@ -345,10 +426,11 @@ protected function render_form_select( array $field ) { $this->before_form_field( $field ); printf( - '', esc_attr( $field['class'] ), esc_attr( $field['id'] ), - esc_attr( $field['name'] ) + esc_attr( $field['name'] ), + esc_attr( $field['atts'] ) ); foreach ( $field['select_options'] as $value => $name ) { @@ -396,172 +478,10 @@ protected function render_form_textarea( array $field ) { } - /** - * Render the hours container and select fields - * - * @param array $field Field data. - * @param array $day The current day in the iteration. - * @param array $hours The array of times. - * - * @since NEXT - * - * @return mixed - */ - protected function render_day_input( $field, $day, array $hours ) { - - $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); - $field['disabled'] = $hours['not_open'] ? true : false; - - $open_label = $hours['not_open'] ? __( 'CLOSED', 'contact-widgets' ) : __( 'OPEN', 'contact-widgets' ); - $open_class = $hours['not_open'] ? 'closed' : 'open'; - - $apply_to_all_toggle = key( $field['days'] ) === $day ? '' . __( 'Apply to All', 'contact-widgets' ) . '' : ''; - - $closed_checkbox = 'checked( $hours['not_open'], true ) . '>'; - - printf( - '

    %1$s
    %2$s %3$s
    ', - '' . esc_html( ucwords( $day ) ) . '' . $open_label . '', - $this->render_hours_selection( $field, sanitize_title( $day ), $hours ), - '' . $apply_to_all_toggle . $closed_checkbox . '' - ); - - } - - /** - * Render the 'Hours' select fields - * - * @param array $field Field data - * @param array $day The current day in the iteration. - * @param array $hours The array of times. - * - * @since NEXT - * - * @return mixed - */ - protected function render_hours_selection( $field, $day, $hours ) { - - ob_start(); - - $times = $this->get_time_array(); - - $field['name'] = str_replace( 'value', strtolower( $day ), $field['name'] ); - - $disabled_field = $field['disabled'] ? ' disabled="disabled"' : ''; - - $x = 1; - - while ( $x <= count( $field['days'][ $day ]['open'] ) ) { - - ?> - -
    - - - - - - - - '; ?> - - - -
    - - '; + if ( $field['wrapper'] ) { + + printf( '', esc_attr( $field['wrapper'] ) ); + + } } @@ -584,6 +508,7 @@ protected function after_form_field( array $field ) { protected function before_widget( array $args, array &$fields ) { $title = array_shift( $fields ); + echo $args['before_widget']; if ( ! empty( $title['value'] ) ) { diff --git a/includes/class-contact.php b/includes/class-contact.php index 5dac8ab..7c8f932 100644 --- a/includes/class-contact.php +++ b/includes/class-contact.php @@ -82,7 +82,7 @@ public function form( $instance ) { */ public function widget( $args, $instance ) { - $fields = $this->get_fields( $instance ); + $fields = $this->get_fields( $instance, [], true ); if ( $this->is_widget_empty( $fields ) ) { @@ -143,8 +143,6 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'title' => [ 'label' => __( 'Title:', 'contact-widgets' ), 'description' => __( 'The title of widget. Leave empty for no title.', 'contact-widgets' ), - 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', - 'sortable' => false, ], 'email' => [ 'label' => __( 'Email:', 'contact-widgets' ), @@ -180,8 +178,9 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'label_after' => true, 'type' => 'checkbox', 'sortable' => false, + 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', isset( $instance['labels']['value'] ) ? $instance['labels']['value'] : 'yes' ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels', 'yes' ) ), 'show_front_end' => false, ], 'map' => [ @@ -190,14 +189,15 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'label_after' => true, 'type' => 'checkbox', 'sortable' => false, + 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', isset( $instance['map']['value'] ) ? $instance['map']['value'] : 'yes' ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'map', 'yes' ) ), 'show_front_end' => false, ], ]; $fields = apply_filters( 'wpcw_widget_contact_custom_fields', $fields, $instance ); - $fields = parent::get_fields( $instance, $fields ); + $fields = parent::get_fields( $instance, $fields, $ordered ); /** * Filter the contact fields diff --git a/includes/class-hours.php b/includes/class-hours.php index fa4bc86..e7f5ece 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -10,9 +10,23 @@ final class Hours extends Base_Widget { - private $current_day; + /** + * Array of days in a week. + * + * @since NEXT + * + * @var array + */ + public $days_of_week = []; - private $current_time; + /** + * Maximum number of time blocks to allow per day. + * + * @since NEXT + * + * @var int + */ + private $max_time_blocks = 2; /** * Widget constructor @@ -31,8 +45,25 @@ public function __construct() { $widget_options ); - $this->current_time = current_time( 'timestamp' ); - $this->current_day = strtolower( date( 'l', $this->current_time ) ); + $this->days_of_week = [ + 0 => __( 'Sunday', 'contact-widgets' ), + 1 => __( 'Monday', 'contact-widgets' ), + 2 => __( 'Tuesday', 'contact-widgets' ), + 3 => __( 'Wednesday', 'contact-widgets' ), + 4 => __( 'Thursday', 'contact-widgets' ), + 5 => __( 'Friday', 'contact-widgets' ), + 6 => __( 'Saturday', 'contact-widgets' ), + ]; + + /** + * Filter the maximum number of time blocks to allow per day. + * + * @since NEXT + * + * @var int + */ + $this->max_time_blocks = (int) apply_filters( 'wpcw_widget_hours_max_time_blocks', $this->max_time_blocks ); + $this->max_time_blocks = ( $this->max_time_blocks > 0 ) ? $this->max_time_blocks : 1; // Must be greater than 0 } @@ -62,23 +93,29 @@ public function form( $instance ) { foreach ( $fields as $key => $field ) { - if ( 'days' === $key ) { + $method = $field['form_callback']; - foreach ( $field['days'] as $day => $hours ) { + if ( + ! is_callable( [ $this, $method ] ) + || + ( empty( $field['value'] ) && $field['hide_empty'] ) + ) { - $this->render_day_input( $fields['days'], $day, $hours ); + continue; - } + } - continue; + if ( ! empty( $field['prepend'] ) ) { + + echo $field['prepend']; // xss ok } - $method = $field['form_callback']; + $this->$method( $field ); - if ( is_callable( [ $this, $method ] ) ) { + if ( ! empty( $field['append'] ) ) { - $this->$method( $field ); + echo $field['append']; // xss ok } @@ -87,87 +124,165 @@ public function form( $instance ) { // Workaround customizer refresh @props @westonruter echo ''; - echo '
    '; // End form + echo '
    '; - echo '
    '; // End wpcw-widget-hours + echo ''; } /** - * Front-end display + * Override update method to unset empty time blocks. * - * @param array $args - * @param array $instance + * @since NEXT + * + * @param array $new_instance + * @param array $old_instance + * + * @return array */ - public function widget( $args, $instance ) { + public function update( $new_instance, $old_instance ) { - $fields = $this->get_fields( $instance ); + $new_instance = parent::update( $new_instance, $old_instance ); - $this->before_widget( $args, $fields ); + if ( 1 === $this->max_time_blocks ) { - foreach ( $fields as $field ) { + return $new_instance; - if ( isset( $field['days'] ) ) { + } - foreach ( $field['days'] as $day_of_week => $store_hours ) { + foreach ( $this->get_days_of_week() as $day => $label ) { - do_action( 'wpcw_widget_hours_before_day', $day_of_week ); + foreach ( range( 1, $this->max_time_blocks ) as $block ) { - if ( $store_hours['not_open'] ) { + if ( + empty( $new_instance['schedule'][ $day ]['blocks'][ $block ]['open'] ) + && + empty( $new_instance['schedule'][ $day ]['blocks'][ $block ]['close'] ) + ) { - printf( - '
  • %1$s %2$s
  • ', - '' . esc_html( ucwords( $day_of_week ) ) . $this->open_sign( $day_of_week, $store_hours ) . '', - '
    ' . __( 'Closed', 'contact-widgets' ) . '
    ' - ); + unset( $new_instance['schedule'][ $day ]['blocks'][ $block ] ); - continue; + } - } + } - $hour_length = count( $store_hours['open'] ); + } - $x = 1; + return $new_instance; - $microformat_data = [ - 'day' => $day_of_week, - 'open' => $store_hours['open'], - 'close' => $store_hours['closed'], - ]; + } - $hours = []; + /** + * Front-end display + * + * @param array $args + * @param array $instance + */ + public function widget( $args, $instance ) { - while ( $x <= $hour_length ) { + $fields = $this->get_fields( $instance, [], false ); - $hours[] = '
    '; + if ( $this->is_widget_empty( $fields ) ) { - $x++; + return; - } + } - printf( - '
  • %1$s %2$s
  • ', - '' . esc_html( ucwords( $day_of_week ) ) . $this->open_sign( $day_of_week, $store_hours ) . '', - '
    ' . implode( '', $hours ) . '
    ' - ); + $this->before_widget( $args, $fields ); - do_action( 'wpcw_widget_hours_after_day', $day_of_week ); + $display_current_status = (bool) ( 'yes' === $this->get_field_value( $instance, 'display_current_status', 'yes' ) ); + $hide_closed = (bool) ( 'yes' === $this->get_field_value( $instance, 'hide_closed', 'yes' ) ); + $display_in_groups = (bool) ( 'yes' === $this->get_field_value( $instance, 'display_in_groups', 'yes' ) ); - } + if ( $display_current_status ) { + + /** + * TODO: Handle this with JavaScript so it works with full-page caching. + * + * 1. Expose this site's timezone and daily schedule as JSON. + * 2. Use JavaScript to compare the visitor's current time against our schedule. + * 3. Populate this element dynamically with JavaScript. + */ + echo '
  • '; + + } + + /** + * TODO: Combine days that have identical hours when the + * `$display_in_groups` option is ON. + * + * And it should also group closed days if the `$hide_closed` + * option is OFF. + * + * e.g. + * + * Monday - Friday + * 9:00 am - 5:00 pm + * + * Saturday + * 9:00 am - 12:00 pm + * + * Sunday + * Closed + */ + foreach ( $this->get_days_of_week() as $day => $label ) { + + $is_closed = (bool) ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]", 'no' ) ); + + if ( $hide_closed && $is_closed ) { continue; } - if ( ! $field['show_front_end'] ) { + $time_blocks = $this->get_field_value( $instance, "schedule[{$day}][blocks]", [] ); + $time_blocks = array_combine( + wp_list_pluck( $time_blocks, 'open' ), + wp_list_pluck( $time_blocks, 'close' ) + ); + + echo '
  • '; + + printf( '%s', esc_html( $label ) ); + + if ( $is_closed ) { + + printf( '%s', __( 'Closed', 'contact-widgets' ) ); continue; } - $escape_callback = $field['escaper']; + printf( + '', + substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), + implode( ', ', array_map( + function ( $close, $open ) { + return sprintf( '%s-%s', $open, $close ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) ), + implode( '
    ', array_map( + function ( $close, $open ) { + return sprintf( + '%s – %s', + date( (string) get_option( 'time_format' ), strtotime( $open ) ), + date( (string) get_option( 'time_format' ), strtotime( $close ) ) + ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) ) + ); + + echo '
  • '; + + } + + if ( $info = $this->get_field_value( $instance, 'info' ) ) { - echo apply_filters( 'the_content', $escape_callback( $field['value'] ) ); + printf( '
  • %s
  • ', wpautop( $info ) ); // xss ok } @@ -184,54 +299,143 @@ public function widget( $args, $instance ) { * * @return array */ - protected function get_fields( array $instance, array $fields = [], $ordered = true ) { - - $fields = [ - 'title' => [ - 'label' => __( 'Title:', 'contact-widgets' ), - 'description' => __( 'The title of this widget. Leave empty for no title.', 'contact-widgets' ), - 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', - 'sortable' => false, - ], - 'days' => [], - 'additional_content' => [ - 'label' => __( 'Additional Info.', 'contact-widgets' ), - 'type' => 'textarea', - 'sanitizer' => function( $value ) { return current_user_can( 'unfiltered_html' ) ? $value : wp_kses_post( stripslashes( $value ) ); }, - 'escaper' => function( $value ) { return nl2br( apply_filters( 'widget_text', $value ) ); }, - 'form_callback' => 'render_form_textarea', - 'description' => __( 'Enter additional information about your business.', 'contact-widgets' ), - ], - 'day_order' => [ - 'label' => __( 'Keep the current day at the top of the widget.', 'contact-widgets' ), - 'type' => 'checkbox', - 'label_after' => true, - 'show_front_end' => false, - 'default' => 'no', - 'value' => 1, - ], + protected function get_fields( array $instance, array $fields = [], $ordered = false ) { + + $fields['title'] = [ + 'label' => __( 'Title:', 'contact-widgets' ), + 'description' => __( 'The title of this widget. Leave empty for no title.', 'contact-widgets' ), ]; - if ( 'no' !== $instance['day_order']['value'] ) { + foreach ( $this->get_days_of_week() as $day => $label ) { - $fields['day_order']['atts'] = 'checked="checked"'; + $is_closed = ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]" ) ); + $blocks = range( 0, $this->max_time_blocks - 1 ); - } + foreach ( $blocks as $block ) { + + $next_block = $block + 1; + $is_last_block = empty( $this->get_field_value( $instance, "schedule[{$day}][blocks][{$next_block}][open]" ) ); + + $fields["schedule[{$day}][blocks][{$block}][open]"] = [ + 'type' => 'select', + 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, + 'form_callback' => 'render_form_select', + 'select_options' => $this->get_times(), + 'prepend' => sprintf( '
    ', $block ), + 'hide_empty' => ( $block > 0 ), + 'default' => ( 0 === $block ) ? '00:00' : '', + 'class' => ( $is_closed ) ? 'widefat time-block-open disabled' : 'widefat time-block-open', + 'sortable' => false, + 'wrapper' => '', + ]; - foreach ( $this->get_days_of_week( $instance['day_order']['value'] ) as $day ) { + if ( 0 === $block ) { - $day = strtolower( $day ); + ob_start(); - $fields['days']['days'][ $day ] = [ - 'open' => ! empty( $instance['days'][ $day ]['open'] ) ? $instance['days'][ $day ]['open'] : '', - 'closed' => ! empty( $instance['days'][ $day ]['closed'] ) ? $instance['days'][ $day ]['closed'] : '', - 'not_open' => ! empty( $instance['days'][ $day ]['not_open'] ) ? true : false, + ?> +
    +
    + + + + +
    +
    +
    +
    + 'select', + 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, + 'form_callback' => 'render_form_select', + 'select_options' => $this->get_times(), + 'hide_empty' => ( $block > 0 ), + 'default' => ( 0 === $block ) ? '00:00' : '', + 'class' => ( $is_closed ) ? 'widefat time-block-open disabled' : 'widefat time-block-open', + 'sortable' => false, + 'wrapper' => '', + 'append' => sprintf( + '%s
    ', + ( $is_closed ) ? 'disabled' : '', + ( $block > 0 ) ? 'remove' : 'add', + ( ! $is_last_block ) ? 'style="display: none;"' : '', + ( $block > 0 ) ? '-' : '+' + ), + ]; + + } + + $fields["schedule[{$day}][closed]"] = [ + 'type' => 'checkbox', + 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, + 'class' => 'status-closed-checkbox', + 'label' => __( 'Closed', 'contact-widgets' ), + 'default' => 'no', + 'value' => 'yes', + 'atts' => $this->checked( $is_closed, true ), + 'sortable' => false, + 'wrapper' => '', + 'prepend' => sprintf( + '
    %s', + __( 'Apply to all', 'contact-widgets' ) + ), + 'append' => '
    ', ]; } + $fields['display_current_status'] = [ + 'type' => 'checkbox', + 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, + 'label' => __( 'Display current status?', 'contact-widgets' ), + 'label_after' => true, + 'default' => 'no', + 'value' => 'yes', + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'display_current_status', 'yes' ) ), + 'sortable' => false, + ]; + + $fields['hide_closed'] = [ + 'type' => 'checkbox', + 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, + 'label' => __( 'Hide days marked as closed?', 'contact-widgets' ), + 'label_after' => true, + 'default' => 'no', + 'value' => 'yes', + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'hide_closed', 'yes' ) ), + 'sortable' => false, + ]; + + $fields['display_in_groups'] = [ + 'type' => 'checkbox', + 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, + 'label' => __( 'Group days with the same hours?', 'contact-widgets' ), + 'label_after' => true, + 'default' => 'no', + 'value' => 'yes', + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'display_in_groups', 'yes' ) ), + 'sortable' => false, + ]; + + $fields['info'] = [ + 'label' => __( 'More Information:', 'contact-widgets' ), + 'type' => 'textarea', + 'sanitizer' => function( $value ) { return current_user_can( 'unfiltered_html' ) ? (string) $value : wp_kses_post( stripslashes( (string) $value ) ); }, + 'escaper' => function( $value ) { return nl2br( apply_filters( 'widget_text', (string) $value ) ); }, + 'form_callback' => 'render_form_textarea', + 'description' => __( 'Display more information about your hours of operation.', 'contact-widgets' ), + 'sortable' => false, + 'hide_empty' => false, + ]; + $fields = apply_filters( 'wpcw_widget_hours_custom_fields', $fields, $instance ); - $fields = parent::get_fields( $instance, $fields ); + $fields = parent::get_fields( $instance, $fields, $ordered ); /** * Filter the contact fields @@ -245,39 +449,56 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t } /** - * Return an array of days of the week + * Return an array of days relative to the site's `start_of_week` setting. * * @since NEXT * * @return array */ - public function get_days_of_week( $current_day ) { - - $days_of_the_week = [ - __( 'Monday', 'contact-widgets' ), - __( 'Tuesday', 'contact-widgets' ), - __( 'Wednesday', 'contact-widgets' ), - __( 'Thursday', 'contact-widgets' ), - __( 'Friday', 'contact-widgets' ), - __( 'Saturday', 'contact-widgets' ), - __( 'Sunday', 'contact-widgets' ), - ]; + public function get_days_of_week() { - $start_of_week = get_option( 'start_of_week', 1 ); + $start_of_week = (int) get_option( 'start_of_week', 1 ); - if ( 'no' !== $current_day && ! is_admin() ) { + $slice_1 = array_slice( $this->days_of_week, $start_of_week, null, true ); + $slice_2 = array_slice( $this->days_of_week, 0, count( $this->days_of_week ) - count( $slice_1 ), true ); - $start_of_week = array_search( date( 'l', $this->current_time ), $days_of_the_week ) + 1; + return $slice_1 + $slice_2; // Preserve keys - } + } + + /** + * Return an array of times in half-hour increments + * + * @since NEXT + * + * @return array + */ + protected function get_times() { - if ( 1 < $start_of_week ) { + /** + * Filter the time increment (in minutes) + * + * @since NEXT + * + * @return int + */ + $increment = (int) apply_filters( 'wpcw_hours_time_increment', HOUR_IN_SECONDS / 60 / 2 ); - return array_merge( array_splice( $days_of_the_week, ( $start_of_week - 1 ) ), $days_of_the_week ); + $times = range( 0, DAY_IN_SECONDS / 60, $increment ); - } + $keys = array_map( function ( $time ) { + + return date( 'H:i', $time * 60 ); + + }, $times ); + + $values = array_map( function ( $time ) { - return (array) $days_of_the_week; + return date( (string) get_option( 'time_format' ), $time * 60 ); + + }, $times ); + + return array_combine( $keys, $values ); } @@ -306,44 +527,6 @@ protected function get_microformat_markup( $microformat_data, $iteration ) { } - /** - * Generate the open sign on the front-end - * - * @param string $day The current day in the iteration. - * @param array $hours Open/Closed hours. - * - * @since NEXT - * - * - * @return mixed - */ - protected function open_sign( $day, $hours ) { - - /** - * Allow users to disable the open sign - * - * @since NEXT - * - * @return string - */ - if ( (bool) ! apply_filters( 'wpcw_widget_hours_open_sign', true ) || $this->current_day !== $day ) { - - return; - - } - - $business_open = $this->is_business_open( $hours ); - $open_sign_text = $business_open ? __( 'Open', 'contact-widgets' ) : __( 'Closed', 'contact-widgets' ); - $open_sign_class = $business_open ? 'open' : 'closed'; - - return sprintf( - '%2$s', - esc_attr( $open_sign_class ), - apply_filters( 'wpcw_widget_hours_open_sign_text', $open_sign_text, $business_open ) - ); - - } - /** * Check if the business is open based on the current server time * diff --git a/includes/class-social.php b/includes/class-social.php index a449145..c907c26 100644 --- a/includes/class-social.php +++ b/includes/class-social.php @@ -100,7 +100,7 @@ class="%s" if ( is_callable( [ $this, $method ] ) && - ( ! empty( $field['value'] ) || $field['show_empty'] ) + ( ! empty( $field['value'] ) && ! $field['hide_empty'] ) ) { $this->$method( $field ); @@ -201,6 +201,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f foreach ( $fields as $key => &$field ) { $default = [ + 'icon' => $key, 'sanitizer' => 'esc_url_raw', 'escaper' => 'esc_url', 'select' => '', @@ -216,8 +217,6 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'title' => [ 'label' => __( 'Title:', 'contact-widgets' ), 'description' => __( 'The title of widget. Leave empty for no title.', 'contact-widgets' ), - 'value' => ! empty( $instance['title'] ) ? $instance['title'] : '', - 'sortable' => false, ], ]; @@ -230,8 +229,9 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'label_after' => true, 'type' => 'checkbox', 'sortable' => false, + 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', isset( $instance['labels']['value'] ) ? $instance['labels']['value'] : 'no' ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels', 'no' ) ), 'show_front_end' => false, ]; From f9f8f6b09b2a41f8437a6d5e5975519ca3462c7c Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 27 Dec 2016 19:28:29 -0600 Subject: [PATCH 46/90] Back compat for other widgets --- includes/class-base-widget.php | 6 +++--- includes/class-contact.php | 13 ++++++++----- includes/class-hours.php | 8 ++++---- includes/class-social.php | 8 ++++---- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 159855e..157e983 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -157,14 +157,14 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t $field = wp_parse_args( $field, $this->field_defaults ); // Title is never sortable and is always at the top - if ( 'title' === $key ) { + if ( $ordered && 'title' === $key ) { $field['sortable'] = false; } - // Save sortable field values as an array alongside an order value - $field_key = ! empty( $field['sortable'] ) ? $key . '[value]' : $key; + // Save values as an array alongside an order value, except titles + $field_key = ( $ordered && 'title' !== $key ) ? $key . '[value]' : $key; // Required properties (cannot be empty) $field['key'] = ! empty( $field['key'] ) ? $field['key'] : $key; diff --git a/includes/class-contact.php b/includes/class-contact.php index 7c8f932..ddfa578 100644 --- a/includes/class-contact.php +++ b/includes/class-contact.php @@ -92,7 +92,8 @@ public function widget( $args, $instance ) { $this->before_widget( $args, $fields ); - $display_labels = ( 'yes' === $instance['labels']['value'] ); + $display_labels = ( 'yes' === $this->get_field_value( $instance, 'labels[value]', 'yes' ) ); + $display_map = ( 'yes' === $this->get_field_value( $instance, 'map[value]', 'yes' ) ); foreach ( $fields as $field ) { @@ -114,11 +115,13 @@ public function widget( $args, $instance ) { } - if ( 'yes' === $instance['map']['value'] && ! empty( $fields['address']['value'] ) ) { + $address = $this->get_field_value( $instance, 'address[value]' ); + + if ( $display_map && ! empty( $address ) ) { printf( '
  • ', - urlencode( trim( strip_tags( $fields['address']['value'] ) ) ), + urlencode( trim( strip_tags( $address ) ) ), urlencode( $this->get_google_maps_locale() ) ); @@ -180,7 +183,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'sortable' => false, 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels', 'yes' ) ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels[value]', 'yes' ) ), 'show_front_end' => false, ], 'map' => [ @@ -191,7 +194,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t 'sortable' => false, 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'map', 'yes' ) ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'map[value]', 'yes' ) ), 'show_front_end' => false, ], ]; diff --git a/includes/class-hours.php b/includes/class-hours.php index e7f5ece..e5341b6 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -190,9 +190,9 @@ public function widget( $args, $instance ) { $this->before_widget( $args, $fields ); - $display_current_status = (bool) ( 'yes' === $this->get_field_value( $instance, 'display_current_status', 'yes' ) ); - $hide_closed = (bool) ( 'yes' === $this->get_field_value( $instance, 'hide_closed', 'yes' ) ); - $display_in_groups = (bool) ( 'yes' === $this->get_field_value( $instance, 'display_in_groups', 'yes' ) ); + $display_current_status = ( 'yes' === $this->get_field_value( $instance, 'display_current_status', 'yes' ) ); + $hide_closed = ( 'yes' === $this->get_field_value( $instance, 'hide_closed', 'yes' ) ); + $display_in_groups = ( 'yes' === $this->get_field_value( $instance, 'display_in_groups', 'yes' ) ); if ( $display_current_status ) { @@ -227,7 +227,7 @@ public function widget( $args, $instance ) { */ foreach ( $this->get_days_of_week() as $day => $label ) { - $is_closed = (bool) ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]", 'no' ) ); + $is_closed = ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]", 'no' ) ); if ( $hide_closed && $is_closed ) { diff --git a/includes/class-social.php b/includes/class-social.php index c907c26..36181cd 100644 --- a/includes/class-social.php +++ b/includes/class-social.php @@ -100,7 +100,7 @@ class="%s" if ( is_callable( [ $this, $method ] ) && - ( ! empty( $field['value'] ) && ! $field['hide_empty'] ) + ( ! empty( $field['value'] ) || ! $field['hide_empty'] ) ) { $this->$method( $field ); @@ -143,7 +143,7 @@ public function widget( $args, $instance ) { $this->before_widget( $args, $fields ); - $display_labels = ( 'yes' === $instance['labels']['value'] ); + $display_labels = ( 'yes' === $this->get_field_value( $instance, 'labels[value]', 'no' ) ); foreach ( $fields as $field ) { @@ -194,7 +194,7 @@ public function front_end_enqueue_scripts() { * * @return array */ - protected function get_fields( array $instance, array $fields = [], $ordered = false ) { + protected function get_fields( array $instance, array $fields = [], $ordered = true ) { include 'social-networks.php'; @@ -231,7 +231,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'sortable' => false, 'default' => 'no', 'value' => 'yes', - 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels', 'no' ) ), + 'atts' => $this->checked( 'yes', $this->get_field_value( $instance, 'labels[value]', 'no' ) ), 'show_front_end' => false, ]; From 74f5b751a0076772a9af1f5647e83826857366c9 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:12:56 -0600 Subject: [PATCH 47/90] Fix social icon sorting and order saving --- includes/class-base-widget.php | 15 +++++++++------ includes/class-contact.php | 2 +- includes/class-hours.php | 2 +- includes/class-social.php | 29 +++++++++++++++++------------ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 157e983..922dc26 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -28,7 +28,8 @@ abstract class Base_Widget extends \WP_Widget { 'sanitizer' => 'sanitize_text_field', 'escaper' => 'esc_html', 'form_callback' => 'render_form_input', - 'default' => '', // Used mainly for social fields to add default value + 'default' => '', + 'save_default' => true, 'value' => '', 'placeholder' => '', 'wrapper' => 'p', @@ -102,11 +103,13 @@ public function update( $new_instance, $old_instance ) { $fields = $this->get_fields( $old_instance ); + $has_sortables = array_filter( wp_list_pluck( $fields, 'sortable' ) ); + foreach ( $fields as $key => $field ) { - $order = array_search( $key, array_keys( $new_instance ) ); - $is_sortable = ( 'title' !== $key && ! empty( $field['sortable'] ) && $order > 0 ); // Start at 1 since title order is 0 - $field_key = ( $is_sortable ) ? $key . '[value]' : $key; + $order = array_search( $key, array_keys( $new_instance ) ); + $ordered = ( $has_sortables && 'title' !== $key && $order > 0 ); // Start at 1 since title order is 0 + $field_key = ( $ordered ) ? $key . '[value]' : $key; $sanitizer_callback = $field['sanitizer']; @@ -120,13 +123,13 @@ public function update( $new_instance, $old_instance ) { } // Force default values when empty - if ( null === $new_value && $field['default'] ) { + if ( null === $new_value && $field['save_default'] && $field['default'] ) { $this->set_field_value( $new_instance, $field_key, $field['default'] ); } - if ( $is_sortable ) { + if ( $ordered ) { $this->set_field_value( $new_instance, $key . '[order]', $order ); diff --git a/includes/class-contact.php b/includes/class-contact.php index ddfa578..803e1fa 100644 --- a/includes/class-contact.php +++ b/includes/class-contact.php @@ -82,7 +82,7 @@ public function form( $instance ) { */ public function widget( $args, $instance ) { - $fields = $this->get_fields( $instance, [], true ); + $fields = $this->get_fields( $instance ); if ( $this->is_widget_empty( $fields ) ) { diff --git a/includes/class-hours.php b/includes/class-hours.php index e5341b6..41a35d2 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -180,7 +180,7 @@ public function update( $new_instance, $old_instance ) { */ public function widget( $args, $instance ) { - $fields = $this->get_fields( $instance, [], false ); + $fields = $this->get_fields( $instance ); if ( $this->is_widget_empty( $fields ) ) { diff --git a/includes/class-social.php b/includes/class-social.php index 36181cd..8173f23 100644 --- a/includes/class-social.php +++ b/includes/class-social.php @@ -40,15 +40,18 @@ public function form( $instance ) { parent::form( $instance ); - $fields = $this->get_fields( $instance ); - $title_field = array_shift( $fields ); + // Unsorted fields + $fields = array_merge( + array_flip( array_keys( $this->get_fields( [] ) ) ), + $this->get_fields( $instance ) + ); echo '
    '; echo '
    '; // Title field - $this->render_form_input( $title_field ); + $this->render_form_input( array_shift( $fields ) ); echo '
    '; @@ -91,6 +94,7 @@ class="%s" echo '
    '; + // Sorted fields $fields = $this->order_field( $fields ); foreach ( $fields as $key => $field ) { @@ -133,7 +137,7 @@ class="%s" */ public function widget( $args, $instance ) { - $fields = $this->get_fields( $instance, [], true ); + $fields = $this->get_fields( $instance ); if ( $this->is_widget_empty( $fields ) ) { @@ -157,13 +161,13 @@ public function widget( $args, $instance ) { printf( '
  • %s
  • ', - $display_labels ? 'has-label' : 'no-label', + ( $display_labels ) ? 'has-label' : 'no-label', $escape_callback( $field['value'] ), esc_attr( $field['target'] ), sprintf( esc_attr_x( 'Visit %1$s on %2$s', '1. Title of website (e.g. My Cat Blog), 2. Name of social network (e.g. Facebook)', 'contact-widgets' ), get_bloginfo( 'name' ), $field['label'] ), isset( $fields['icon_size']['value'] ) ? esc_attr( $fields['icon_size']['value'] ) : '2x', esc_attr( $field['icon'] ), - $display_labels ? esc_html( $field['label'] ) : '' + ( $display_labels ) ? esc_html( $field['label'] ) : '' ); } @@ -201,12 +205,13 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t foreach ( $fields as $key => &$field ) { $default = [ - 'icon' => $key, - 'sanitizer' => 'esc_url_raw', - 'escaper' => 'esc_url', - 'select' => '', - 'social' => true, - 'target' => '_blank', + 'icon' => $key, + 'sanitizer' => 'esc_url_raw', + 'escaper' => 'esc_url', + 'select' => '', + 'social' => true, + 'save_default' => false, + 'target' => '_blank', ]; $field = wp_parse_args( $field, $default ); From 52706259470a40416f21cabf902b133a71893abc Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:17:48 -0600 Subject: [PATCH 48/90] Fix jshints --- assets/js/admin.js | 22 ++++++++++------------ assets/js/admin.min.js | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 3f6ed27..0b8dcbe 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -226,9 +226,7 @@ } var $block = $( this ).closest( '.time-block' ), - $clone = dayRow.cloneTimeBlock( $block, $block.parent() ), - $close = $block.find( 'select.time-block-close' ), - $open = $clone.find( 'select.time-block-open' ); + $clone = dayRow.cloneTimeBlock( $block, $block.parent() ); $clone.find( 'a.button' ).attr( 'data-action', 'remove' ).text( '-' ); @@ -280,13 +278,13 @@ var $blocks = $day.find( '.time-block' ); - $widget.find( '.day-row' ).not( $day ).each( function( index ) { + $widget.find( '.day-row' ).not( $day ).each( function() { var $target = $( this ).find( '.time-blocks' ); $target.empty(); - $blocks.each( function( index ) { + $blocks.each( function() { dayRow.cloneTimeBlock( $( this ), $target, true, true ); @@ -299,12 +297,12 @@ cloneTimeBlock: function ( $block, $target, deep, flashDay ) { var $day = $block.closest( '.day-row' ), - day = parseInt( $day.attr( 'data-day' ) ), - target_day = parseInt( $target.closest( '.day-row' ).attr( 'data-day' ) ), - block = parseInt( $block.attr( 'data-time-block' ) ), - target_block = $target.is( ':empty' ) ? 0 : parseInt( $target.find( '.time-block' ).last().attr( 'data-time-block' ) ) + 1, - deep = ( 'undefined' === typeof deep ) ? false : deep, - flashDay = ( 'undefined' === typeof flashDay ) ? false : flashDay, + day = parseInt( $day.attr( 'data-day' ), 10 ), + target_day = parseInt( $target.closest( '.day-row' ).attr( 'data-day' ), 10 ), + block = parseInt( $block.attr( 'data-time-block' ), 10 ), + target_block = $target.is( ':empty' ) ? 0 : parseInt( $target.find( '.time-block' ).last().attr( 'data-time-block' ), 10 ) + 1, + deep = deep || false, + flashDay = flashDay || false, $clone = $block.clone( deep ), html = $clone.html(), name_search = '\\[schedule\\]\\[' + day + '\\]\\[blocks\\]\\[' + block + '\\]', @@ -319,7 +317,7 @@ if ( deep ) { - $clone.find( 'select' ).each( function( index ) { + $clone.find( 'select' ).each( function() { var classes = $( this ) .attr( 'class' ) diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index c641926..1ccd28c 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());c.find("select.time-block-close"),e.find("select.time-block-open");e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(b){var c=a(this).find(".time-blocks");c.empty(),g.each(function(b){d.cloneTimeBlock(a(this),c,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day")),h=parseInt(c.closest(".day-row").attr("data-day")),i=parseInt(b.attr("data-time-block")),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"))+1,d="undefined"==typeof d?!1:d,e="undefined"==typeof e?!1:e,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(c){var d=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+d).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file From 2aabdc06aba9ce396aaa3f266a245df6620220e3 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:19:08 -0600 Subject: [PATCH 49/90] Update PHP versions in tests --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5dc0c2e..de5359e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ language: - node_js php: - - 5.6 - - 7.0 + - 5.4 + - 7.1 env: - WP_VERSION=4.4 WP_MULTISITE=0 From a95995fe5cbeac2f2f6217ed81317573ac1194c2 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:20:52 -0600 Subject: [PATCH 50/90] Ignore bogus jshint snifs --- assets/js/admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 0b8dcbe..c3a9fb9 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -301,8 +301,8 @@ target_day = parseInt( $target.closest( '.day-row' ).attr( 'data-day' ), 10 ), block = parseInt( $block.attr( 'data-time-block' ), 10 ), target_block = $target.is( ':empty' ) ? 0 : parseInt( $target.find( '.time-block' ).last().attr( 'data-time-block' ), 10 ) + 1, - deep = deep || false, - flashDay = flashDay || false, + deep = deep || false, // jshint ignore:line + flashDay = flashDay || false, // jshint ignore:line $clone = $block.clone( deep ), html = $clone.html(), name_search = '\\[schedule\\]\\[' + day + '\\]\\[blocks\\]\\[' + block + '\\]', From c6f615b1abbca71892b521365c7a8c495ba3bd3d Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:29:58 -0600 Subject: [PATCH 51/90] Fix sniff --- includes/class-hours.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 41a35d2..0b0b961 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -313,8 +313,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f foreach ( $blocks as $block ) { - $next_block = $block + 1; - $is_last_block = empty( $this->get_field_value( $instance, "schedule[{$day}][blocks][{$next_block}][open]" ) ); + $is_last_block = ( false === $this->get_field_value( $instance, sprintf( 'schedule[%d][blocks][%d][open]', $day, $block + 1 ), false ) ); $fields["schedule[{$day}][blocks][{$block}][open]"] = [ 'type' => 'select', From 7d3f684befa86e0ffa21db312954afe4193b8830 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:30:12 -0600 Subject: [PATCH 52/90] Titles never sortable --- includes/class-base-widget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 922dc26..d976c84 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -160,7 +160,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = t $field = wp_parse_args( $field, $this->field_defaults ); // Title is never sortable and is always at the top - if ( $ordered && 'title' === $key ) { + if ( 'title' === $key ) { $field['sortable'] = false; From ff71d5ed97f9ad2e4973b63cf9349f7dc0f1a887 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:33:14 -0600 Subject: [PATCH 53/90] Codeception requires 5.6 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index de5359e..dd4a26b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: - node_js php: - - 5.4 + - 5.6 - 7.1 env: From d535b788305f26ce9390ec302d62bbaf8f898c17 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:40:42 -0600 Subject: [PATCH 54/90] Fix checkboxes in contact widget --- includes/class-base-widget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index d976c84..41c9919 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -108,7 +108,7 @@ public function update( $new_instance, $old_instance ) { foreach ( $fields as $key => $field ) { $order = array_search( $key, array_keys( $new_instance ) ); - $ordered = ( $has_sortables && 'title' !== $key && $order > 0 ); // Start at 1 since title order is 0 + $ordered = ( $has_sortables && 'title' !== $key ); $field_key = ( $ordered ) ? $key . '[value]' : $key; $sanitizer_callback = $field['sanitizer']; From caf836b912d4e4469974967bf5596d0d13cdb83f Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 00:42:15 -0600 Subject: [PATCH 55/90] Fix spacing sniffs --- includes/class-hours.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 0b0b961..2a92728 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -315,7 +315,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f $is_last_block = ( false === $this->get_field_value( $instance, sprintf( 'schedule[%d][blocks][%d][open]', $day, $block + 1 ), false ) ); - $fields["schedule[{$day}][blocks][{$block}][open]"] = [ + $fields[ "schedule[{$day}][blocks][{$block}][open]" ] = [ 'type' => 'select', 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, 'form_callback' => 'render_form_select', @@ -345,11 +345,11 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f
    'select', 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, 'form_callback' => 'render_form_select', @@ -370,7 +370,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f } - $fields["schedule[{$day}][closed]"] = [ + $fields[ "schedule[{$day}][closed]" ] = [ 'type' => 'checkbox', 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, 'class' => 'status-closed-checkbox', From 85efef5a420b2f401a92d9fde668e63e10f0c82f Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 28 Dec 2016 11:22:36 -0500 Subject: [PATCH 56/90] Style tweaks on widget button/closed checkbox --- assets/css/admin.css | 3 ++- assets/css/admin.min.css | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index b289e85..f957f05 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -180,6 +180,7 @@ width: calc(20% - 5px); font-size: 18px; text-align: center; + line-height: 1.2; } .wpcw-widget-hours .apply-to-all { @@ -191,5 +192,5 @@ } .wpcw-widget-hours .status-closed-checkbox input { - margin: 2px 0 0 5px; + margin: 0px 0 0 5px; } diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 1fbecb6..30fd1fd 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:2px 0 0 5px} \ No newline at end of file +.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center;line-height:1.2}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:0 0 0 5px} \ No newline at end of file From 0f43a5550595394b387ad63a7d33f575d5583862 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 10:27:51 -0600 Subject: [PATCH 57/90] Add support for hidden screen reader labels --- includes/class-base-widget.php | 4 +++- includes/class-hours.php | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/class-base-widget.php b/includes/class-base-widget.php index 41c9919..526045a 100644 --- a/includes/class-base-widget.php +++ b/includes/class-base-widget.php @@ -23,6 +23,7 @@ abstract class Base_Widget extends \WP_Widget { 'name' => '', 'label' => '', 'label_after' => false, + 'hide_label' => false, 'description' => '', 'type' => 'text', 'sanitizer' => 'sanitize_text_field', @@ -337,8 +338,9 @@ protected function is_widget_empty( array $fields ) { protected function print_label( array $field ) { printf( - ' ', + ' ', esc_attr( $field['id'] ), + ( $field['hide_label'] ) ? 'screen-reader-text' : '', esc_attr( $field['description'] ), esc_html( $field['label'] ) ); diff --git a/includes/class-hours.php b/includes/class-hours.php index 2a92728..2667bb6 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -318,11 +318,13 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f $fields[ "schedule[{$day}][blocks][{$block}][open]" ] = [ 'type' => 'select', 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, + 'label' => ( $block > 0 ) ? sprintf( _x( 'Open Time (Block %d)', 'time block number', 'contact-widgets' ), $block + 1 ) : __( 'Open Time', 'contact-widgets' ), + 'hide_label' => true, 'form_callback' => 'render_form_select', 'select_options' => $this->get_times(), 'prepend' => sprintf( '
    ', $block ), 'hide_empty' => ( $block > 0 ), - 'default' => ( 0 === $block ) ? '00:00' : '', + 'default' => ( $block > 0 ) ? '' : '00:00', 'class' => ( $is_closed ) ? 'widefat time-block-open disabled' : 'widefat time-block-open', 'sortable' => false, 'wrapper' => '', @@ -352,10 +354,12 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f $fields[ "schedule[{$day}][blocks][{$block}][close]" ] = [ 'type' => 'select', 'sanitizer' => function( $value ) { return date( 'H:i', strtotime( (string) $value ) ); }, + 'label' => ( $block > 0 ) ? sprintf( _x( 'Close Time (Block %d)', 'time block number', 'contact-widgets' ), $block + 1 ) : __( 'Close Time', 'contact-widgets' ), + 'hide_label' => true, 'form_callback' => 'render_form_select', 'select_options' => $this->get_times(), 'hide_empty' => ( $block > 0 ), - 'default' => ( 0 === $block ) ? '00:00' : '', + 'default' => ( $block > 0 ) ? '' : '00:00', 'class' => ( $is_closed ) ? 'widefat time-block-open disabled' : 'widefat time-block-open', 'sortable' => false, 'wrapper' => '', From fe766791e3f84d745a01f2e7489d1d3a8dee48ca Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 10:39:21 -0600 Subject: [PATCH 58/90] Fix classname on close selects --- includes/class-hours.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 2667bb6..eb419c6 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -360,7 +360,7 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'select_options' => $this->get_times(), 'hide_empty' => ( $block > 0 ), 'default' => ( $block > 0 ) ? '' : '00:00', - 'class' => ( $is_closed ) ? 'widefat time-block-open disabled' : 'widefat time-block-open', + 'class' => ( $is_closed ) ? 'widefat time-block-close disabled' : 'widefat time-block-close', 'sortable' => false, 'wrapper' => '', 'append' => sprintf( From c51e0beaa8e9c4eccce00b80358e75a997333ce1 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 28 Dec 2016 15:35:23 -0500 Subject: [PATCH 59/90] Display the 'Apply to All' link on only the first day in the widget --- includes/class-hours.php | 73 ++++++---------------------------------- 1 file changed, 11 insertions(+), 62 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index eb419c6..17c8b03 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -306,6 +306,8 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'description' => __( 'The title of this widget. Leave empty for no title.', 'contact-widgets' ), ]; + $iteration = 1; + foreach ( $this->get_days_of_week() as $day => $label ) { $is_closed = ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]" ) ); @@ -374,6 +376,11 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f } + $apply_to_all_link = ( 1 === $iteration ) ? sprintf( + '%s', + __( 'Apply to all', 'contact-widgets' ) + ) : ''; + $fields[ "schedule[{$day}][closed]" ] = [ 'type' => 'checkbox', 'sanitizer' => function ( $value ) { return ( 'yes' === (string) $value ) ? 'yes' : 'no'; }, @@ -385,12 +392,14 @@ protected function get_fields( array $instance, array $fields = [], $ordered = f 'sortable' => false, 'wrapper' => '', 'prepend' => sprintf( - '
    %s', - __( 'Apply to all', 'contact-widgets' ) + '
    %s', + $apply_to_all_link ), 'append' => '
    ', ]; + $iteration++; + } $fields['display_current_status'] = [ @@ -505,64 +514,4 @@ protected function get_times() { } - /** - * Generate the opening hours microformat markup - * @link https://schema.org/openingHours - * - * @since NEXT - * - * @param array $microformat_data Microformat data array. - * - * @return string - */ - protected function get_microformat_markup( $microformat_data, $iteration ) { - - $day = ucwords( substr( $microformat_data['day'], 0, 2 ) ); - $open = date( 'H:i', strtotime( $microformat_data['open'][ $iteration ] ) ); - $close = date( 'H:i', strtotime( $microformat_data['close'][ $iteration ] ) ); - - $microformat_attributes = [ - 'itemprop="openingHours"', - 'datetime="' . esc_attr( $day . ' ' . $open . '-' . $close ) . '"', - ]; - - return implode( ' ', $microformat_attributes ); - - } - - /** - * Check if the business is open based on the current server time - * - * @param array $hours Open/Closed times - * - * @since NEXT - * - * @return boolean - */ - protected function is_business_open( $hours ) { - - $iteration = 1; - - if ( $hours['not_open'] ) { - - return false; - - } - - foreach ( $hours['open'] as $open_hours ) { - - if ( $this->current_time >= strtotime( $open_hours ) && $this->current_time <= strtotime( $hours['closed'][ $iteration ] ) ) { - - return true; - - } - - $iteration++; - - } - - return false; - - } - } From eb19705e620787b6609aa1fbfb02ac4a25aaced7 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 28 Dec 2016 15:40:03 -0500 Subject: [PATCH 60/90] Remove overflow auto, causing scroll issues in hours of operation widget. --- assets/css/admin.css | 1 - assets/css/admin.min.css | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index f957f05..4ae5cf1 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -2,7 +2,6 @@ * Form fields */ .wpcw-widget .form { - overflow: auto; margin-bottom: 1em; } .wpcw-widget .title { diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 30fd1fd..16328c7 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{overflow:auto;margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center;line-height:1.2}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:0 0 0 5px} \ No newline at end of file +.wpcw-widget .form{margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center;line-height:1.2}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:0 0 0 5px} \ No newline at end of file From df306a3e3581f51e01d0d29286ae68cf09cc5950 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 28 Dec 2016 16:42:40 -0600 Subject: [PATCH 61/90] Add method to return an instance schedule --- includes/class-hours.php | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/includes/class-hours.php b/includes/class-hours.php index 17c8b03..3b977cb 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -514,4 +514,92 @@ protected function get_times() { } + /** + * Return the schedule of a widget instance. + * + * @param array $instance + * @param bool $group (optional) + * @param bool $hide_closed (optional) + * + * @return array + */ + public function get_schedule( array $instance, $group = false, $hide_closed = false ) { + + $schedule = []; + $days_of_week = $this->get_days_of_week(); + + foreach ( $days_of_week as $day => $label ) { + + $schedule[ $day ]['label'] = $label; + + $is_closed = ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]", 'no' ) ); + + if ( $is_closed ) { + + $schedule[ $day ]['open'] = false; + + if ( $hide_closed ) { + + unset( $schedule[ $day ] ); + + } + + continue; + + } + + $blocks = $this->get_field_value( $instance, "schedule[{$day}][blocks]", [] ); + + foreach ( $blocks as $block ) { + + $schedule[ $day ]['open'][] = [ $block['open'], $block['close'] ]; + + } + + } + + if ( ! $group ) { + + return $schedule; + + } + + $groups = []; + + foreach ( $schedule as $day => $data ) { + + if ( false === $data['open'] ) { + + if ( ! $hide_closed ) { + + $groups['closed']['label'][ $day ] = $days_of_week[ $day ]; + $groups['closed']['open'] = false; + + } + + continue; + + } + + foreach ( (array) $data['open'] as $block ) { + + if ( empty( $block[0] ) || empty( $block[1] ) ) { + + continue; + + } + + $key = md5( $block[0] . $block[1] ); + + $groups[ $key ]['label'][ $day ] = $days_of_week[ $day ]; + $groups[ $key ]['open'] = sprintf( '%s - %s', $block[0], $block[1] ); + + } + + } + + return array_values( $groups ); + + } + } From d349e9075627dd044945e68e6bb05304856190a3 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Wed, 28 Dec 2016 19:17:49 -0500 Subject: [PATCH 62/90] Populate/Display open sign based on end user time. --- assets/css/style.css | 7 ++-- assets/css/style.min.css | 2 +- assets/js/wp-hours-widget.js | 62 ++++++++++++++++++++++++++++++++ assets/js/wp-hours-widget.min.js | 1 + includes/class-hours.php | 8 +++++ 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 assets/js/wp-hours-widget.js create mode 100644 assets/js/wp-hours-widget.min.js diff --git a/assets/css/style.css b/assets/css/style.css index c59e58c..993440d 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -34,19 +34,18 @@ .wpcw-widget-social ul li.has-label span { margin-right: 0.25em; } -.wpcw-widget-hours ul li span.open-sign { +.wpcw-widget-hours ul li span.wpcw-open-sign { display: inline-block; - margin: 0 0 3px 5px; padding: 2px 5px; border-radius: 4px; border: 1px solid transparent; } -.wpcw-widget-hours ul li span.open-sign.open { +.wpcw-widget-hours ul li span.wpcw-open-sign.open { background-color: #dff0d8; border-color: #d6e9c6; color: #3c763d; } -.wpcw-widget-hours ul li span.open-sign.closed { +.wpcw-widget-hours ul li span.wpcw-open-sign.closed { background-color: #f2dede; border-color: #ebccd1; color: #a94442; diff --git a/assets/css/style.min.css b/assets/css/style.min.css index 36d37ea..693e2ce 100644 --- a/assets/css/style.min.css +++ b/assets/css/style.min.css @@ -1 +1 @@ -.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong.day,.wpcw-widget-hours ul li time,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em}.wpcw-widget-hours ul li span.open-sign{display:inline-block;margin:0 0 3px 5px;padding:2px 5px;border-radius:4px;border:1px solid transparent}.wpcw-widget-hours ul li span.open-sign.open{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}.wpcw-widget-hours ul li span.open-sign.closed{background-color:#f2dede;border-color:#ebccd1;color:#a94442} \ No newline at end of file +.wpcw-widget-contact ul,.wpcw-widget-hours ul,.wpcw-widget-social ul{margin:0;padding:0;list-style:none}.wpcw-widget-contact ul li,.wpcw-widget-hours ul li,.wpcw-widget-social ul li.has-label{padding:10px 0}.wpcw-widget-contact ul li:after,.wpcw-widget-contact ul li:before,.wpcw-widget-hours ul li:after,.wpcw-widget-hours ul li:before,.wpcw-widget-social ul li:after,.wpcw-widget-social ul li:before{display:none}.wpcw-widget-contact ul li div{display:inline}.wpcw-widget-social ul li:not(.has-label){display:inline-block;margin:0 .75em .75em 0;border:none}.wpcw-widget-hours ul li strong.day,.wpcw-widget-hours ul li time,.wpcw-widget-social ul li.has-label a{display:block}.wpcw-widget-social ul li.has-label span{margin-right:.25em}.wpcw-widget-hours ul li span.wpcw-open-sign{display:inline-block;padding:2px 5px;border-radius:4px;border:1px solid transparent}.wpcw-widget-hours ul li span.wpcw-open-sign.open{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d}.wpcw-widget-hours ul li span.wpcw-open-sign.closed{background-color:#f2dede;border-color:#ebccd1;color:#a94442} \ No newline at end of file diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js new file mode 100644 index 0000000..f02c91e --- /dev/null +++ b/assets/js/wp-hours-widget.js @@ -0,0 +1,62 @@ +( function ( $ ) { + + var hoursWidget = { + + init: function( e ) { + + var date = new Date(), + cur_time = hoursWidget.getCurrentTime( date ), + time_blocks = wpcw_hours.schedule[ date.getDay() ].open, + $open_sign = $( '.wpcw-open-sign' ); + + + if ( ! time_blocks ) { + + $open_sign.addClass( 'closed' ).html( 'Closed' ); + + return; + + } + + for ( i = 0; i < time_blocks.length; i++ ) { + + if ( cur_time < time_blocks[ i ][1] && cur_time >= time_blocks[ i ][0] ) { + + $open_sign.addClass( 'open' ).html( 'Open' ); + + return; + + } + + } + + $open_sign.addClass( 'closed' ).html( 'Closed' ); + + }, + + getCurrentTime: function( date ) { + + var h = hoursWidget.addZeros( date.getHours() ), + m = hoursWidget.addZeros( date.getMinutes() ); + + return h + ":" + m; + + }, + + addZeros: function( time ) { + + if ( time < 10 ) { + + time = "0" + time; + + } + + return time; + + } + + }; + + hoursWidget.init(); + +} )( jQuery ); diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js new file mode 100644 index 0000000..437bb46 --- /dev/null +++ b/assets/js/wp-hours-widget.min.js @@ -0,0 +1 @@ +!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html("Closed");for(i=0;i=f[i][0])return void g.addClass("open").html("Open");g.addClass("closed").html("Closed")},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 3b977cb..c204780 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -196,6 +196,14 @@ public function widget( $args, $instance ) { if ( $display_current_status ) { + $suffix = SCRIPT_DEBUG ? '' : '.min'; + + wp_enqueue_script( 'wpcw-hours', \Contact_Widgets::$assets_url . "js/wp-hours-widget{$suffix}.js", [ 'jquery' ], Plugin::$version, true ); + + wp_localize_script( 'wpcw-hours', 'wpcw_hours', [ + 'schedule' => $this->get_schedule( $instance ), + ] ); + /** * TODO: Handle this with JavaScript so it works with full-page caching. * From 953b3508298460af919c8d12db16862802bbb995 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 29 Dec 2016 03:30:07 -0600 Subject: [PATCH 63/90] Add logic to group days together --- includes/class-hours.php | 212 +++++++++++++++++++++++++++++---------- 1 file changed, 160 insertions(+), 52 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index c204780..85921c8 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -215,43 +215,21 @@ public function widget( $args, $instance ) { } - /** - * TODO: Combine days that have identical hours when the - * `$display_in_groups` option is ON. - * - * And it should also group closed days if the `$hide_closed` - * option is OFF. - * - * e.g. - * - * Monday - Friday - * 9:00 am - 5:00 pm - * - * Saturday - * 9:00 am - 12:00 pm - * - * Sunday - * Closed - */ - foreach ( $this->get_days_of_week() as $day => $label ) { + $schedule = $this->get_schedule( $instance, $display_in_groups, $hide_closed ); - $is_closed = ( 'yes' === $this->get_field_value( $instance, "schedule[{$day}][closed]", 'no' ) ); + foreach ( $schedule as $day => $data ) { + + $is_closed = ( false === $data['open'] ); - if ( $hide_closed && $is_closed ) { + if ( $is_closed && $hide_closed ) { continue; } - $time_blocks = $this->get_field_value( $instance, "schedule[{$day}][blocks]", [] ); - $time_blocks = array_combine( - wp_list_pluck( $time_blocks, 'open' ), - wp_list_pluck( $time_blocks, 'close' ) - ); - echo '
  • '; - printf( '%s', esc_html( $label ) ); + printf( '%s', esc_html( $data['label'] ) ); if ( $is_closed ) { @@ -261,27 +239,50 @@ public function widget( $args, $instance ) { } + $time_blocks = is_array( $data['open'] ) ? $data['open'] : [ explode( '-', $data['open'] ) ]; + $time_blocks = array_combine( + wp_list_pluck( $time_blocks, 0 ), + wp_list_pluck( $time_blocks, 1 ) + ); + + $datetime = ! empty( $data['datetime'] ) ? $data['datetime'] : null; + + if ( ! $datetime ) { + + $datetime = sprintf( + '%s %s', + substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), + implode( + ', ', + array_map( + function ( $close, $open ) { + return sprintf( '%s-%s', $open, $close ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) + ) + ); + + } + printf( - '', - substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), - implode( ', ', array_map( - function ( $close, $open ) { - return sprintf( '%s-%s', $open, $close ); - }, - $time_blocks, - array_keys( $time_blocks ) - ) ), - implode( '
    ', array_map( - function ( $close, $open ) { - return sprintf( - '%s – %s', - date( (string) get_option( 'time_format' ), strtotime( $open ) ), - date( (string) get_option( 'time_format' ), strtotime( $close ) ) - ); - }, - $time_blocks, - array_keys( $time_blocks ) - ) ) + '', + $datetime, + implode( + '
    ', + array_map( + function ( $close, $open ) { + return sprintf( + '%s – %s', + date( (string) get_option( 'time_format' ), strtotime( $open ) ), + date( (string) get_option( 'time_format' ), strtotime( $close ) ) + ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) + ) ); echo '
  • '; @@ -580,8 +581,8 @@ public function get_schedule( array $instance, $group = false, $hide_closed = fa if ( ! $hide_closed ) { - $groups['closed']['label'][ $day ] = $days_of_week[ $day ]; - $groups['closed']['open'] = false; + $groups['closed']['label'][] = $day; + $groups['closed']['open'] = false; } @@ -599,15 +600,122 @@ public function get_schedule( array $instance, $group = false, $hide_closed = fa $key = md5( $block[0] . $block[1] ); - $groups[ $key ]['label'][ $day ] = $days_of_week[ $day ]; - $groups[ $key ]['open'] = sprintf( '%s - %s', $block[0], $block[1] ); + $groups[ $key ]['label'][] = $day; + $groups[ $key ]['open'] = sprintf( '%s-%s', $block[0], $block[1] ); } } + foreach ( $groups as $key => &$group ) { + + // Microformat datetime + $group['datetime'] = sprintf( + '%s %s', + implode( + ',', + array_map( + function ( $day ) { + return substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ); + }, + $group['label'] + ) + ), + $group['open'] + ); + + $group['label'] = $this->get_grouped_days_label( $group['label'] ); + + } + return array_values( $groups ); } + /** + * Return a label for days that are grouped together that + * also honors the `start_of_week` setting. + * + * @param array $days + * + * @return string + */ + protected function get_grouped_days_label( array $days ) { + + $slices = []; + $days_of_week = $this->get_days_of_week(); + $week = array_keys( $days_of_week ); + + foreach ( array_values( array_diff( $week, $days ) ) as $day ) { + + $slice = array_slice( $week, 0, (int) array_search( $day, $week ) ); + $week = array_values( array_diff( $week, $slice ) ); + + unset( $week[0] ); + + $week = array_values( $week ); + $slice = array_combine( + $slice, + array_intersect_key( + $days_of_week, + array_flip( $slice ) + ) + ); + + $slices[] = $slice; + + } + + $last = array_intersect( $week, $days ); + + $slices[] = array_combine( + $last, + array_intersect_key( + $days_of_week, + array_flip( $last ) + ) + ); + + $labels = []; + + foreach ( array_values( array_filter( $slices ) ) as $range ) { + + $count = count( $range ); + + if ( 1 === $count || 2 === $count ) { + + $labels[] = array_shift( $range ); + + } + + if ( 2 === $count ) { + + $labels[] = array_pop( $range ); + + } + + if ( $count > 2 ) { + + $labels[] = sprintf( + '%s – %s', + array_shift( $range ), + array_pop( $range ) + ); + + } + + } + + $length = count( $labels ) - 2; + + return trim( + sprintf( + '%s %s', + ( $length > 0 ) ? implode( ', ', array_slice( $labels, 0, $length ) ) . ',' : null, + implode( ' & ', array_slice( $labels, -2, 2 ) ) + ) + ); + + } + } From f03c51f2540220f3cc5b51efd1fe3dfd107bbba3 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 29 Dec 2016 04:24:55 -0600 Subject: [PATCH 64/90] Support grouping on days with multiple time blocks --- includes/class-hours.php | 118 ++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 85921c8..720c6ad 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -239,36 +239,14 @@ public function widget( $args, $instance ) { } - $time_blocks = is_array( $data['open'] ) ? $data['open'] : [ explode( '-', $data['open'] ) ]; $time_blocks = array_combine( - wp_list_pluck( $time_blocks, 0 ), - wp_list_pluck( $time_blocks, 1 ) + wp_list_pluck( $data['open'], 0 ), + wp_list_pluck( $data['open'], 1 ) ); - $datetime = ! empty( $data['datetime'] ) ? $data['datetime'] : null; - - if ( ! $datetime ) { - - $datetime = sprintf( - '%s %s', - substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), - implode( - ', ', - array_map( - function ( $close, $open ) { - return sprintf( '%s-%s', $open, $close ); - }, - $time_blocks, - array_keys( $time_blocks ) - ) - ) - ); - - } - printf( '', - $datetime, + ! empty( $data['datetime'] ) ? $data['datetime'] : null, implode( '
    ', array_map( @@ -565,6 +543,26 @@ public function get_schedule( array $instance, $group = false, $hide_closed = fa } + $time_blocks = array_combine( + wp_list_pluck( $blocks, 'open' ), + wp_list_pluck( $blocks, 'close' ) + ); + + $schedule[ $day ]['datetime'] = sprintf( + '%s %s', + substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), + implode( + ',', + array_map( + function ( $close, $open ) { + return sprintf( '%s-%s', $open, $close ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) + ) + ); + } if ( ! $group ) { @@ -590,39 +588,57 @@ public function get_schedule( array $instance, $group = false, $hide_closed = fa } - foreach ( (array) $data['open'] as $block ) { - - if ( empty( $block[0] ) || empty( $block[1] ) ) { - - continue; - - } - - $key = md5( $block[0] . $block[1] ); - - $groups[ $key ]['label'][] = $day; - $groups[ $key ]['open'] = sprintf( '%s-%s', $block[0], $block[1] ); + $key = md5( + implode( + '', + array_map( + function ( $block ) { + return sprintf( '%s-%s', $block[0], $block[1] ); + }, + $data['open'] + ) + ) + ); - } + $groups[ $key ]['label'][] = $day; + $groups[ $key ]['open'] = $data['open']; } foreach ( $groups as $key => &$group ) { - // Microformat datetime - $group['datetime'] = sprintf( - '%s %s', - implode( - ',', - array_map( - function ( $day ) { - return substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ); - }, - $group['label'] + if ( false !== $group['open'] ) { + + $time_blocks = array_combine( + wp_list_pluck( $group['open'], 0 ), + wp_list_pluck( $group['open'], 1 ) + ); + + // Microformat datetime + $group['datetime'] = sprintf( + '%s %s', + implode( + ',', + array_map( + function ( $day ) { + return substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ); + }, + $group['label'] + ) + ), + implode( + ',', + array_map( + function ( $close, $open ) { + return sprintf( '%s-%s', $open, $close ); + }, + $time_blocks, + array_keys( $time_blocks ) + ) ) - ), - $group['open'] - ); + ); + + } $group['label'] = $this->get_grouped_days_label( $group['label'] ); From 2a2778cb05ac7d9f55ee25462c64b824ef5f30e7 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 09:58:43 -0500 Subject: [PATCH 65/90] Localize open/closed strings --- assets/js/wp-hours-widget.js | 4 ++-- assets/js/wp-hours-widget.min.js | 2 +- includes/class-hours.php | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index f02c91e..f778cba 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -22,7 +22,7 @@ if ( cur_time < time_blocks[ i ][1] && cur_time >= time_blocks[ i ][0] ) { - $open_sign.addClass( 'open' ).html( 'Open' ); + $open_sign.addClass( 'open' ).html( wpcw_hours.open_string ); return; @@ -30,7 +30,7 @@ } - $open_sign.addClass( 'closed' ).html( 'Closed' ); + $open_sign.addClass( 'closed' ).html( wpcw_hours.closed_string ); }, diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index 437bb46..593ce97 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html("Closed");for(i=0;i=f[i][0])return void g.addClass("open").html("Open");g.addClass("closed").html("Closed")},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html("Closed");for(i=0;i=f[i][0])return void g.addClass("open").html(wpcw_hours.open_string);g.addClass("closed").html(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 720c6ad..2bddfcc 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -201,7 +201,9 @@ public function widget( $args, $instance ) { wp_enqueue_script( 'wpcw-hours', \Contact_Widgets::$assets_url . "js/wp-hours-widget{$suffix}.js", [ 'jquery' ], Plugin::$version, true ); wp_localize_script( 'wpcw-hours', 'wpcw_hours', [ - 'schedule' => $this->get_schedule( $instance ), + 'schedule' => $this->get_schedule( $instance ), + 'open_string' => __( 'Open', 'contact-widgets' ), + 'closed_string' => __( 'Closed', 'contact-widgets' ), ] ); /** From 75b9fa7a4f2d09975b7ebd779be786a08a6bcd1e Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 10:27:45 -0500 Subject: [PATCH 66/90] Tweak closed string. --- assets/js/wp-hours-widget.js | 2 +- assets/js/wp-hours-widget.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index f778cba..2c0ae09 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -12,7 +12,7 @@ if ( ! time_blocks ) { - $open_sign.addClass( 'closed' ).html( 'Closed' ); + $open_sign.addClass( 'closed' ).html( wpcw_hours.closed_string ); return; diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index 593ce97..c4da73b 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html("Closed");for(i=0;i=f[i][0])return void g.addClass("open").html(wpcw_hours.open_string);g.addClass("closed").html(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html(wpcw_hours.closed_string);for(i=0;i=f[i][0])return void g.addClass("open").html(wpcw_hours.open_string);g.addClass("closed").html(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file From cc026846bcb52becc71818ecd142006d3529aa62 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 13:14:29 -0500 Subject: [PATCH 67/90] First pass at dynamic time options based on selection --- assets/js/admin.js | 40 ++++++++++++++++++++++++++++++++ assets/js/admin.min.js | 2 +- assets/js/wp-hours-widget.js | 28 ++++++++-------------- assets/js/wp-hours-widget.min.js | 2 +- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index c3a9fb9..f55536a 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -362,6 +362,39 @@ $day.find( 'select' ).toggleClass( 'disabled', ! closed ); + }, + + changeTime: function( e ) { + + var $target = $( e.currentTarget ), + time = $target.val(); + + dayRow.updateTimeSelect( $target, time ); + + }, + + updateTimeSelect: function( $target, time ) { + + var $parent = $target.closest( '.time-block' ), + $close_select = $parent.find( '.time-block-close' ); + + $close_select.children().show(); + $close_select.find( 'option[value="' + time + '"]' ).prevAll().andSelf().hide(); + + if ( time === $target.find( 'option:last-child' ).val() ) { + + $close_select.find( 'option:first-child' ).show().prop( 'selected', true ); + + return; + + } + + if ( time >= $close_select.val() ) { + + $close_select.find( 'option[value="' + time + '"]' ).next().prop( 'selected', true ); + + } + } }; @@ -378,6 +411,13 @@ $( document ).on( 'click', '.wpcw-widget-hours .time-block a.button[data-action="remove"]', dayRow.removeBlock ); $( document ).on( 'click', '.wpcw-widget-hours .apply-to-all', dayRow.applyToAll ); $( document ).on( 'change', '.wpcw-widget-hours .status-closed-checkbox input', dayRow.toggleClosed ); + $( document ).on( 'change', '.wpcw-widget-hours .time-block-open', dayRow.changeTime ); + + $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function( e ) { + + dayRow.updateTimeSelect( $( this ), $( this ).val() ); + + } ); // Sortable $( document ).on( 'wpcw.change', start_sortable ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 1ccd28c..cc1a393 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(a,b){var c=a.closest(".time-block"),d=c.find(".time-block-close");return d.children().show(),d.find('option[value="'+b+'"]').prevAll().andSelf().hide(),b===a.find("option:last-child").val()?void d.find("option:first-child").show().prop("selected",!0):void(b>=d.val()&&d.find('option[value="'+b+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 2c0ae09..15da7bb 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -9,28 +9,26 @@ time_blocks = wpcw_hours.schedule[ date.getDay() ].open, $open_sign = $( '.wpcw-open-sign' ); + if ( time_blocks.length ) { - if ( ! time_blocks ) { + for ( i = 0; i < time_blocks.length; i++ ) { - $open_sign.addClass( 'closed' ).html( wpcw_hours.closed_string ); + var open_time = ( '00:00' !== time_blocks[ i ][0] ) ? time_blocks[ i ][0] : '24:00', + closed_time = ( '00:00' !== time_blocks[ i ][1] ) ? time_blocks[ i ][1] : '24:00'; - return; + if ( cur_time < closed_time && cur_time >= open_time ) { - } - - for ( i = 0; i < time_blocks.length; i++ ) { + $open_sign.addClass( 'open' ).text( wpcw_hours.open_string ); - if ( cur_time < time_blocks[ i ][1] && cur_time >= time_blocks[ i ][0] ) { + return; - $open_sign.addClass( 'open' ).html( wpcw_hours.open_string ); - - return; + } } } - $open_sign.addClass( 'closed' ).html( wpcw_hours.closed_string ); + $open_sign.addClass( 'closed' ).text( wpcw_hours.closed_string ); }, @@ -45,13 +43,7 @@ addZeros: function( time ) { - if ( time < 10 ) { - - time = "0" + time; - - } - - return time; + return ( time < 10 ) ? "0" + time : time; } diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index c4da73b..2ce0eba 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(!f)return void g.addClass("closed").html(wpcw_hours.closed_string);for(i=0;i=f[i][0])return void g.addClass("open").html(wpcw_hours.open_string);g.addClass("closed").html(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a&&(a="0"+a),a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(f.length)for(i=0;ie&&e>=h)return void g.addClass("open").text(wpcw_hours.open_string)}g.addClass("closed").text(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file From a5fe450b40d9462cf7b2d3505c5770f8c2a636a5 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 13:23:15 -0500 Subject: [PATCH 68/90] Tweak admin.js so when the widget is updated, the fields are re-hidden appropriately. --- assets/js/admin.js | 15 +++++++++++++++ assets/js/admin.min.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index f55536a..d41776a 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -375,6 +375,18 @@ updateTimeSelect: function( $target, time ) { + if ( ! $target ) { + + $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function( e ) { + + dayRow.updateTimeSelect( $( this ), $( this ).val() ); + + } ); + + return; + + } + var $parent = $target.closest( '.time-block' ), $close_select = $parent.find( '.time-block-close' ); @@ -423,6 +435,9 @@ $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); $( document ).on( 'widget-updated', start_sortable ); + $( document ).on( 'widget-updated', function() { + dayRow.updateTimeSelect(); + } ); } ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index cc1a393..6b54aaa 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(a,b){var c=a.closest(".time-block"),d=c.find(".time-block-close");return d.children().show(),d.find('option[value="'+b+'"]').prevAll().andSelf().hide(),b===a.find("option:last-child").val()?void d.find("option:first-child").show().prop("selected",!0):void(b>=d.val()&&d.find('option[value="'+b+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b)})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b),a(document).on("widget-updated",function(){d.updateTimeSelect()})})}(jQuery); \ No newline at end of file From 1781a3febc2f81f1fc0b69de388c7dbd153be2f5 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 13:24:49 -0500 Subject: [PATCH 69/90] Refactor. --- assets/js/admin.js | 5 ++++- assets/js/admin.min.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index d41776a..d77feef 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -434,9 +434,12 @@ // Sortable $( document ).on( 'wpcw.change', start_sortable ); $( document ).on( 'click.widgets-toggle', start_sortable ); - $( document ).on( 'widget-updated', start_sortable ); $( document ).on( 'widget-updated', function() { + + start_sortable(); + dayRow.updateTimeSelect(); + } ); } ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 6b54aaa..16730e1 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",b),a(document).on("widget-updated",function(){d.updateTimeSelect()})})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",function(){b(),d.updateTimeSelect()})})}(jQuery); \ No newline at end of file From 8b064f1ebbbb8bd8868197bfcb1983607271efab Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 29 Dec 2016 12:36:06 -0600 Subject: [PATCH 70/90] Abstract datetime logic, use key/value pairs for open times --- includes/class-hours.php | 114 +++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 64 deletions(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 2bddfcc..612e955 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -241,14 +241,9 @@ public function widget( $args, $instance ) { } - $time_blocks = array_combine( - wp_list_pluck( $data['open'], 0 ), - wp_list_pluck( $data['open'], 1 ) - ); - printf( '', - ! empty( $data['datetime'] ) ? $data['datetime'] : null, + $data['datetime'], implode( '
    ', array_map( @@ -259,8 +254,8 @@ function ( $close, $open ) { date( (string) get_option( 'time_format' ), strtotime( $close ) ) ); }, - $time_blocks, - array_keys( $time_blocks ) + $data['open'], + array_keys( $data['open'] ) ) ) ); @@ -541,29 +536,11 @@ public function get_schedule( array $instance, $group = false, $hide_closed = fa foreach ( $blocks as $block ) { - $schedule[ $day ]['open'][] = [ $block['open'], $block['close'] ]; + $schedule[ $day ]['open'][ $block['open'] ] = $block['close']; } - $time_blocks = array_combine( - wp_list_pluck( $blocks, 'open' ), - wp_list_pluck( $blocks, 'close' ) - ); - - $schedule[ $day ]['datetime'] = sprintf( - '%s %s', - substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ), - implode( - ',', - array_map( - function ( $close, $open ) { - return sprintf( '%s-%s', $open, $close ); - }, - $time_blocks, - array_keys( $time_blocks ) - ) - ) - ); + $schedule[ $day ]['datetime'] = $this->get_datetime( $day, $schedule[ $day ]['open'] ); } @@ -581,8 +558,8 @@ function ( $close, $open ) { if ( ! $hide_closed ) { - $groups['closed']['label'][] = $day; - $groups['closed']['open'] = false; + $groups['closed']['label'][ $day ] = $days_of_week[ $day ]; + $groups['closed']['open'] = false; } @@ -594,16 +571,17 @@ function ( $close, $open ) { implode( '', array_map( - function ( $block ) { - return sprintf( '%s-%s', $block[0], $block[1] ); + function ( $close, $open ) { + return $open . $close; }, - $data['open'] + $data['open'], + array_keys( $data['open'] ) ) ) ); - $groups[ $key ]['label'][] = $day; - $groups[ $key ]['open'] = $data['open']; + $groups[ $key ]['label'][ $day ] = $days_of_week[ $day ]; + $groups[ $key ]['open'] = $data['open']; } @@ -611,38 +589,11 @@ function ( $block ) { if ( false !== $group['open'] ) { - $time_blocks = array_combine( - wp_list_pluck( $group['open'], 0 ), - wp_list_pluck( $group['open'], 1 ) - ); - - // Microformat datetime - $group['datetime'] = sprintf( - '%s %s', - implode( - ',', - array_map( - function ( $day ) { - return substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ); - }, - $group['label'] - ) - ), - implode( - ',', - array_map( - function ( $close, $open ) { - return sprintf( '%s-%s', $open, $close ); - }, - $time_blocks, - array_keys( $time_blocks ) - ) - ) - ); + $group['datetime'] = $this->get_datetime( array_keys( $group['label'] ), $group['open'] ); } - $group['label'] = $this->get_grouped_days_label( $group['label'] ); + $group['label'] = $this->get_grouped_days_label( array_keys( $group['label'] ) ); } @@ -736,4 +687,39 @@ protected function get_grouped_days_label( array $days ) { } + /** + * Return a datetime string suitable for microformats. + * + * e.g. Mo,Tu,We,Th,Fr 09:00-17:00 + * + * @param int|array $days + * @param array $time_blocks + * + * @return string + */ + protected function get_datetime( $days, array $time_blocks ) { + + $days = array_map( + function ( $day ) { + return substr( jddayofweek( fmod( $day - 1, 7 ), 2 ), 0, 2 ); + }, + (array) $days + ); + + $times = array_map( + function ( $close, $open ) { + return sprintf( '%s-%s', $open, $close ); + }, + $time_blocks, + array_keys( $time_blocks ) + ); + + return sprintf( + '%s %s', + implode( ',', $days ), + implode( ',', $times ) + ); + + } + } From 1bfbc9f4687ab0cd34da62942a426da507deefc2 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 13:49:10 -0500 Subject: [PATCH 71/90] Refactor our loop for open business label - front end of site. --- assets/js/wp-hours-widget.js | 27 +++++++++++++++++---------- assets/js/wp-hours-widget.min.js | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 15da7bb..0437c9d 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -7,24 +7,31 @@ var date = new Date(), cur_time = hoursWidget.getCurrentTime( date ), time_blocks = wpcw_hours.schedule[ date.getDay() ].open, - $open_sign = $( '.wpcw-open-sign' ); + $open_sign = $( '.wpcw-open-sign' ), + open = false; - if ( time_blocks.length ) { + if ( time_blocks ) { - for ( i = 0; i < time_blocks.length; i++ ) { + $.each( time_blocks, function( open_time, close_time ) { - var open_time = ( '00:00' !== time_blocks[ i ][0] ) ? time_blocks[ i ][0] : '24:00', - closed_time = ( '00:00' !== time_blocks[ i ][1] ) ? time_blocks[ i ][1] : '24:00'; + open_time = ( '00:00' !== open_time ) ? open_time : '24:00'; + close_time = ( '00:00' !== close_time ) ? close_time : '24:00'; - if ( cur_time < closed_time && cur_time >= open_time ) { + if ( cur_time < close_time && cur_time >= open_time ) { - $open_sign.addClass( 'open' ).text( wpcw_hours.open_string ); - - return; + open = true; } - } + } ); + + } + + if ( open ) { + + $open_sign.addClass( 'open' ).text( wpcw_hours.open_string ); + + return; } diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index 2ce0eba..06ec205 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign");if(f.length)for(i=0;ie&&e>=h)return void g.addClass("open").text(wpcw_hours.open_string)}g.addClass("closed").text(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign"),h=!1;return f&&a.each(f,function(a,b){a="00:00"!==a?a:"24:00",b="00:00"!==b?b:"24:00",b>e&&e>=a&&(h=!0)}),h?void g.addClass("open").text(wpcw_hours.open_string):void g.addClass("closed").text(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file From fa0cab0292a59ea601c6212542ac18056613a204 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 30 Dec 2016 04:37:12 +0500 Subject: [PATCH 72/90] Update open/closed sign based on end user locale. --- assets/js/wp-hours-widget.js | 27 ++++++++++++++++----------- assets/js/wp-hours-widget.min.js | 2 +- includes/class-hours.php | 6 ++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 0437c9d..39e7998 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -5,19 +5,19 @@ init: function( e ) { var date = new Date(), - cur_time = hoursWidget.getCurrentTime( date ), - time_blocks = wpcw_hours.schedule[ date.getDay() ].open, - $open_sign = $( '.wpcw-open-sign' ), - open = false; + gmt_time = wpcw_hours.gmt_time, + time_blocks = wpcw_hours.schedule[ date.getDay() ].open, + $open_sign = $( '.wpcw-open-sign' ), + open = false; if ( time_blocks ) { $.each( time_blocks, function( open_time, close_time ) { - open_time = ( '00:00' !== open_time ) ? open_time : '24:00'; - close_time = ( '00:00' !== close_time ) ? close_time : '24:00'; + open_time = ( '00:00' === open_time ) ? '24:00' : open_time; + close_time = ( '00:00' === close_time ) ? '24:00' : close_time; - if ( cur_time < close_time && cur_time >= open_time ) { + if ( gmt_time < hoursWidget.localizeTime( close_time ) && gmt_time >= hoursWidget.localizeTime( open_time ) ) { open = true; @@ -39,12 +39,17 @@ }, - getCurrentTime: function( date ) { + localizeTime: function( time ) { - var h = hoursWidget.addZeros( date.getHours() ), - m = hoursWidget.addZeros( date.getMinutes() ); + var time_parts = time.split( ':' ), + check_time = new Date(); - return h + ":" + m; + check_time.setHours( time_parts[0] ); + check_time.setMinutes( time_parts[1] ); + + var gmt_string = new Date( check_time.toGMTString() ); + + return hoursWidget.addZeros( gmt_string.getHours() ) + ':' + hoursWidget.addZeros( gmt_string.getMinutes() ); }, diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index 06ec205..1d4689f 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=b.getCurrentTime(d),f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign"),h=!1;return f&&a.each(f,function(a,b){a="00:00"!==a?a:"24:00",b="00:00"!==b?b:"24:00",b>e&&e>=a&&(h=!0)}),h?void g.addClass("open").text(wpcw_hours.open_string):void g.addClass("closed").text(wpcw_hours.closed_string)},getCurrentTime:function(a){var c=b.addZeros(a.getHours()),d=b.addZeros(a.getMinutes());return c+":"+d},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(c){var d=new Date,e=wpcw_hours.gmt_time,f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign"),h=!1;return f&&a.each(f,function(a,c){a="00:00"===a?"24:00":a,c="00:00"===c?"24:00":c,e=b.localize_time(a)&&(h=!0)}),h?void g.addClass("open").text(wpcw_hours.open_string):void g.addClass("closed").text(wpcw_hours.closed_string)},localize_time:function(a){var c=a.split(":"),d=new Date;d.setHours(c[0]),d.setMinutes(c[1]);var e=new Date(d.toGMTString());return b.addZeros(e.getHours())+":"+b.addZeros(e.getMinutes())},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file diff --git a/includes/class-hours.php b/includes/class-hours.php index 612e955..3f583dd 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -202,8 +202,10 @@ public function widget( $args, $instance ) { wp_localize_script( 'wpcw-hours', 'wpcw_hours', [ 'schedule' => $this->get_schedule( $instance ), - 'open_string' => __( 'Open', 'contact-widgets' ), - 'closed_string' => __( 'Closed', 'contact-widgets' ), + 'gmt_offset' => get_option( 'gmt_offset' ), + 'gmt_time' => current_time( 'H:i' ), + 'open_string' => apply_filters( 'wpcw_hours_open_string', __( 'Open', 'contact-widgets' ) ), + 'closed_string' => apply_filters( 'wpcw_hours_closed_string',__( 'Closed', 'contact-widgets' ) ), ] ); /** From 848102b83e425f1bde8a8ccea312a20688a10a89 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 30 Dec 2016 04:37:35 +0500 Subject: [PATCH 73/90] Remove rogue space. --- includes/class-hours.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-hours.php b/includes/class-hours.php index 3f583dd..31daf4b 100644 --- a/includes/class-hours.php +++ b/includes/class-hours.php @@ -716,7 +716,7 @@ function ( $close, $open ) { array_keys( $time_blocks ) ); - return sprintf( + return sprintf( '%s %s', implode( ',', $days ), implode( ',', $times ) From 4240312656ea5d02a34440798d35ab91354bcf89 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 19:01:17 -0500 Subject: [PATCH 74/90] Update js files for acceptance tests --- assets/js/admin.js | 4 ++-- assets/js/admin.min.js | 2 +- assets/js/wp-hours-widget.js | 14 +++++++------- assets/js/wp-hours-widget.min.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index d77feef..1c0605e 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -377,7 +377,7 @@ if ( ! $target ) { - $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function( e ) { + $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function() { dayRow.updateTimeSelect( $( this ), $( this ).val() ); @@ -425,7 +425,7 @@ $( document ).on( 'change', '.wpcw-widget-hours .status-closed-checkbox input', dayRow.toggleClosed ); $( document ).on( 'change', '.wpcw-widget-hours .time-block-open', dayRow.changeTime ); - $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function( e ) { + $( document ).find( '.wpcw-widget-hours .time-block-open' ).each( function() { dayRow.updateTimeSelect( $( this ), $( this ).val() ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index 16730e1..b52e11e 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(b){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",function(){b(),d.updateTimeSelect()})})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",function(){b(),d.updateTimeSelect()})})}(jQuery); \ No newline at end of file diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 39e7998..72e6063 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -2,7 +2,7 @@ var hoursWidget = { - init: function( e ) { + init: function() { var date = new Date(), gmt_time = wpcw_hours.gmt_time, @@ -41,13 +41,13 @@ localizeTime: function( time ) { - var time_parts = time.split( ':' ), - check_time = new Date(); + var time_parts = time.split( ':' ), + time_object = new Date(); - check_time.setHours( time_parts[0] ); - check_time.setMinutes( time_parts[1] ); + time_object.setHours( time_parts[0] ); + time_object.setMinutes( time_parts[1] ); - var gmt_string = new Date( check_time.toGMTString() ); + var gmt_string = new Date( time_object.toGMTString() ); return hoursWidget.addZeros( gmt_string.getHours() ) + ':' + hoursWidget.addZeros( gmt_string.getMinutes() ); @@ -55,7 +55,7 @@ addZeros: function( time ) { - return ( time < 10 ) ? "0" + time : time; + return ( time < 10 ) ? '0' + time : time; } diff --git a/assets/js/wp-hours-widget.min.js b/assets/js/wp-hours-widget.min.js index 1d4689f..6ffd325 100644 --- a/assets/js/wp-hours-widget.min.js +++ b/assets/js/wp-hours-widget.min.js @@ -1 +1 @@ -!function(a){var b={init:function(c){var d=new Date,e=wpcw_hours.gmt_time,f=wpcw_hours.schedule[d.getDay()].open,g=a(".wpcw-open-sign"),h=!1;return f&&a.each(f,function(a,c){a="00:00"===a?"24:00":a,c="00:00"===c?"24:00":c,e=b.localize_time(a)&&(h=!0)}),h?void g.addClass("open").text(wpcw_hours.open_string):void g.addClass("closed").text(wpcw_hours.closed_string)},localize_time:function(a){var c=a.split(":"),d=new Date;d.setHours(c[0]),d.setMinutes(c[1]);var e=new Date(d.toGMTString());return b.addZeros(e.getHours())+":"+b.addZeros(e.getMinutes())},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file +!function(a){var b={init:function(){var c=new Date,d=wpcw_hours.gmt_time,e=wpcw_hours.schedule[c.getDay()].open,f=a(".wpcw-open-sign"),g=!1;return e&&a.each(e,function(a,c){a="00:00"===a?"24:00":a,c="00:00"===c?"24:00":c,d=b.localizeTime(a)&&(g=!0)}),g?void f.addClass("open").text(wpcw_hours.open_string):void f.addClass("closed").text(wpcw_hours.closed_string)},localizeTime:function(a){var c=a.split(":"),d=new Date;d.setHours(c[0]),d.setMinutes(c[1]);var e=new Date(d.toGMTString());return b.addZeros(e.getHours())+":"+b.addZeros(e.getMinutes())},addZeros:function(a){return 10>a?"0"+a:a}};b.init()}(jQuery); \ No newline at end of file From 59ca9325b69296f5669bd481f8de1240790430ad Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 19:03:34 -0500 Subject: [PATCH 75/90] Add globals to the top of js file for localized variable --- assets/js/wp-hours-widget.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 72e6063..03df7bd 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -1,3 +1,4 @@ +/*globals wpcw_hours*/ ( function ( $ ) { var hoursWidget = { From b674ad002011cce82b22da2a532e91dd4a33e8a9 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Thu, 29 Dec 2016 19:04:18 -0500 Subject: [PATCH 76/90] update spacing in globals declaration --- assets/js/wp-hours-widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/wp-hours-widget.js b/assets/js/wp-hours-widget.js index 03df7bd..7751bb8 100644 --- a/assets/js/wp-hours-widget.js +++ b/assets/js/wp-hours-widget.js @@ -1,4 +1,4 @@ -/*globals wpcw_hours*/ +/* globals wpcw_hours */ ( function ( $ ) { var hoursWidget = { From 9ade607aa2622927bc664733bb5df061f534f8b1 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Fri, 30 Dec 2016 14:07:54 -0500 Subject: [PATCH 77/90] Update time selector fields. --- Gruntfile.js | 16 +- assets/css/admin.css | 5 +- assets/css/admin.min.css | 2 +- assets/css/jquery.timepicker.css | 72 ++ assets/css/jquery.timepicker.min.css | 1 + assets/js/admin.js | 14 +- assets/js/admin.min.js | 2 +- assets/js/jquery.timepicker.js | 1257 ++++++++++++++++++++++++++ assets/js/jquery.timepicker.min.js | 1 + includes/class-base-widget.php | 7 +- includes/class-hours.php | 52 +- 11 files changed, 1373 insertions(+), 56 deletions(-) create mode 100755 assets/css/jquery.timepicker.css create mode 100644 assets/css/jquery.timepicker.min.css create mode 100755 assets/js/jquery.timepicker.js create mode 100644 assets/js/jquery.timepicker.min.js diff --git a/Gruntfile.js b/Gruntfile.js index b5dc20c..5007ce0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,9 +29,12 @@ module.exports = function(grunt) { files: [{ expand: true, cwd: 'assets/css', - src: ['*.css', '!*.min.css'], + src: ['*.css', '!*.min.css', '!*.timepicker.css'], dest: 'assets/css', ext: '.min.css' + }, + { + 'assets/css/jquery.timepicker.min.css': ['assets/css/jquery.timepicker.css'] }] } }, @@ -45,8 +48,13 @@ module.exports = function(grunt) { cwd: 'assets/js', dest: 'assets/js', ext: '.min.js', - src: ['*.js', '!*.min.js'] - } + src: ['*.js', '!*.min.js', '!*.timepicker.js'] + }, + timepicker: { + files: { + 'assets/js/jquery.timepicker.min.js': ['assets/js/jquery.timepicker.js'] + } + }, }, watch: { @@ -59,7 +67,7 @@ module.exports = function(grunt) { tasks: ['cssmin'] }, uglify: { - files: ['*.js', '!*.js.css'], + files: ['*.js', '!*.min.js'], options: { cwd: 'assets/js', nospawn: true diff --git a/assets/css/admin.css b/assets/css/admin.css index 4ae5cf1..d851613 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -170,13 +170,14 @@ margin-bottom: 15px; } -.wpcw-widget-hours .time-block select { +.wpcw-widget-hours .time-block .timeselect { width: calc(40% - 5px); margin-right: 5px; + min-height: 28px; } .wpcw-widget-hours .time-block .button { - width: calc(20% - 5px); + width: calc(19% - 5px); font-size: 18px; text-align: center; line-height: 1.2; diff --git a/assets/css/admin.min.css b/assets/css/admin.min.css index 16328c7..96fc059 100644 --- a/assets/css/admin.min.css +++ b/assets/css/admin.min.css @@ -1 +1 @@ -.wpcw-widget .form{margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block select{width:calc(40% - 5px);margin-right:5px}.wpcw-widget-hours .time-block .button{width:calc(20% - 5px);font-size:18px;text-align:center;line-height:1.2}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:0 0 0 5px} \ No newline at end of file +.wpcw-widget .form{margin-bottom:1em}.wpcw-widget .title{margin-top:1em}.wpcw-widget .form p{margin:0 0 10px}.wpcw-widget .form p.sortable-placeholder{margin:0 0 8px}.wpcw-widget .form label i{margin:0 7px 0 3px}.wpcw-widget .form>p>span{display:table;width:100%}.wpcw-widget .form>p textarea{min-height:80px;resize:none;vertical-align:top}.wpcw-widget .form.ui-sortable>p .widefat{display:table-cell;width:100%}.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle{display:table-cell;position:relative;width:25px;background-color:#f7f7f7;border:1px solid #ddd;border-left:none;cursor:row-resize;cursor:grab;cursor:-moz-grab;cursor:-webkit-grab;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.04);-moz-box-shadow:0 1px 1px rgba(0,0,0,.04);box-shadow:0 1px 1px rgba(0,0,0,.04)}.wpcw-widget .form.ui-sortable .ui-sortable-helper *,.wpcw-widget .form.ui-sortable .wpcw-widget-sortable-handle:active{cursor:row-resize;cursor:grabbing;cursor:-moz-grabbing;cursor:-webkit-grabbing}.wpcw-widget .form.ui-sortable span.dashicons{position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;overflow:auto;font-size:18px;color:#a0a5aa}.wpcw-widget .form.ui-sortable span.dashicons:before{position:relative;top:1px}.wpcw-widget .default-fields{display:none}.wpcw-widget-social .icons{margin:10px 0}.wpcw-widget-social .icons a{margin:5px;font-size:20px;display:inline-block}.wpcw-widget-social .icons a:focus{box-shadow:none}.wpcw-widget-social .icons a.inactive:not(:hover){color:#ccc}.wpcw-widget-hours .day-row{display:inline-block;width:100%;padding:6px 0;border-bottom:1px solid #e5e5e5}.wpcw-widget-hours [class~=day-row]:last-of-type{margin-bottom:1em;border-bottom:none}.wpcw-widget-hours .day-row-top{padding:6px 0}.wpcw-widget-hours .day-row-top:hover{cursor:pointer}.wpcw-widget-hours .day-row-top strong{font-weight:500}.wpcw-widget-hours .toggle-icon{float:right;margin-top:-3px}.wpcw-widget-hours .status-closed-label,.wpcw-widget-hours .status-open-label{float:right;width:40%;margin-right:5px;font-weight:500;font-size:12px;text-transform:uppercase}.wpcw-widget-hours .status-open-label{color:#59CE45}.wpcw-widget-hours .status-closed-label{opacity:.5}.wpcw-widget-hours .day-row.status-closed .status-closed-label,.wpcw-widget-hours .day-row.status-open .status-open-label{display:block}.wpcw-widget-hours .day-row.status-closed .status-open-label,.wpcw-widget-hours .day-row.status-open .status-closed-label{display:none}.wpcw-widget-hours .day-row-container{display:none;float:left;width:100%;margin:10px 0 6px}.wpcw-widget-hours .time-block{width:100%;float:left;margin-bottom:10px}.wpcw-widget-hours .day-row-container div:last-of-type{margin-bottom:15px}.wpcw-widget-hours .time-block .timeselect{width:calc(40% - 5px);margin-right:5px;min-height:28px}.wpcw-widget-hours .time-block .button{width:calc(19% - 5px);font-size:18px;text-align:center;line-height:1.2}.wpcw-widget-hours .apply-to-all{float:left}.wpcw-widget-hours .status-closed-checkbox{float:right}.wpcw-widget-hours .status-closed-checkbox input{margin:0 0 0 5px} \ No newline at end of file diff --git a/assets/css/jquery.timepicker.css b/assets/css/jquery.timepicker.css new file mode 100755 index 0000000..cd75f13 --- /dev/null +++ b/assets/css/jquery.timepicker.css @@ -0,0 +1,72 @@ +.ui-timepicker-wrapper { + overflow-y: auto; + height: 150px; + width: 6.5em; + background: #fff; + border: 1px solid #ddd; + -webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2); + -moz-box-shadow:0 5px 10px rgba(0,0,0,0.2); + box-shadow:0 5px 10px rgba(0,0,0,0.2); + outline: none; + z-index: 10001; + margin: 0; +} + +.ui-timepicker-wrapper.ui-timepicker-with-duration { + width: 13em; +} + +.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-30, +.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-60 { + width: 11em; +} + +.ui-timepicker-list { + margin: 0; + padding: 0; + list-style: none; +} + +.ui-timepicker-duration { + margin-left: 5px; color: #888; +} + +.ui-timepicker-list:hover .ui-timepicker-duration { + color: #888; +} + +.ui-timepicker-list li { + padding: 3px 0 3px 5px; + cursor: pointer; + white-space: nowrap; + color: #000; + list-style: none; + margin: 0; +} + +.ui-timepicker-list:hover .ui-timepicker-selected { + background: #fff; color: #000; +} + +li.ui-timepicker-selected, +.ui-timepicker-list li:hover, +.ui-timepicker-list .ui-timepicker-selected:hover { + background: #1980EC; color: #fff; +} + +li.ui-timepicker-selected .ui-timepicker-duration, +.ui-timepicker-list li:hover .ui-timepicker-duration { + color: #ccc; +} + +.ui-timepicker-list li.ui-timepicker-disabled, +.ui-timepicker-list li.ui-timepicker-disabled:hover, +.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled { + color: #888; + cursor: default; +} + +.ui-timepicker-list li.ui-timepicker-disabled:hover, +.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled { + background: #f2f2f2; +} diff --git a/assets/css/jquery.timepicker.min.css b/assets/css/jquery.timepicker.min.css new file mode 100644 index 0000000..a956b91 --- /dev/null +++ b/assets/css/jquery.timepicker.min.css @@ -0,0 +1 @@ +.ui-timepicker-wrapper{overflow-y:auto;height:150px;width:6.5em;background:#fff;border:1px solid #ddd;-webkit-box-shadow:0 5px 10px rgba(0,0,0,.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,.2);box-shadow:0 5px 10px rgba(0,0,0,.2);outline:0;z-index:10001;margin:0}.ui-timepicker-wrapper.ui-timepicker-with-duration{width:13em}.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-30,.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-60{width:11em}.ui-timepicker-list{margin:0;padding:0;list-style:none}.ui-timepicker-duration{margin-left:5px;color:#888}.ui-timepicker-list:hover .ui-timepicker-duration{color:#888}.ui-timepicker-list li{padding:3px 0 3px 5px;cursor:pointer;white-space:nowrap;color:#000;list-style:none;margin:0}.ui-timepicker-list:hover .ui-timepicker-selected{background:#fff;color:#000}.ui-timepicker-list .ui-timepicker-selected:hover,.ui-timepicker-list li:hover,li.ui-timepicker-selected{background:#1980EC;color:#fff}.ui-timepicker-list li:hover .ui-timepicker-duration,li.ui-timepicker-selected .ui-timepicker-duration{color:#ccc}.ui-timepicker-list li.ui-timepicker-disabled,.ui-timepicker-list li.ui-timepicker-disabled:hover,.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled{color:#888;cursor:default}.ui-timepicker-list li.ui-timepicker-disabled:hover,.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled{background:#f2f2f2} \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index 1c0605e..7dd91c1 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -56,6 +56,12 @@ } + function initialize_timepicker() { + + $( '.timeselect' ).timepicker(); + + } + var socialField = { $btn: null, @@ -232,6 +238,8 @@ $( this ).hide(); + initialize_timepicker(); + }, removeBlock: function ( e ) { @@ -360,7 +368,7 @@ $day.find( 'a.button' ).toggleClass( 'disabled', ! closed ); - $day.find( 'select' ).toggleClass( 'disabled', ! closed ); + $day.find( '.timeselect' ).toggleClass( 'disabled', ! closed ); }, @@ -413,6 +421,8 @@ $( document ).ready( function ( $ ) { + initialize_timepicker(); + // Social $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); @@ -438,6 +448,8 @@ start_sortable(); + initialize_timepicker(); + dayRow.updateTimeSelect(); } ); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js index b52e11e..15aec02 100644 --- a/assets/js/admin.min.js +++ b/assets/js/admin.min.js @@ -1 +1 @@ -!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var c={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var d=c;return d.$btn=a(this),d.$widget=d.$btn.parents(".wpcw-widget"),d.$widget.find("."+d.$btn.data("key")).is(":animated")?!1:d.$btn.hasClass("inactive")?(d.$template=d.$widget.find(".default-fields"),d.$template=a(a.trim(d.$template.clone().html())),void d.add()):void d.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},d={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block"),e=d.cloneTimeBlock(c,c.parent());e.find("a.button").attr("data-action","remove").text("-"),a(this).hide()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),e=c.closest(".wpcw-widget"),f=e.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?e.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):e.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");e.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){d.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find("select").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),e=c.val();d.updateTimeSelect(c,e)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(){d.updateTimeSelect(a(this),a(this).val())});var e=b.closest(".time-block"),f=e.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){a(document).on("click",".wpcw-widget-social .icons a",c.init),a(document).on("click",".wpcw-widget-hours .day-row-top",d.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",d.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',d.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',d.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",d.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",d.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",d.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(){d.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",function(){b(),d.updateTimeSelect()})})}(jQuery); \ No newline at end of file +!function(a){function b(){var b=a(".wpcw-widget .form").not(".wpcw-widget-hours .form");b.sortable({items:"> *:not(.not-sortable)",handle:".wpcw-widget-sortable-handle",containment:"parent",placeholder:"sortable-placeholder",axis:"y",tolerance:"pointer",forcePlaceholderSize:!0,cursorAt:{top:40},stop:function(a,c){b.find(".customizer_update").val(c.item.index()).trigger("change")}})}function c(){a(".timeselect").timepicker()}a.fn.selectString=function(b){var c=a(this)[0],d=c.value.indexOf(b),e=d+b.length;if(c&&!(0>d))if(c.setSelectionRange)c.focus(),c.setSelectionRange(d,e);else if(c.createTextRange){var f=c.createTextRange();f.collapse(!0),f.moveEnd("character",e),f.moveStart("character",d),f.select()}else c.selectionStart&&(c.selectionStart=d,c.selectionEnd=e)};var d={$btn:null,$widget:null,$template:null,init:function(b){b.preventDefault();var c=d;return c.$btn=a(this),c.$widget=c.$btn.parents(".wpcw-widget"),c.$widget.find("."+c.$btn.data("key")).is(":animated")?!1:c.$btn.hasClass("inactive")?(c.$template=c.$widget.find(".default-fields"),c.$template=a(a.trim(c.$template.clone().html())),void c.add()):void c.remove()},add:function(){this.$btn.removeClass("inactive");var a=this.$btn.data();this.$template.addClass(a.key).find("label").prop("for",a.id),this.$template.find("input").prop("id",a.id).prop("name",a.name).prop("value",a.value),this.$template.find("label span.fa").prop("class",this.$btn.find("i").attr("class")),this.$template.find("label span.text").text(a.label),this.$template.hide().prependTo(this.$widget.find(".form")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250),this.$template.find("input").selectString(a.select),this.update_customizer()},remove:function(){this.$btn.addClass("inactive"),this.$widget.find(".form ."+this.$btn.data("key")).stop(!0,!0).animate({height:"toggle",opacity:"toggle"},250,function(){a(this).remove()}),this.update_customizer()},update_customizer:function(){var a=this.$widget.find("div > div").length;this.$widget.find(".customizer_update").val(a).trigger("change")}},e={toggle:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.find(".day-row-container");if(d.is(":animated"))return!1;var e=c.find(".toggle-icon"),f=c.hasClass("active");f||e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),d.slideToggle("fast",function(){f&&e.toggleClass("dashicons-arrow-down").toggleClass("dashicons-arrow-up"),c.toggleClass("active")})},maybeBlockSelect:function(b){var c=a(this).closest(".day-row");c.hasClass("status-closed")&&b.preventDefault()},addBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var d=a(this).closest(".time-block"),f=e.cloneTimeBlock(d,d.parent());f.find("a.button").attr("data-action","remove").text("-"),a(this).hide(),c()},removeBlock:function(b){if(b.preventDefault(),a(this).hasClass("disabled"))return!1;var c=a(this).closest(".time-block");c.prev(".time-block").find("a.button").show(),c.remove()},applyToAll:function(b){b.preventDefault();var c=a(this).closest(".day-row"),d=c.closest(".wpcw-widget"),f=d.find(".day-row").filter(function(){return a(this).is(":animated")});if(f.length>0)return!1;c.hasClass("status-closed")?d.find(".status-closed-checkbox input:not(:checked)").not(this).trigger("click"):d.find(".status-closed-checkbox input:checked").not(this).trigger("click");var g=c.find(".time-block");d.find(".day-row").not(c).each(function(){var b=a(this).find(".time-blocks");b.empty(),g.each(function(){e.cloneTimeBlock(a(this),b,!0,!0)})})},cloneTimeBlock:function(b,c,d,e){var f=b.closest(".day-row"),g=parseInt(f.attr("data-day"),10),h=parseInt(c.closest(".day-row").attr("data-day"),10),i=parseInt(b.attr("data-time-block"),10),j=c.is(":empty")?0:parseInt(c.find(".time-block").last().attr("data-time-block"),10)+1,d=d||!1,e=e||!1,k=b.clone(d),l=k.html(),m="\\[schedule\\]\\["+g+"\\]\\[blocks\\]\\["+i+"\\]",n="[schedule]["+h+"][blocks]["+j+"]",o="schedule-"+g+"-blocks-"+i,p="schedule-"+h+"-blocks-"+j;return l=l.replace(new RegExp(m,"g"),n),l=l.replace(new RegExp(o,"g"),p),k=k.html(l),d&&k.find("select").each(function(){var c=a(this).attr("class").split(" ").map(function(a){return a.trim()}).join(".");a(this).val(b.find("select."+c).val())}),c.append(k),k.attr("data-time-block",j),e&&k.closest(".day-row").fadeTo(50,.1,function(){a(this).fadeTo(500,1)}),k},toggleClosed:function(){var b=a(this).closest(".day-row"),c=b.hasClass("status-closed");b.toggleClass("status-closed").toggleClass("status-open"),b.find("a.button").toggleClass("disabled",!c),b.find(".timeselect").toggleClass("disabled",!c)},changeTime:function(b){var c=a(b.currentTarget),d=c.val();e.updateTimeSelect(c,d)},updateTimeSelect:function(b,c){if(!b)return void a(document).find(".wpcw-widget-hours .time-block-open").each(function(){e.updateTimeSelect(a(this),a(this).val())});var d=b.closest(".time-block"),f=d.find(".time-block-close");return f.children().show(),f.find('option[value="'+c+'"]').prevAll().andSelf().hide(),c===b.find("option:last-child").val()?void f.find("option:first-child").show().prop("selected",!0):void(c>=f.val()&&f.find('option[value="'+c+'"]').next().prop("selected",!0))}};a(document).ready(function(a){c(),a(document).on("click",".wpcw-widget-social .icons a",d.init),a(document).on("click",".wpcw-widget-hours .day-row-top",e.toggle),a(document).on("mousedown",".wpcw-widget-hours .time-block select",e.maybeBlockSelect),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="add"]',e.addBlock),a(document).on("click",'.wpcw-widget-hours .time-block a.button[data-action="remove"]',e.removeBlock),a(document).on("click",".wpcw-widget-hours .apply-to-all",e.applyToAll),a(document).on("change",".wpcw-widget-hours .status-closed-checkbox input",e.toggleClosed),a(document).on("change",".wpcw-widget-hours .time-block-open",e.changeTime),a(document).find(".wpcw-widget-hours .time-block-open").each(function(){e.updateTimeSelect(a(this),a(this).val())}),a(document).on("wpcw.change",b),a(document).on("click.widgets-toggle",b),a(document).on("widget-updated",function(){b(),c(),e.updateTimeSelect()})})}(jQuery); \ No newline at end of file diff --git a/assets/js/jquery.timepicker.js b/assets/js/jquery.timepicker.js new file mode 100755 index 0000000..5e6e275 --- /dev/null +++ b/assets/js/jquery.timepicker.js @@ -0,0 +1,1257 @@ +/*! + * jquery-timepicker v1.11.9 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. + * Copyright (c) 2015 Jon Thornton - http://jonthornton.github.com/jquery-timepicker/ + * License: MIT + */ + + +(function (factory) { + if (typeof exports === "object" && exports && + typeof module === "object" && module && module.exports === exports) { + // Browserify. Attach to jQuery module. + factory(require("jquery")); + } else if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { + var _ONE_DAY = 86400; + var _lang = { + am: 'am', + pm: 'pm', + AM: 'AM', + PM: 'PM', + decimal: '.', + mins: 'mins', + hr: 'hr', + hrs: 'hrs' + }; + + var methods = { + init: function(options) + { + return this.each(function() + { + var self = $(this); + + // pick up settings from data attributes + var attributeOptions = []; + for (var key in $.fn.timepicker.defaults) { + if (self.data(key)) { + attributeOptions[key] = self.data(key); + } + } + + var settings = $.extend({}, $.fn.timepicker.defaults, options, attributeOptions); + + if (settings.lang) { + _lang = $.extend(_lang, settings.lang); + } + + settings = _parseSettings(settings); + self.data('timepicker-settings', settings); + self.addClass('ui-timepicker-input'); + + if (settings.useSelect) { + _render(self); + } else { + self.prop('autocomplete', 'off'); + if (settings.showOn) { + for (var i in settings.showOn) { + self.on(settings.showOn[i]+'.timepicker', methods.show); + } + } + self.on('change.timepicker', _formatValue); + self.on('keydown.timepicker', _keydownhandler); + self.on('keyup.timepicker', _keyuphandler); + if (settings.disableTextInput) { + self.on('keydown.timepicker', _disableTextInputHandler); + } + + _formatValue.call(self.get(0), null, 'initial'); + } + }); + }, + + show: function(e) + { + var self = $(this); + var settings = self.data('timepicker-settings'); + + if (e) { + e.preventDefault(); + } + + if (settings.useSelect) { + self.data('timepicker-list').focus(); + return; + } + + if (_hideKeyboard(self)) { + // block the keyboard on mobile devices + self.blur(); + } + + var list = self.data('timepicker-list'); + + // check if input is readonly + if (self.prop('readonly')) { + return; + } + + // check if list needs to be rendered + if (!list || list.length === 0 || typeof settings.durationTime === 'function') { + _render(self); + list = self.data('timepicker-list'); + } + + if (_isVisible(list)) { + return; + } + + self.data('ui-timepicker-value', self.val()); + _setSelected(self, list); + + // make sure other pickers are hidden + methods.hide(); + + // position the dropdown relative to the input + list.show(); + var listOffset = {}; + + if (settings.orientation.match(/r/)) { + // right-align the dropdown + listOffset.left = self.offset().left + self.outerWidth() - list.outerWidth() + parseInt(list.css('marginLeft').replace('px', ''), 10); + } else { + // left-align the dropdown + listOffset.left = self.offset().left + parseInt(list.css('marginLeft').replace('px', ''), 10); + } + + var verticalOrientation; + if (settings.orientation.match(/t/)) { + verticalOrientation = 't'; + } else if (settings.orientation.match(/b/)) { + verticalOrientation = 'b'; + } else if ((self.offset().top + self.outerHeight(true) + list.outerHeight()) > $(window).height() + $(window).scrollTop()) { + verticalOrientation = 't'; + } else { + verticalOrientation = 'b'; + } + + if (verticalOrientation == 't') { + // position the dropdown on top + list.addClass('ui-timepicker-positioned-top'); + listOffset.top = self.offset().top - list.outerHeight() + parseInt(list.css('marginTop').replace('px', ''), 10); + } else { + // put it under the input + list.removeClass('ui-timepicker-positioned-top'); + listOffset.top = self.offset().top + self.outerHeight() + parseInt(list.css('marginTop').replace('px', ''), 10); + } + + list.offset(listOffset); + + // position scrolling + var selected = list.find('.ui-timepicker-selected'); + + if (!selected.length) { + var timeInt = _time2int(_getTimeValue(self)); + if (timeInt !== null) { + selected = _findRow(self, list, timeInt); + } else if (settings.scrollDefault) { + selected = _findRow(self, list, settings.scrollDefault()); + } + } + + if (selected && selected.length) { + var topOffset = list.scrollTop() + selected.position().top - selected.outerHeight(); + list.scrollTop(topOffset); + } else { + list.scrollTop(0); + } + + // prevent scroll propagation + if(settings.stopScrollPropagation) { + $(document).on('wheel.ui-timepicker', '.ui-timepicker-wrapper', function(e){ + e.preventDefault(); + var currentScroll = $(this).scrollTop(); + $(this).scrollTop(currentScroll + e.originalEvent.deltaY); + }); + } + + // attach close handlers + $(document).on('touchstart.ui-timepicker mousedown.ui-timepicker', _closeHandler); + $(window).on('resize.ui-timepicker', _closeHandler); + if (settings.closeOnWindowScroll) { + $(document).on('scroll.ui-timepicker', _closeHandler); + } + + self.trigger('showTimepicker'); + + return this; + }, + + hide: function(e) + { + var self = $(this); + var settings = self.data('timepicker-settings'); + + if (settings && settings.useSelect) { + self.blur(); + } + + $('.ui-timepicker-wrapper').each(function() { + var list = $(this); + if (!_isVisible(list)) { + return; + } + + var self = list.data('timepicker-input'); + var settings = self.data('timepicker-settings'); + + if (settings && settings.selectOnBlur) { + _selectValue(self); + } + + list.hide(); + self.trigger('hideTimepicker'); + }); + + return this; + }, + + option: function(key, value) + { + if (typeof key == 'string' && typeof value == 'undefined') { + return $(this).data('timepicker-settings')[key]; + } + + return this.each(function(){ + var self = $(this); + var settings = self.data('timepicker-settings'); + var list = self.data('timepicker-list'); + + if (typeof key == 'object') { + settings = $.extend(settings, key); + } else if (typeof key == 'string') { + settings[key] = value; + } + + settings = _parseSettings(settings); + + self.data('timepicker-settings', settings); + + _formatValue.call(self.get(0), {'type':'change'}, 'initial'); + + if (list) { + list.remove(); + self.data('timepicker-list', false); + } + + if (settings.useSelect) { + _render(self); + } + }); + }, + + getSecondsFromMidnight: function() + { + return _time2int(_getTimeValue(this)); + }, + + getTime: function(relative_date) + { + var self = this; + + var time_string = _getTimeValue(self); + if (!time_string) { + return null; + } + + var offset = _time2int(time_string); + if (offset === null) { + return null; + } + + if (!relative_date) { + relative_date = new Date(); + } + + // construct a Date from relative date, and offset's time + var time = new Date(relative_date); + time.setHours(offset / 3600); + time.setMinutes(offset % 3600 / 60); + time.setSeconds(offset % 60); + time.setMilliseconds(0); + + return time; + }, + + isVisible: function() { + var self = this; + var list = self.data('timepicker-list'); + return !!(list && _isVisible(list)); + }, + + setTime: function(value) + { + var self = this; + var settings = self.data('timepicker-settings'); + + if (settings.forceRoundTime) { + var prettyTime = _roundAndFormatTime(_time2int(value), settings) + } else { + var prettyTime = _int2time(_time2int(value), settings); + } + + if (value && prettyTime === null && settings.noneOption) { + prettyTime = value; + } + + _setTimeValue(self, prettyTime); + if (self.data('timepicker-list')) { + _setSelected(self, self.data('timepicker-list')); + } + + return this; + }, + + remove: function() + { + var self = this; + + // check if this element is a timepicker + if (!self.hasClass('ui-timepicker-input')) { + return; + } + + var settings = self.data('timepicker-settings'); + self.removeAttr('autocomplete', 'off'); + self.removeClass('ui-timepicker-input'); + self.removeData('timepicker-settings'); + self.off('.timepicker'); + + // timepicker-list won't be present unless the user has interacted with this timepicker + if (self.data('timepicker-list')) { + self.data('timepicker-list').remove(); + } + + if (settings.useSelect) { + self.show(); + } + + self.removeData('timepicker-list'); + + return this; + } + }; + + // private methods + + function _isVisible(elem) + { + var el = elem[0]; + return el.offsetWidth > 0 && el.offsetHeight > 0; + } + + function _parseSettings(settings) + { + if (settings.minTime) { + settings.minTime = _time2int(settings.minTime); + } + + if (settings.maxTime) { + settings.maxTime = _time2int(settings.maxTime); + } + + if (settings.durationTime && typeof settings.durationTime !== 'function') { + settings.durationTime = _time2int(settings.durationTime); + } + + if (settings.scrollDefault == 'now') { + settings.scrollDefault = function() { + return settings.roundingFunction(_time2int(new Date()), settings); + } + } else if (settings.scrollDefault && typeof settings.scrollDefault != 'function') { + var val = settings.scrollDefault; + settings.scrollDefault = function() { + return settings.roundingFunction(_time2int(val), settings); + } + } else if (settings.minTime) { + settings.scrollDefault = function() { + return settings.roundingFunction(settings.minTime, settings); + } + } + + if ($.type(settings.timeFormat) === "string" && settings.timeFormat.match(/[gh]/)) { + settings._twelveHourTime = true; + } + + if (settings.showOnFocus === false && settings.showOn.indexOf('focus') != -1) { + settings.showOn.splice(settings.showOn.indexOf('focus'), 1); + } + + if (settings.disableTimeRanges.length > 0) { + // convert string times to integers + for (var i in settings.disableTimeRanges) { + settings.disableTimeRanges[i] = [ + _time2int(settings.disableTimeRanges[i][0]), + _time2int(settings.disableTimeRanges[i][1]) + ]; + } + + // sort by starting time + settings.disableTimeRanges = settings.disableTimeRanges.sort(function(a, b){ + return a[0] - b[0]; + }); + + // merge any overlapping ranges + for (var i = settings.disableTimeRanges.length-1; i > 0; i--) { + if (settings.disableTimeRanges[i][0] <= settings.disableTimeRanges[i-1][1]) { + settings.disableTimeRanges[i-1] = [ + Math.min(settings.disableTimeRanges[i][0], settings.disableTimeRanges[i-1][0]), + Math.max(settings.disableTimeRanges[i][1], settings.disableTimeRanges[i-1][1]) + ]; + settings.disableTimeRanges.splice(i, 1); + } + } + } + + return settings; + } + + function _render(self) + { + var settings = self.data('timepicker-settings'); + var list = self.data('timepicker-list'); + + if (list && list.length) { + list.remove(); + self.data('timepicker-list', false); + } + + if (settings.useSelect) { + list = $('",{"class":"ui-timepicker-select"});var g=d}else{d=a("
      ",{"class":"ui-timepicker-list"});var g=a("
      ",{"class":"ui-timepicker-wrapper",tabindex:-1});g.css({display:"none",position:"absolute"}).append(d)}if(c.noneOption)if(c.noneOption===!0&&(c.noneOption=c.useSelect?"Time...":"None"),a.isArray(c.noneOption)){for(var i in c.noneOption)if(parseInt(i,10)==i){var k=e(c.noneOption[i],c.useSelect);d.append(k)}}else{var k=e(c.noneOption,c.useSelect);d.append(k)}if(c.className&&g.addClass(c.className),(null!==c.minTime||null!==c.durationTime)&&c.showDuration){"function"==typeof c.step?"function":c.step;g.addClass("ui-timepicker-with-duration"),g.addClass("ui-timepicker-step-"+c.step)}var l=c.minTime;"function"==typeof c.durationTime?l=t(c.durationTime()):null!==c.durationTime&&(l=c.durationTime);var n=null!==c.minTime?c.minTime:0,o=null!==c.maxTime?c.maxTime:n+v-1;n>o&&(o+=v),o===v-1&&"string"===a.type(c.timeFormat)&&c.show2400&&(o=v);var p=c.disableTimeRanges,w=0,y=p.length,z=c.step;"function"!=typeof z&&(z=function(){return c.step});for(var i=n,A=0;o>=i;A++,i+=60*z(A)){var B=i,C=s(B,c);if(c.useSelect){var D=a("