| 1 |
"use strict"; |
| 2 |
|
| 3 |
jQuery('body').on({ |
| 4 |
'touchmove': function(e) { |
| 5 |
|
| 6 |
jQuery( '.timespartly' ).each( function ( index ){ |
| 7 |
|
| 8 |
var td_el = jQuery( this ).get( 0 ); |
| 9 |
|
| 10 |
if ( (undefined != td_el._tippy) ){ |
| 11 |
|
| 12 |
var instance = td_el._tippy; |
| 13 |
instance.hide(); |
| 14 |
} |
| 15 |
} ); |
| 16 |
} |
| 17 |
}); |
| 18 |
|
| 19 |
/** |
| 20 |
* Request Object |
| 21 |
* Here we can define Search parameters and Update it later, when some parameter was changed |
| 22 |
* |
| 23 |
*/ |
| 24 |
var wpbc_ajx_booking_listing = (function ( obj, $) { |
| 25 |
|
| 26 |
// Secure parameters for Ajax ------------------------------------------------------------------------------------ |
| 27 |
var p_secure = obj.security_obj = obj.security_obj || { |
| 28 |
user_id: 0, |
| 29 |
nonce : '', |
| 30 |
locale : '' |
| 31 |
}; |
| 32 |
|
| 33 |
obj.set_secure_param = function ( param_key, param_val ) { |
| 34 |
p_secure[ param_key ] = param_val; |
| 35 |
}; |
| 36 |
|
| 37 |
obj.get_secure_param = function ( param_key ) { |
| 38 |
return p_secure[ param_key ]; |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
// Listing Search parameters ------------------------------------------------------------------------------------ |
| 43 |
var p_listing = obj.search_request_obj = obj.search_request_obj || { |
| 44 |
sort : "booking_id", |
| 45 |
sort_type : "DESC", |
| 46 |
page_num : 1, |
| 47 |
page_items_count: 10, |
| 48 |
create_date : "", |
| 49 |
keyword : "", |
| 50 |
source : "" |
| 51 |
}; |
| 52 |
|
| 53 |
obj.search_set_all_params = function ( request_param_obj ) { |
| 54 |
p_listing = request_param_obj; |
| 55 |
}; |
| 56 |
|
| 57 |
obj.search_get_all_params = function () { |
| 58 |
return p_listing; |
| 59 |
}; |
| 60 |
|
| 61 |
obj.search_get_param = function ( param_key ) { |
| 62 |
return p_listing[ param_key ]; |
| 63 |
}; |
| 64 |
|
| 65 |
obj.search_set_param = function ( param_key, param_val ) { |
| 66 |
// if ( Array.isArray( param_val ) ){ |
| 67 |
// param_val = JSON.stringify( param_val ); |
| 68 |
// } |
| 69 |
p_listing[ param_key ] = param_val; |
| 70 |
}; |
| 71 |
|
| 72 |
obj.search_set_params_arr = function( params_arr ){ |
| 73 |
_.each( params_arr, function ( p_val, p_key, p_data ){ // Define different Search parameters for request |
| 74 |
this.search_set_param( p_key, p_val ); |
| 75 |
} ); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
// Other parameters ------------------------------------------------------------------------------------ |
| 80 |
var p_other = obj.other_obj = obj.other_obj || { }; |
| 81 |
|
| 82 |
obj.set_other_param = function ( param_key, param_val ) { |
| 83 |
p_other[ param_key ] = param_val; |
| 84 |
}; |
| 85 |
|
| 86 |
obj.get_other_param = function ( param_key ) { |
| 87 |
return p_other[ param_key ]; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
return obj; |
| 92 |
}( wpbc_ajx_booking_listing || {}, jQuery )); |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* Ajax ------------------------------------------------------------------------------------------------------ */ |
| 97 |
|
| 98 |
/** |
| 99 |
* Send Ajax search request |
| 100 |
* for searching specific Keyword and other params |
| 101 |
*/ |
| 102 |
function wpbc_ajx_booking_ajax_search_request(){ |
| 103 |
|
| 104 |
console.groupCollapsed('AJX_BOOKING_LISTING'); console.log( ' == Before Ajax Send - search_get_all_params() == ' , wpbc_ajx_booking_listing.search_get_all_params() ); |
| 105 |
|
| 106 |
wpbc_booking_listing_reload_button__spin_start(); |
| 107 |
|
| 108 |
/* |
| 109 |
//FixIn: forVideo |
| 110 |
if ( ! is_this_action ){ |
| 111 |
//wpbc_ajx_booking__actual_listing__hide(); |
| 112 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( |
| 113 |
'<div style="width:100%;text-align: center;" id="wpbc_loading_section"><span class="wpbc_icn_autorenew wpbc_spin"></span></div>' |
| 114 |
+ jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html() |
| 115 |
); |
| 116 |
if ( 'function' === typeof (jQuery( '#wpbc_loading_section' ).wpbc_my_modal) ){ // FixIn: 9.0.1.5. |
| 117 |
jQuery( '#wpbc_loading_section' ).wpbc_my_modal( 'show' ); |
| 118 |
} else { |
| 119 |
alert( 'Warning! Booking Calendar. Its seems that you have deactivated loading of Bootstrap JS files at Booking Settings General page in Advanced section.' ) |
| 120 |
} |
| 121 |
} |
| 122 |
is_this_action = false; |
| 123 |
*/ |
| 124 |
// Start Ajax |
| 125 |
jQuery.post( wpbc_url_ajax, |
| 126 |
{ |
| 127 |
action : 'WPBC_AJX_BOOKING_LISTING', |
| 128 |
wpbc_ajx_user_id: wpbc_ajx_booking_listing.get_secure_param( 'user_id' ), |
| 129 |
nonce : wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 130 |
wpbc_ajx_locale : wpbc_ajx_booking_listing.get_secure_param( 'locale' ), |
| 131 |
|
| 132 |
search_params : wpbc_ajx_booking_listing.search_get_all_params() |
| 133 |
}, |
| 134 |
/** |
| 135 |
* S u c c e s s |
| 136 |
* |
| 137 |
* @param response_data - its object returned from Ajax - class-live-searcg.php |
| 138 |
* @param textStatus - 'success' |
| 139 |
* @param jqXHR - Object |
| 140 |
*/ |
| 141 |
function ( response_data, textStatus, jqXHR ) { |
| 142 |
//FixIn: forVideo |
| 143 |
//jQuery( '#wpbc_loading_section' ).wpbc_my_modal( 'hide' ); |
| 144 |
|
| 145 |
console.log( ' == Response WPBC_AJX_BOOKING_LISTING == ', response_data ); console.groupEnd(); |
| 146 |
// Probably Error |
| 147 |
if ( (typeof response_data !== 'object') || (response_data === null) ){ |
| 148 |
jQuery( '.wpbc_ajx_under_toolbar_row' ).hide(); // FixIn: 9.6.1.5. |
| 149 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( |
| 150 |
'<div class="wpbc-settings-notice notice-warning" style="text-align:left">' + |
| 151 |
response_data + |
| 152 |
'</div>' |
| 153 |
); |
| 154 |
return; |
| 155 |
} |
| 156 |
|
| 157 |
// Reload page, after filter toolbar was reseted |
| 158 |
if ( ( undefined != response_data[ 'ajx_cleaned_params' ]) |
| 159 |
&& ( 'reset_done' === response_data[ 'ajx_cleaned_params' ][ 'ui_reset' ]) |
| 160 |
){ |
| 161 |
window.location.href = response_data[ 'ajx_cleaned_params' ]['ui_reset_url']; |
| 162 |
// location.reload(); |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
// Show listing |
| 167 |
if ( response_data[ 'ajx_count' ] > 0 ){ |
| 168 |
|
| 169 |
wpbc_ajx_booking_show_listing( response_data[ 'ajx_items' ], response_data[ 'ajx_search_params' ], response_data[ 'ajx_booking_resources' ] ); |
| 170 |
|
| 171 |
wpbc_pagination_echo( |
| 172 |
wpbc_ajx_booking_listing.get_other_param( 'pagination_container' ), |
| 173 |
wpbc_ajx_booking_listing.get_other_param( 'pagination_container_header' ), |
| 174 |
wpbc_ajx_booking_listing.get_other_param( 'pagination_container_footer' ), |
| 175 |
{ |
| 176 |
'page_active': response_data[ 'ajx_search_params' ][ 'page_num' ], |
| 177 |
'pages_count': Math.ceil( response_data[ 'ajx_count' ] / response_data[ 'ajx_search_params' ][ 'page_items_count' ] ), |
| 178 |
|
| 179 |
'page_items_count': response_data[ 'ajx_search_params' ][ 'page_items_count' ], |
| 180 |
'sort_type' : response_data[ 'ajx_search_params' ][ 'sort_type' ], |
| 181 |
'total_count' : response_data[ 'ajx_count' ], |
| 182 |
} |
| 183 |
); |
| 184 |
wpbc_ajx_booking_define_ui_hooks(); // Redefine Hooks, because we show new DOM elements |
| 185 |
|
| 186 |
} else { |
| 187 |
|
| 188 |
wpbc_ajx_booking__actual_listing__hide(); |
| 189 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( |
| 190 |
'<div class="wpbc-settings-notice0 notice-warning0" style="text-align:center;font-size: 15px;margin: 2em 0;">' + |
| 191 |
'<p><strong>No results found for current filter options...</strong></p>' + |
| 192 |
'<p><strong><a href="javascript:void(0)" ' + |
| 193 |
' onclick="javascript:wpbc_ajx_booking_send_search_request_with_params( {' + |
| 194 |
' \'ui_reset\': \'make_reset\', ' + |
| 195 |
' \'page_num\': 1 ' + |
| 196 |
'} );">Reset filters</a> to show all bookings.</strong></p>' + |
| 197 |
'</div>' |
| 198 |
); |
| 199 |
} |
| 200 |
|
| 201 |
// Update new booking count |
| 202 |
if ( undefined !== response_data[ 'ajx_new_bookings_count' ] ){ |
| 203 |
var ajx_new_bookings_count = parseInt( response_data[ 'ajx_new_bookings_count' ] ) |
| 204 |
if (ajx_new_bookings_count>0){ |
| 205 |
jQuery( '.wpbc_badge_count' ).show(); |
| 206 |
} |
| 207 |
jQuery( '.bk-update-count' ).html( ajx_new_bookings_count ); |
| 208 |
} |
| 209 |
|
| 210 |
wpbc_booking_listing_reload_button__spin_pause(); |
| 211 |
|
| 212 |
jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page |
| 213 |
} |
| 214 |
).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } |
| 215 |
jQuery( '.wpbc_ajx_under_toolbar_row' ).hide(); // FixIn: 9.6.1.5. |
| 216 |
var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; |
| 217 |
if ( jqXHR.responseText ){ |
| 218 |
error_message += jqXHR.responseText; |
| 219 |
} |
| 220 |
error_message = error_message.replace( /\n/g, "<br />" ); |
| 221 |
|
| 222 |
wpbc_ajx_booking_show_message( error_message ); |
| 223 |
}) |
| 224 |
// .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) |
| 225 |
// .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) |
| 226 |
; // End Ajax |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
/** |
| 231 |
* Views ----------------------------------------------------------------------------------------------------- */ |
| 232 |
|
| 233 |
/** |
| 234 |
* Show Listing Table and define gMail checkbox hooks |
| 235 |
* |
| 236 |
* @param json_items_arr - JSON object with Items |
| 237 |
* @param json_search_params - JSON object with Search |
| 238 |
*/ |
| 239 |
function wpbc_ajx_booking_show_listing( json_items_arr, json_search_params, json_booking_resources ){ |
| 240 |
|
| 241 |
wpbc_ajx_define_templates__resource_manipulation( json_items_arr, json_search_params, json_booking_resources ); |
| 242 |
|
| 243 |
//console.log( 'json_items_arr' , json_items_arr, json_search_params ); |
| 244 |
jQuery( '.wpbc_ajx_under_toolbar_row' ).css( "display", "flex" ); // FixIn: 9.6.1.5. |
| 245 |
var list_header_tpl = wp.template( 'wpbc_ajx_booking_list_header' ); |
| 246 |
var list_footer_tpl = wp.template( 'wpbc_ajx_booking_list_footer' ); |
| 247 |
var list_row_tpl = wp.template( 'wpbc_ajx_booking_list_row' ); |
| 248 |
|
| 249 |
|
| 250 |
// Header. |
| 251 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( list_header_tpl() ); |
| 252 |
// Send to template all request params: jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( list_header_tpl(wpbc_ajx_booking_listing.search_get_all_params()) ); |
| 253 |
// Body. |
| 254 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).append( '<div class="wpbc_selectable_body"></div>' ); |
| 255 |
// Footer. |
| 256 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).append( list_footer_tpl() ); |
| 257 |
|
| 258 |
// R o w s |
| 259 |
console.groupCollapsed( 'LISTING_ROWS' ); // LISTING_ROWS |
| 260 |
_.each( json_items_arr, function ( p_val, p_key, p_data ){ |
| 261 |
if ( 'undefined' !== typeof json_search_params[ 'keyword' ] ){ // Parameter for marking keyword with different color in a list |
| 262 |
p_val[ '__search_request_keyword__' ] = json_search_params[ 'keyword' ]; |
| 263 |
} else { |
| 264 |
p_val[ '__search_request_keyword__' ] = ''; |
| 265 |
} |
| 266 |
p_val[ 'booking_resources' ] = json_booking_resources; |
| 267 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) + ' .wpbc_selectable_body' ).append( list_row_tpl( p_val ) ); |
| 268 |
} ); |
| 269 |
console.groupEnd(); // LISTING_ROWS |
| 270 |
|
| 271 |
wpbc_define_gmail_checkbox_selection( jQuery ); // Redefine Hooks for clicking at Checkboxes |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
/** |
| 276 |
* Define template for changing booking resources & update it each time, when listing updating, useful for showing actual booking resources. |
| 277 |
* |
| 278 |
* @param json_items_arr - JSON object with Items |
| 279 |
* @param json_search_params - JSON object with Search |
| 280 |
* @param json_booking_resources - JSON object with Resources |
| 281 |
*/ |
| 282 |
function wpbc_ajx_define_templates__resource_manipulation( json_items_arr, json_search_params, json_booking_resources ){ |
| 283 |
|
| 284 |
// ------------------------------------------------------------------------------------------------------------- |
| 285 |
// New. 2025-04-21. |
| 286 |
// ------------------------------------------------------------------------------------------------------------- |
| 287 |
// Change booking resource in Modal. |
| 288 |
var modal__change_booking_resource = wp.template( 'wpbc_ajx__modal__change_booking_resource' ); |
| 289 |
|
| 290 |
jQuery( '#section_in_in_modal__change_booking_resource' ).html( |
| 291 |
modal__change_booking_resource( { |
| 292 |
'ajx_search_params' : json_search_params, |
| 293 |
'ajx_booking_resources': json_booking_resources |
| 294 |
} ) |
| 295 |
); |
| 296 |
|
| 297 |
// Duplicate booking into another resource in Modal. New. 2025-04-21. |
| 298 |
var modal__duplicate_booking_to_other_resource = wp.template( 'wpbc_ajx__modal__duplicate_booking_to_other_resource' ); |
| 299 |
|
| 300 |
jQuery( '#section_in_in_modal__duplicate_booking_to_other_resource' ).html( |
| 301 |
modal__duplicate_booking_to_other_resource( { |
| 302 |
'ajx_search_params' : json_search_params, |
| 303 |
'ajx_booking_resources': json_booking_resources |
| 304 |
} ) |
| 305 |
); |
| 306 |
// ------------------------------------------------------------------------------------------------------------- |
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
/** |
| 312 |
* Show just message instead of listing and hide pagination |
| 313 |
*/ |
| 314 |
function wpbc_ajx_booking_show_message( message ){ |
| 315 |
|
| 316 |
wpbc_ajx_booking__actual_listing__hide(); |
| 317 |
|
| 318 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( |
| 319 |
'<div class="wpbc-settings-notice notice-warning" style="text-align:left">' + |
| 320 |
message + |
| 321 |
'</div>' |
| 322 |
); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
/** |
| 327 |
* H o o k s - its Action/Times when need to re-Render Views ----------------------------------------------- */ |
| 328 |
|
| 329 |
/** |
| 330 |
* Send Ajax Search Request after Updating search request parameters |
| 331 |
* |
| 332 |
* @param params_arr |
| 333 |
*/ |
| 334 |
function wpbc_ajx_booking_send_search_request_with_params ( params_arr ){ |
| 335 |
|
| 336 |
// Define different Search parameters for request |
| 337 |
_.each( params_arr, function ( p_val, p_key, p_data ) { |
| 338 |
//console.log( 'Request for: ', p_key, p_val ); |
| 339 |
wpbc_ajx_booking_listing.search_set_param( p_key, p_val ); |
| 340 |
}); |
| 341 |
|
| 342 |
// Send Ajax Request |
| 343 |
wpbc_ajx_booking_ajax_search_request(); |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Search request for "Page Number" |
| 348 |
* @param page_number int |
| 349 |
*/ |
| 350 |
function wpbc_ajx_booking_pagination_click( page_number ){ |
| 351 |
|
| 352 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 353 |
'page_num': page_number |
| 354 |
} ); |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
/** |
| 359 |
* Keyword Searching ----------------------------------------------------------------------------------------- */ |
| 360 |
|
| 361 |
/** |
| 362 |
* Search request for "Keyword", also set current page to 1 |
| 363 |
* |
| 364 |
* @param element_id - HTML ID of element, where was entered keyword |
| 365 |
*/ |
| 366 |
function wpbc_ajx_booking_send_search_request_for_keyword( element_id ) { |
| 367 |
|
| 368 |
// We need to Reset page_num to 1 with each new search, because we can be at page #4, but after new search we can have totally only 1 page |
| 369 |
wpbc_ajx_booking_send_search_request_with_params( { |
| 370 |
'keyword' : jQuery( element_id ).val(), |
| 371 |
'page_num': 1 |
| 372 |
} ); |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* Send search request after few seconds (usually after 1,5 sec) |
| 377 |
* Closure function. Its useful, for do not send too many Ajax requests, when someone make fast typing. |
| 378 |
*/ |
| 379 |
var wpbc_ajx_booking_searching_after_few_seconds = function (){ |
| 380 |
|
| 381 |
var closed_timer = 0; |
| 382 |
|
| 383 |
return function ( element_id, timer_delay ){ |
| 384 |
|
| 385 |
// Get default value of "timer_delay", if parameter was not passed into the function. |
| 386 |
timer_delay = typeof timer_delay !== 'undefined' ? timer_delay : 1500; |
| 387 |
|
| 388 |
clearTimeout( closed_timer ); // Clear previous timer |
| 389 |
|
| 390 |
// Start new Timer |
| 391 |
closed_timer = setTimeout( wpbc_ajx_booking_send_search_request_for_keyword.bind( null, element_id ), timer_delay ); |
| 392 |
} |
| 393 |
}(); |
| 394 |
|
| 395 |
|
| 396 |
/** |
| 397 |
* Define Dynamic Hooks (like pagination click, which renew each time with new listing showing) ------------- */ |
| 398 |
|
| 399 |
/** |
| 400 |
* Define HTML ui Hooks: on KeyUp | Change | -> Sort Order & Number Items / Page |
| 401 |
* We are hcnaged it each time, when showing new listing, because DOM elements chnaged |
| 402 |
*/ |
| 403 |
function wpbc_ajx_booking_define_ui_hooks() { |
| 404 |
|
| 405 |
if ( 'function' === typeof (wpbc_define_tippy_tooltips) ) { |
| 406 |
wpbc_define_tippy_tooltips( '.wpbc__list__table ' ); |
| 407 |
} |
| 408 |
|
| 409 |
wpbc_ajx_booking__ui_define__locale(); |
| 410 |
wpbc_ajx_booking__ui_define__remark(); |
| 411 |
|
| 412 |
wpbc_boo_listing__init_hook__sort_by(); |
| 413 |
|
| 414 |
// Items Per Page. |
| 415 |
jQuery( '.wpbc_items_per_page' ).on( |
| 416 |
'change', |
| 417 |
function (event) { |
| 418 |
wpbc_ajx_booking_send_search_request_with_params( |
| 419 |
{ |
| 420 |
'page_items_count': jQuery( this ).val(), |
| 421 |
'page_num' : 1 |
| 422 |
} |
| 423 |
); |
| 424 |
} |
| 425 |
); |
| 426 |
|
| 427 |
// Sorting. |
| 428 |
jQuery( '.wpbc_items_sort_type' ).on( |
| 429 |
'change', |
| 430 |
function (event) { |
| 431 |
wpbc_ajx_booking_send_search_request_with_params( { 'sort_type': jQuery( this ).val() } ); |
| 432 |
} |
| 433 |
); |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
/** |
| 438 |
* Show / Hide Listing --------------------------------------------------------------------------------------- */ |
| 439 |
|
| 440 |
/** |
| 441 |
* Show Listing Table - Sending Ajax Request - with parameters that we early defined in "wpbc_ajx_booking_listing" Obj. |
| 442 |
*/ |
| 443 |
function wpbc_ajx_booking__actual_listing__show(){ |
| 444 |
|
| 445 |
wpbc_ajx_booking_ajax_search_request(); // Send Ajax Request - with parameters that we early defined in "wpbc_ajx_booking_listing" Obj. |
| 446 |
} |
| 447 |
|
| 448 |
/** |
| 449 |
* Hide Listing Table ( and Pagination ) |
| 450 |
*/ |
| 451 |
function wpbc_ajx_booking__actual_listing__hide(){ |
| 452 |
jQuery( '.wpbc_ajx_under_toolbar_row' ).hide(); // FixIn: 9.6.1.5. |
| 453 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html( '' ); |
| 454 |
jQuery( wpbc_ajx_booking_listing.get_other_param( 'pagination_container' ) ).html( '' ); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
/** |
| 459 |
* Support functions for Content Template data --------------------------------------------------------------- */ |
| 460 |
|
| 461 |
/** |
| 462 |
* Highlight strings, |
| 463 |
* by inserting <span class="fieldvalue name fieldsearchvalue">...</span> html elements into the string. |
| 464 |
* @param {string} booking_details - Source string |
| 465 |
* @param {string} booking_keyword - Keyword to highlight |
| 466 |
* @returns {string} |
| 467 |
*/ |
| 468 |
function wpbc_get_highlighted_search_keyword( booking_details, booking_keyword ){ |
| 469 |
|
| 470 |
booking_keyword = booking_keyword.trim().toLowerCase(); |
| 471 |
if ( 0 == booking_keyword.length ){ |
| 472 |
return booking_details; |
| 473 |
} |
| 474 |
|
| 475 |
// Highlight substring withing HTML tags in "Content of booking fields data" -- e.g. starting from > and ending with < |
| 476 |
let keywordRegex = new RegExp( `fieldvalue[^<>]*>([^<]*${booking_keyword}[^<]*)`, 'gim' ); |
| 477 |
|
| 478 |
//let matches = [...booking_details.toLowerCase().matchAll( keywordRegex )]; |
| 479 |
let matches = booking_details.toLowerCase().matchAll( keywordRegex ); |
| 480 |
matches = Array.from( matches ); |
| 481 |
|
| 482 |
let strings_arr = []; |
| 483 |
let pos_previous = 0; |
| 484 |
let search_pos_start; |
| 485 |
let search_pos_end; |
| 486 |
|
| 487 |
for ( const match of matches ){ |
| 488 |
|
| 489 |
search_pos_start = match.index + match[ 0 ].toLowerCase().indexOf( '>', 0 ) + 1 ; |
| 490 |
|
| 491 |
strings_arr.push( booking_details.substr( pos_previous, (search_pos_start - pos_previous) ) ); |
| 492 |
|
| 493 |
search_pos_end = booking_details.toLowerCase().indexOf( '<', search_pos_start ); |
| 494 |
|
| 495 |
strings_arr.push( '<span class="fieldvalue name fieldsearchvalue">' + booking_details.substr( search_pos_start, (search_pos_end - search_pos_start) ) + '</span>' ); |
| 496 |
|
| 497 |
pos_previous = search_pos_end; |
| 498 |
} |
| 499 |
|
| 500 |
strings_arr.push( booking_details.substr( pos_previous, (booking_details.length - pos_previous) ) ); |
| 501 |
|
| 502 |
return strings_arr.join( '' ); |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Convert special HTML characters from: & -> & |
| 507 |
* |
| 508 |
* @param text |
| 509 |
* @returns {*} |
| 510 |
*/ |
| 511 |
function wpbc_decode_HTML_entities( text ){ |
| 512 |
var textArea = document.createElement( 'textarea' ); |
| 513 |
textArea.innerHTML = text; |
| 514 |
return textArea.value; |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Convert TO special HTML characters from: & -> & |
| 519 |
* |
| 520 |
* @param text |
| 521 |
* @returns {*} |
| 522 |
*/ |
| 523 |
function wpbc_encode_HTML_entities(text) { |
| 524 |
var textArea = document.createElement('textarea'); |
| 525 |
textArea.innerText = text; |
| 526 |
return textArea.innerHTML; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
/** |
| 531 |
* Support Functions - Spin Icon in Buttons ------------------------------------------------------------------ */ |
| 532 |
|
| 533 |
/** |
| 534 |
* Spin button in Filter toolbar - Start |
| 535 |
*/ |
| 536 |
function wpbc_booking_listing_reload_button__spin_start(){ |
| 537 |
jQuery( '#wpbc_booking_listing_reload_button .menu_icon.wpbc_spin').removeClass( 'wpbc_animation_pause' ); |
| 538 |
} |
| 539 |
|
| 540 |
/** |
| 541 |
* Spin button in Filter toolbar - Pause |
| 542 |
*/ |
| 543 |
function wpbc_booking_listing_reload_button__spin_pause(){ |
| 544 |
jQuery( '#wpbc_booking_listing_reload_button .menu_icon.wpbc_spin' ).addClass( 'wpbc_animation_pause' ); |
| 545 |
} |
| 546 |
|
| 547 |
/** |
| 548 |
* Spin button in Filter toolbar - is Spinning ? |
| 549 |
* |
| 550 |
* @returns {boolean} |
| 551 |
*/ |
| 552 |
function wpbc_booking_listing_reload_button__is_spin(){ |
| 553 |
if ( jQuery( '#wpbc_booking_listing_reload_button .menu_icon.wpbc_spin' ).hasClass( 'wpbc_animation_pause' ) ){ |
| 554 |
return true; |
| 555 |
} else { |
| 556 |
return false; |
| 557 |
} |
| 558 |
} |