-
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 36 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.
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,155 @@ | |
| // Social | ||
| $( document ).on( 'click', '.wpcw-widget-social .icons a', socialField.init ); | ||
|
|
||
| $( 'body' ).on( 'click', '.day-container', function() { | ||
|
|
||
| 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(); | ||
|
|
||
| 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( '<a href="#" class="remove-time button-secondary"><span class="dashicons dashicons-no-alt"></span></a>' ); | ||
|
|
||
| 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(); | ||
|
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 This method is misspelled. |
||
|
|
||
| } ); | ||
|
|
||
| $( '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 ) { | ||
|
|
||
| var select_fields = $( e.currentTarget ).parents( '.day-container' ).find( 'select' ); | ||
|
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 As a good rule of thumb, vars that represent element objects should use a |
||
|
|
||
| if ( $( this ).is( ':checked' ) ) { | ||
|
|
||
| select_fields.attr( 'disabled', 'disabled' ); | ||
|
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 The |
||
|
|
||
| return; | ||
|
|
||
| } | ||
|
|
||
| select_fields.removeAttr( 'disabled' ); | ||
|
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 This should be changed to |
||
|
|
||
| } ); | ||
|
|
||
| // 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' ) ) { | ||
|
|
||
| $( '.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(); | ||
|
|
||
| return; | ||
|
|
||
| } | ||
|
|
||
| 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() { | ||
|
|
||
| $( 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( '<a href="#" class="remove-time button-secondary"><span class="dashicons dashicons-no-alt"></span></a>' ); | ||
|
|
||
| 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(); | ||
|
|
||
| } ); | ||
|
|
||
| // Sortable | ||
| $( document ).on( 'wpcw.change', start_sortable ); | ||
| $( document ).on( 'click.widgets-toggle', start_sortable ); | ||
|
|
||
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 We should target this widget specifically, just like we do on the Social widget: