← All changes
|
includes/page-availability-general/_src/availability_general_page.js
+51
-9
11.1
→
11.8.4
View file →
| @@ -67,35 +67,72 @@ | ||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | function scroll_to_group( group_name ) { |
| 70 | 70 | var $group = $( '.wpbc_ui__collapsible_group[data-group="' + group_name + '"]' ); |
| 71 | - var $scroll_parent; | |
| 71 | + var $scroll_parent = $(); | |
| 72 | + var scroll_parent_el; | |
| 73 | + var group_el; | |
| 72 | 74 | var scroll_top; |
| 75 | + var parent_rect; | |
| 76 | + var group_rect; | |
| 73 | 77 | |
| 74 | 78 | if ( ! $group.length ) { |
| 75 | 79 | return; |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | - $scroll_parent = $group.closest( '.wpbc_ui_el__vert_right_bar__content, .wpbc_rightbar_palette, .wpbc_ag_rightbar_panels' ).first(); | |
| 82 | + $group.parents().each( function () { | |
| 83 | + var $candidate = $( this ); | |
| 84 | + var overflow_y = $candidate.css( 'overflow-y' ); | |
| 79 | 85 | |
| 86 | + if ( | |
| 87 | + $candidate.hasClass( 'simplebar-content-wrapper' ) | |
| 88 | + || ( | |
| 89 | + /(auto|scroll)/.test( overflow_y ) | |
| 90 | + && this.scrollHeight > this.clientHeight | |
| 91 | + ) | |
| 92 | + ) { | |
| 93 | + $scroll_parent = $candidate; | |
| 94 | + return false; | |
| 95 | + } | |
| 96 | + } ); | |
| 97 | + | |
| 80 | 98 | if ( ! $scroll_parent.length ) { |
| 81 | - $group.get( 0 ).scrollIntoView( { block: 'start' } ); | |
| 99 | + $scroll_parent = $group.closest( '.wpbc_ui_el__vert_right_bar__content' ).find( '.simplebar-content-wrapper' ).first(); | |
| 100 | + } | |
| 101 | + | |
| 102 | + if ( ! $scroll_parent.length ) { | |
| 103 | + $group.get( 0 ).scrollIntoView( { block: 'nearest' } ); | |
| 82 | 104 | return; |
| 83 | 105 | } |
| 84 | 106 | |
| 85 | - scroll_top = $scroll_parent.scrollTop() + $group.position().top - 10; | |
| 107 | + scroll_parent_el = $scroll_parent.get( 0 ); | |
| 108 | + group_el = $group.get( 0 ); | |
| 109 | + parent_rect = scroll_parent_el.getBoundingClientRect(); | |
| 110 | + group_rect = group_el.getBoundingClientRect(); | |
| 111 | + scroll_top = $scroll_parent.scrollTop() + group_rect.top - parent_rect.top - 10; | |
| 112 | + | |
| 86 | 113 | $scroll_parent.stop().animate( { scrollTop: Math.max( 0, scroll_top ) }, 180 ); |
| 87 | 114 | } |
| 88 | 115 | |
| 89 | 116 | function apply_open_section_from_url() { |
| 90 | - if ( 'working_time' !== cfg.open_section ) { | |
| 117 | + var section_groups = { | |
| 118 | + weekdays: 'general-availability-weekdays', | |
| 119 | + from_today: 'general-availability-from-today', | |
| 120 | + buffer: 'general-availability-buffer', | |
| 121 | + working_time: 'general-availability-working-time' | |
| 122 | + }; | |
| 123 | + var group_name = section_groups[ cfg.open_section ] || ''; | |
| 124 | + | |
| 125 | + if ( '' === group_name ) { | |
| 91 | 126 | return; |
| 92 | 127 | } |
| 93 | 128 | |
| 94 | - open_group( 'general-availability-working-time', true ); | |
| 95 | - setTimeout( function () { | |
| 96 | - scroll_to_group( 'general-availability-working-time' ); | |
| 97 | - }, 120 ); | |
| 129 | + open_group( group_name, true ); | |
| 130 | + $.each( [ 120, 650 ], function ( index, delay ) { | |
| 131 | + setTimeout( function () { | |
| 132 | + scroll_to_group( group_name ); | |
| 133 | + }, delay ); | |
| 134 | + } ); | |
| 98 | 135 | } |
| 99 | 136 | |
| 100 | 137 | function refresh_buffer_fields() { |
| 101 | 138 | var value = $( 'input[name="booking_unavailable_extra_in_out"]:checked' ).val() || ''; |
| @@ -921,8 +958,13 @@ | ||
| 921 | 958 | cfg.settings = response.data.settings; |
| 922 | 959 | } |
| 923 | 960 | |
| 924 | 961 | load_calendar_preview(); |
| 962 | + document.dispatchEvent( new CustomEvent( 'wpbc:availability-general:settings-saved', { | |
| 963 | + detail: { | |
| 964 | + settings: response.data && response.data.settings ? response.data.settings : {} | |
| 965 | + } | |
| 966 | + } ) ); | |
| 925 | 967 | show_message( ( response.data && response.data.message ) || ( cfg.i18n && cfg.i18n.saved ) || 'General availability settings updated.', 'success', 2000 ); |
| 926 | 968 | } ).fail( function () { |
| 927 | 969 | show_message( ( cfg.i18n && cfg.i18n.save_failed ) || 'Unable to save general availability settings.', 'error', 10000 ); |
| 928 | 970 | } ).always( function () { |