1/** 2 * Free date hints runtime. 3 * 4 * Mirrors the public Pro cost-hint trigger names when they are not already 5 * present, so existing integrations can call the same functions. 6 */ 7// FixIn: 10.15.6.2. 8(function ( w, $ ) { 9 'use strict'; 10 11 var knownHints = [ 12 'check_in_date_hint', 13 'check_out_date_hint', 14 'selected_dates_hint', 15 'days_number_hint', 16 'start_time_hint', 17 'end_time_hint' 18 ]; 19 20 w.wpbc_free_date_hints__apply = function ( resourceId, hints ) { 21 resourceId = parseInt( resourceId, 10 ) || 1; 22 hints = hints || {}; 23 24 $.each( hints, function ( hintName, hintValue ) { 25 var valueText = $( '<div />' ).html( hintValue ).text(); 26 27 $( '#' + hintName + '_tip' + resourceId + ',.' + hintName + '_tip' + resourceId ).html( hintValue ); 28 $( '#' + hintName + resourceId ).val( valueText ); 29 30 if ( typeof w.wpbc__spin_loader__micro__hide === 'function' ) { 31 w.wpbc__spin_loader__micro__hide( hintName + '_tip' + resourceId ); 32 } 33 } ); 34 }; 35 36 if ( typeof w.wpbc_send_ajax__show_cost_hints !== 'function' ) { 37 w.wpbc_send_ajax__show_cost_hints = function ( resourceId ) { 38 var allDates, 39 formData, 40 myBookingFormName = '', 41 nonceEl, 42 inst; 43 44 resourceId = parseInt( resourceId, 10 ) || 1; 45 46 $( '.booking_form_div' ).trigger( 'before_show_cost_hints', [ resourceId ] ); 47 48 if ( document.getElementById( 'parent_of_additional_calendar' + resourceId ) !== null ) { 49 resourceId = parseInt( document.getElementById( 'parent_of_additional_calendar' + resourceId ).value, 10 ) || resourceId; 50 } 51 52 if ( 0 === $( '#booking_form' + resourceId ).find( '.wpbc_free_date_hint' ).length ) { 53 return false; 54 } 55 56 allDates = $( '#date_booking' + resourceId ).val() || ''; 57 58 if ( 59 'undefined' !== typeof _wpbc && 60 'dynamic' === _wpbc.calendar__get_param_value( resourceId, 'days_select_mode' ) 61 ) { 62 inst = ( typeof w.wpbc_calendar__get_inst === 'function' ) ? w.wpbc_calendar__get_inst( resourceId ) : null; 63 $( '.wpbc_select_check_out_date_message' ).remove(); 64 if ( null !== inst && inst.stayOpen === true ) { 65 $( '.wpbc_free_date_hint' ).html( '...' ); 66 return false; 67 } 68 } 69 70 $.each( knownHints, function ( index, hintName ) { 71 var hintId = hintName + '_tip' + resourceId; 72 73 if ( typeof w.wpbc__spin_loader__micro__show__inside === 'function' ) { 74 w.wpbc__spin_loader__micro__show__inside( hintId, '#' + hintId + ',.' + hintId ); 75 } else { 76 $( '#' + hintId + ',.' + hintId ).html( '...' ); 77 } 78 } ); 79 80 if ( document.getElementById( 'booking_form_type' + resourceId ) !== null ) { 81 myBookingFormName = document.getElementById( 'booking_form_type' + resourceId ).value; 82 } 83 84 nonceEl = document.getElementById( 'wpbc_nonceCALCULATE_THE_COST' + resourceId ); 85 if ( ! nonceEl ) { 86 return false; 87 } 88 89 formData = wpbc_free_date_hints__get_form_fields_as_string( resourceId ); 90 91 $.ajax( { 92 url: w.wpbc_url_ajax, 93 type: 'POST', 94 success: function ( data, textStatus ) { 95 if ( 'success' === textStatus ) { 96 $( '#ajax_respond_insert' + resourceId ).html( data ); 97 } 98 $( '.booking_form_div' ).trigger( 'after_show_cost_hints', [ resourceId ] ); 99 }, 100 error: function ( XMLHttpRequest, textStatus ) { 101 w.status = 'Ajax sending Error status:' + textStatus; 102 if ( w.console && w.console.error ) { 103 w.console.error( XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText ); 104 } 105 }, 106 data: { 107 action: 'CALCULATE_THE_COST', 108 form: formData, 109 all_dates: allDates, 110 bk_type: resourceId, 111 booking_form_type: myBookingFormName, 112 wpdev_active_locale: ( 'undefined' !== typeof _wpbc ) ? _wpbc.get_other_param( 'locale_active' ) : '', 113 wpbc_nonce: nonceEl.value 114 } 115 } ); 116 117 $( '.booking_form_div' ).trigger( 'show_cost_hints', [ resourceId ] ); 118 $( '.booking_form_div' ).trigger( 'wpbc_booking_date_or_option_selected', [ resourceId ] ); 119 120 return false; 121 }; 122 } 123 124 if ( typeof w.wpbc_show_cost_hints_after_few_seconds !== 'function' ) { 125 w.wpbc_show_cost_hints_after_few_seconds = (function () { 126 var closedTimer = 0; 127 128 return function ( resourceId, timerDelay ) { 129 timerDelay = typeof timerDelay !== 'undefined' ? timerDelay : 250; 130 clearTimeout( closedTimer ); 131 closedTimer = setTimeout( w.wpbc_send_ajax__show_cost_hints.bind( null, resourceId ), timerDelay ); 132 }; 133 }()); 134 } 135 136 if ( typeof w.showCostHintInsideBkForm !== 'function' ) { 137 w.showCostHintInsideBkForm = function ( resourceId ) { 138 w.wpbc_show_cost_hints_after_few_seconds( resourceId ); 139 }; 140 } 141 142 $( function () {
143 $( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loadedResourceId ) { 144 w.wpbc_show_cost_hints_after_few_seconds( loadedResourceId ); 145 } ); 146 147 $( '.booking_form_div' ).on( 'date_selected', function ( event, resourceId ) { 148 w.wpbc_show_cost_hints_after_few_seconds( resourceId ); 149 } ); 150 151 $( document ).on( 'change', '.booking_form_div input, .booking_form_div select, .booking_form_div textarea', function () { 152 var form = $( this ).closest( 'form.booking_form' ), 153 resourceId; 154 155 if ( ! form.length || /^date_booking/.test( this.name || '' ) ) { 156 return; 157 } 158 159 resourceId = parseInt( form.attr( 'id' ).replace( 'booking_form', '' ), 10 ); 160 if ( resourceId > 0 ) { 161 w.wpbc_show_cost_hints_after_few_seconds( resourceId ); 162 } 163 } ); 164 } ); 165 166 function wpbc_free_date_hints__get_form_fields_as_string( resourceId ) { 167 var form = document.getElementById( 'booking_form' + resourceId ), 168 formData = '', 169 count, 170 i, 171 element, 172 elementType, 173 inputValue; 174 175 if ( ! form || ! form.elements ) { 176 return ''; 177 } 178 179 count = form.elements.length; 180 for ( i = 0; i < count; i++ ) { 181 element = form.elements[ i ]; 182 183 if ( ! element || ! element.name ) { 184 continue; 185 } 186 187 if ( 188 'button' === element.type || 189 'hidden' === element.type || 190 element.name === ( 'date_booking' + resourceId ) || 191 element.name === ( 'captcha_input' + resourceId ) 192 ) { 193 continue; 194 } 195 196 elementType = element.type; 197 198 if ( 'checkbox' === element.type ) { 199 inputValue = element.checked ? element.value : ''; 200 } else if ( 'radio' === element.type ) { 201 if ( ! element.checked ) { 202 continue; 203 } 204 inputValue = element.value; 205 } else { 206 inputValue = $( element ).val(); 207 } 208 209 if ( 'selectbox-multiple' === element.type || 'select-multiple' === element.type ) { 210 inputValue = $( '[name="' + element.name + '"]' ).val(); 211 if ( inputValue === null || inputValue.toString() === '' ) { 212 inputValue = ''; 213 } 214 } 215 216 elementType = ( element.className.indexOf( 'wpdev-validates-as-email' ) !== -1 ) ? 'email' : elementType; 217 elementType = ( element.className.indexOf( 'wpdev-validates-as-coupon' ) !== -1 ) ? 'coupon' : elementType; 218 elementType = ( 'select-one' === elementType ) ? 'selectbox-one' : elementType; 219 elementType = ( 'select-multiple' === elementType ) ? 'selectbox-multiple' : elementType; 220 221 if ( formData !== '' ) { 222 formData += '~'; 223 } 224 formData += elementType + '^' + element.name + '^' + inputValue; 225 } 226 227 return formData; 228 } 229}( window, jQuery ));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.