PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / _toolbar_ui / _src / toolbar_ui.js

toolbar_ui.js in Booking Calendar 11.1, at includes/_toolbar_ui/_src/toolbar_ui.js

114 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3
4 /**
5 * Encode HTML text to safe HTML entities
6 *
7 * Replace all characters in the given range (unicode 00A0 - 9999, as well as ampersand, greater & less than)
8 * with their html entity equivalents, which is simply &#nnn; where nnn is the unicode value we get from charCodeAt
9 *
10 * @param rawStr
11 * @returns {*}
12 */
13 function wpbc_get_safe_html_text( rawStr ){
14
15 var encodedStr = rawStr.replace( /[\u00A0-\u9999<>\&]/g, function ( i ){
16 return '&#' + i.charCodeAt( 0 ) + ';';
17 } );
18
19 return encodedStr;
20 }
21
22
23 /**
24 * Change Value and Title of dropdown after clicking on Apply button
25 *
26 * @param params Example: { 'dropdown_id': 'wh_booking_date', 'dropdown_radio_name': 'ui_wh_booking_date_radio' }
27 */
28 function wpbc_ui_dropdown_apply_click( params ){
29
30 // Get input values of all elements in LI section, where RADIO was selected
31 var filter_ui_dates_arr = jQuery( 'input[name="' + params[ 'dropdown_radio_name' ] + '"]:checked' )
32 .parents( 'li' ).find( ':input' )
33 .map( function (){
34 return wpbc_get_safe_html_text( jQuery( this ).val() );
35 } ).get();
36
37 if ( 0 !== filter_ui_dates_arr.length ){ // Continue only if radio button was selected, and we are having value
38
39 // Get titles of all elements in LI section, where RADIO was selected
40 var filter_ui_titles_arr = jQuery( 'input[name="' + params[ 'dropdown_radio_name' ] + '"]:checked' )
41 .parents( 'li' ).find( ':input' )
42 .map( function (){
43 if ( 'text' == jQuery( this ).prop( 'type' ) ){
44 return jQuery( this ).val();
45 }
46 if ( ( 'selectbox-one' == jQuery( this ).prop( 'type' ) ) || ( 'select-one' == jQuery( this ).prop( 'type' ) ) ){
47 return jQuery( this ).find( ':selected' ).text();
48 }
49 if (
50 ( 'radio' == jQuery( this ).prop( 'type' ) )
51 || ( 'checkbox' == jQuery( this ).prop( 'type' ) )
52 ){
53 var input_selected = jQuery( this ).filter(':checked').next( '.wpbc_ui_control_label' ).html();
54 if ( undefined == input_selected ) {
55 input_selected = jQuery( this ).filter(':checked').prev( '.wpbc_ui_control_label' ).html();
56 }
57 return ( undefined !== input_selected ) ? input_selected : '';
58 }
59
60 return jQuery( this ).val();
61 } ).get();
62
63 // Update Value to dropdown input hidden elements. Such value stringify.
64 jQuery( '#' + params[ 'dropdown_id' ] ).val( JSON.stringify( filter_ui_dates_arr ) );
65
66 // Generate change action, for ability to send Ajax request
67 jQuery( '#' + params[ 'dropdown_id' ] ).trigger( 'change' );
68
69 // Get Label of selected Radio button
70 var filter_ui_dates_title = jQuery( 'input[name="' + params[ 'dropdown_radio_name' ] + '"]:checked' ).next( '.wpbc_ui_control_label' ).html() + ': ';
71
72 // Remove selected value of radio button from beginning, we will use Label title instead
73 filter_ui_titles_arr.shift();
74
75 // Update Title in dropdown
76 var encoded_html_text = wpbc_get_safe_html_text( filter_ui_dates_title + filter_ui_titles_arr.join( ' - ' ) );
77 jQuery( '#' + params[ 'dropdown_id' ] + '_selector .wpbc_selected_in_dropdown' ).html( encoded_html_text );
78 }
79
80 jQuery( '#' + params[ 'dropdown_id' ] + '_container' ).hide();
81 }
82
83
84 /**
85 * Close dropdown after clicking on Close button
86 *
87 * @param dropdown_id ID of dropdown
88 */
89 function wpbc_ui_dropdown_close_click( dropdown_id ){
90
91 jQuery( '#' + dropdown_id + '_container' ).hide();
92 }
93
94
95 /**
96 * Simple option click on dropdown
97 *
98 * @param params Example: { 'dropdown_id': 'wh_booking_date', 'is_this_simple_list': true, 'value': '5', '_this': this }
99 */
100 function wpbc_ui_dropdown_simple_click( params ){
101
102 jQuery( '#' + params[ 'dropdown_id' ] + '_selector .wpbc_selected_in_dropdown' ).html( jQuery( params[ '_this' ] ).html() );
103
104 jQuery( '#' + params[ 'dropdown_id' ] ).val( JSON.stringify( [params[ 'value' ]] ) );
105
106 jQuery( '#' + params[ 'dropdown_id' ] + '_container li input[type=checkbox],'
107 + '#' + params[ 'dropdown_id' ] + '_container li input[type=radio]' ).prop( 'checked', false );
108
109 jQuery( '#' + params[ 'dropdown_id' ] ).trigger( 'change' );
110
111 if ( ! params[ 'is_this_simple_list' ] ){
112 jQuery( '#' + params[ 'dropdown_id' ] + '_container' ).hide();
113 }
114 }