-
Notifications
You must be signed in to change notification settings - Fork 16
Hours of Operation Widget #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 7 commits
0d4b47e
161f710
2b6d398
b61adc7
f4f8b2f
19e194a
85be62d
9e45c18
9d89524
ae5944c
d078738
0b4f41a
0d97494
a7925cd
8a82f3f
cbf7f2a
76d74dd
f23620f
48d5ae9
f82c4d8
0552d7f
5fca127
b25ab37
296094d
d2aef42
e9d98d6
ee6a926
864ccbd
d8cc2f4
89a17f0
bb6d088
0a8ddfb
6d6fc2d
5d59db8
23fb005
3a7c2db
5a93723
202a1cc
180b1c0
665acab
e41cd5f
d4774c6
001894c
8f54b39
f427f15
f9f8f6b
74f5b75
5270625
2aabdc0
a95995f
c6f615b
7d3f684
ff71d5e
d535b78
caf836b
fd557f2
85efef5
0f43a55
fe76679
c51e0be
eb19705
df306a3
d349e90
953b350
f03c51f
2a2778c
75b9fa7
cc02684
a5fe450
1781a3f
8b064f1
1bfbc9f
fa0cab0
848102b
4240312
59ca932
b674ad0
9ade607
33aa7f0
f49522a
13ce03b
17b99b6
2b53502
ddd5710
c7f36f9
ee8eed6
06d70b7
9883db7
5d5c4a9
e3bb055
0ae298f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)', | ||
|
|
@@ -166,6 +166,50 @@ | |
| // 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' ); | ||
|
||
|
|
||
| } ); | ||
|
|
||
| $( '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 ); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @EvanHerman Don't increment the version number until we decide to release the plugin.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbardo I think the version was incremented because we tagged the previous release when we bumped the tested up to version to 4.7.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @EvanHerman That's weird, it shouldn't show off as a change then. Okay moving on!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonathanbardo I think the issue was that the version was bumped in the |
||
| * Author: GoDaddy | ||
| * Author URI: https://godaddy.com | ||
| * Text Domain: contact-widgets | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -396,10 +396,120 @@ 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; | ||
|
|
||
| $apply_to_all_toggle = key( $field['days'] ) === $day ? '<a href="#" class="js_wpcw_apply_hours_to_all">' . sprintf( _x( 'Apply to All %s', 'Dashicon Down Arrow', 'contact-widgets' ), '<span class="dashicons dashicons-arrow-down-alt"></span>' ) . '</a>' : ''; | ||
|
|
||
| printf( | ||
| '<div class="day-container">%1$s<p>%2$s</p></div>', | ||
| '<strong>' . esc_html( ucwords( $day ) ) . '<span class="day-checkbox-toggle">' . $apply_to_all_toggle . '<input name="' . $field['name'] . '[not_open]" id="' . $field['name'] . '[not_open]" class="js_wphoow_closed_checkbox" type="checkbox" value="1" ' . $this->checked( $hours['not_open'], true ) . '><label for="' . $field['name'] . '[not_open]" class="js_wphoow_closed_checkbox"><small>' . esc_html__( 'Closed', 'contact-widgets' ) . '</small></label></strong></span>', | ||
| $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 NEXT | ||
| * | ||
| * @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"' : ''; | ||
|
|
||
| ?> | ||
|
|
||
| <select name="<?php echo esc_attr( $field['name'] . '[open]' ); ?>" <?php echo $disabled_field; ?>> | ||
|
|
||
| <?php | ||
|
|
||
| foreach ( $times as $time ) { | ||
|
|
||
| ?> | ||
|
|
||
| <option <?php selected( $hours['open'], $time ); ?>><?php echo esc_html( $time ); ?></option> | ||
|
|
||
| <?php | ||
|
|
||
| } | ||
|
|
||
| ?> | ||
|
|
||
| </select> | ||
|
|
||
| <select name="<?php echo esc_attr( $field['name'] . '[closed]' ); ?>" <?php echo $disabled_field; ?>> | ||
|
|
||
| <?php | ||
|
|
||
| foreach ( $times as $time ) { | ||
|
|
||
| ?> | ||
|
|
||
| <option <?php selected( $hours['closed'], $time ); ?>><?php echo esc_html( $time ); ?></option> | ||
|
|
||
| <?php | ||
|
|
||
| } | ||
|
|
||
| ?> | ||
|
|
||
| </select> | ||
|
|
||
| <?php | ||
|
|
||
| return ob_get_clean(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Generate an array of times in half hour increments | ||
| * | ||
| * @since NEXT | ||
| * | ||
| * @return array | ||
| */ | ||
| 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 | ||
| * | ||
| * @param array $field | ||
| * @param array | ||
| */ | ||
| protected function after_form_field( array $field ) { | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EvanHerman As a good rule of thumb, vars that represent element objects should use a
$prefix, while vars that simple contain data should not. This can be helpful when examining the code later.