PluginProbe
Booking Calendar / 10.11
Booking Calendar v10.11
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 / core / any / js / admin-support.js

admin-support.js in Booking Calendar 10.11, at core/any/js/admin-support.js

819 lines 32.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * @version 1.0
3 * @package Support Functions
4 * @subpackage BackEnd Main Script Lib
5 * @category Scripts
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 *
11 * @modified 2015-04-09
12 */
13
14 function wpbc_parse_url_and_get_params_arr( url ) {
15
16 var url_parameters = url.split( '?' )[1];
17 var result_params_arr = {};
18 var url_parameters_arr = url_parameters.split( /\?|&/ );
19 var param_length = url_parameters_arr.length;
20 for ( var i = 0; i < param_length; i++ ) {
21 if ( ! url_parameters_arr[i] ) {
22 continue;
23 }
24 var ary = url_parameters_arr[i].split( '=' );
25 result_params_arr[ary[0]] = ary[1];
26 }
27 return result_params_arr;
28 }
29
30 function wpbc_ui_settings__menu__click( url, left_vert_nav_menu_a, section_id_to_show, text_for_path ){
31
32 var current_page_params = wpbc_parse_url_and_get_params_arr( window.location.href );
33 var destination_page_params = wpbc_parse_url_and_get_params_arr( url );
34
35 var is_this_same_page = 0;
36
37 if (current_page_params['page'] === destination_page_params['page']){
38 is_this_same_page++;
39 }
40 if (
41 ( (typeof( current_page_params['tab'] ) === 'undefined') && (typeof( destination_page_params['tab'] ) === 'undefined') ) ||
42 ( (current_page_params['tab'] === destination_page_params['tab']) )
43 ) {
44 is_this_same_page++;
45 }
46 if (
47 ( (typeof( current_page_params['subtab'] ) === 'undefined') && (typeof( destination_page_params['subtab'] ) === 'undefined') ) ||
48 ( (current_page_params['subtab'] === destination_page_params['subtab']) )
49 ) {
50 is_this_same_page++;
51 }
52
53 if ( 3 === is_this_same_page ) {
54 wpbc_ui_settings__panel__click( left_vert_nav_menu_a, section_id_to_show, text_for_path )
55 } else {
56 window.location.href = url;
57 }
58
59 }
60
61 function wpbc_ui_settings__panel__click( left_vert_nav_menu_a, section_id_to_show, text_for_path ){
62
63 // Update text in Top Menu.
64 jQuery( '.wpbc_settings_path_el_active' ).html(
65 '<a onclick="javascript:wpbc_ui_settings__panel__click( \'' + left_vert_nav_menu_a + '\', \'' + section_id_to_show + '\', \'' + text_for_path + '\' );" href="javascript:void(0);">' + text_for_path + '</a>'
66 );
67
68 // Show / Hide section and enable Left Vert Menu item
69 wpbc_navigation_click_show_section( left_vert_nav_menu_a, section_id_to_show , '.postbox' , false);
70
71 // wpbc_scroll_to( '.wpbc_settings_path_el_active' ); // Scroll to path.
72 // wpbc_scroll_to( '.wpbc_page_top__header_tabs' ); // Scroll to Top.
73 wpbc_scroll_to( '.wpbc_settings_page_header_title' ); // Scroll to Top.
74
75 }
76
77
78 /**
79 * When click on Navigation Column menu
80 */
81 function wpbc_navigation_click_show_section( _this, section_id_to_show ){
82 var container_to_hide_class = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.postbox';
83 var is_scroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
84
85 // -- Set Left Nav Active ------------------------------------------------------------------------------------------
86 jQuery( _this ).parents( '.wpbc_settings_flex_container' ).find( '.wpbc_settings_navigation_item_active' ).removeClass( 'wpbc_settings_navigation_item_active' );
87 jQuery( _this ).parents( '.wpbc_settings_navigation_item' ).addClass( 'wpbc_settings_navigation_item_active' );
88 // -- Hide all and show selected ----------------------------------------------------------------------------------
89 jQuery( _this ).parents( '.wpbc_settings_flex_container' ).find( container_to_hide_class ).hide();
90 jQuery( '.wpbc_container_always_hide__on_left_nav_click' ).hide();
91 jQuery( section_id_to_show ).show();
92
93 // -- Scroll -------------------------------------------------------------------------------------------------------
94 //jQuery( _this ).trigger( 'blur' );
95 if ( is_scroll ) {
96 var targetOffset = wpbc_scroll_to( section_id_to_show );
97 }
98
99 // -- Set Value to Input about selected Nav element --------------------------------------------------------------- // FixIn: 9.8.6.1.
100 var section_id_tab = section_id_to_show.substring( 0, section_id_to_show.length - 8 ) + '_tab';
101 if ( container_to_hide_class == section_id_to_show ){
102 section_id_tab = '#wpbc_general_settings_all_tab'
103 }
104 if ('#wpbc_general_settings_capacity_metabox,#wpbc_general_settings_capacity_upgrade_metabox'== section_id_to_show){
105 section_id_tab = '#wpbc_general_settings_capacity_tab'
106 }
107 jQuery( '#form_visible_section' ).val( section_id_tab );
108 }
109
110
111 /**
112 * Scroll to specific HTML element
113 *
114 * @param {type} object_name
115 * @returns {undefined}
116 */
117 function wpbc_scroll_to(object_name) {
118
119 if ( jQuery( object_name ).length > 0 ) {
120 var targetOffset = jQuery( object_name ).offset().top;
121 if ( targetOffset < 0 ) {
122 targetOffset = 0;
123 }
124 if ( jQuery( '#wpadminbar' ).length > 0 ) {
125 targetOffset = targetOffset - 50 - 40;
126 } else {
127 targetOffset = targetOffset - 20;
128 }
129 jQuery( 'html,body' ).animate( { scrollTop: targetOffset }, 500 );
130 return targetOffset;
131 }
132 return 0;
133 }
134
135 /**
136 * Auto scroll to unchor after page loaded.
137 */
138 jQuery( document ).ready(
139 function () {
140 setTimeout(
141 function () {
142 // window.location.hash = #section_id / doc: https://developer.mozilla.org/en-US/docs/Web/API/Location .
143 wpbc_scroll_to( window.location.hash );
144 },
145 100
146 );
147 }
148 );
149
150 function wpbc_animate_border( element, time, colors, x ) {
151
152 if ( x >= colors.length ) {
153 x = 0;
154 } else {
155 x++;
156 var color;
157 if ( colors[ x ] === '' ) {
158 color = '';
159 } else {
160 color = '#' + colors[ x ];
161 }
162 element.css( 'border-color', color );
163 element.css( 'color', color );
164 setTimeout( function () {
165 wpbc_animate_border( element, time, colors, x );
166 }, time );
167 }
168 }
169
170 function wpbc_field_highlight( object_name ) {
171
172 if ( jQuery( object_name ).length > 0 ) {
173
174 wpbc_scroll_to( object_name );
175
176 wpbc_animate_border(
177 jQuery( object_name ) // Element
178 , 200 // Time in ms
179 , ['d63637', '', 'd63637', '', 'd63637', '', 'd63637', '', 'd63637', '', 'd63637', ''] // Colors Array
180 , 0
181 );
182 }
183 }
184
185 /**
186 * Show Yes/No dialog
187 *
188 * @param {type} message_question
189 * @returns {Boolean}
190 */
191 function wpbc_are_you_sure( message_question ){
192 var answer = confirm( message_question );
193 if ( answer) { return true; }
194 else { return false;}
195 }
196
197 function wpbc_admin_show_message_processing( message_type ){
198
199 var message = '' ;
200
201 if ( message_type == 'saving' )
202 message += _wpbc.get_message( 'message_saving' );
203 else if ( message_type == 'updating' )
204 message += _wpbc.get_message( 'message_updating' );
205 else if ( message_type == 'deleting' )
206 message += _wpbc.get_message( 'message_deleting' );
207 else
208 message += _wpbc.get_message( 'message_processing' );
209
210 if ( message == 'undefined' )
211 message = 'Processing'
212
213 message = ' <span class="wpdevelop"><span class="wpbc_icn_rotate_right wpbc_spin wpbc_ajax_icon wpbc_processing wpbc_icn_autorenew" aria-hidden="true"></span></span> ' + message + '...';
214
215 wpbc_admin_show_message( message, 'info', 10000 );
216 }
217
218 /**
219 * Show Alert Messages
220 *
221 * @param {string} message
222 * @param {string} m_type - notice (default) | error | warning | info | success
223 * @param {tyintpe} m_delay - microseconds
224 * @param {bool} is_append (default true) - append notice instead of replacing
225 * @returns {undefined}
226 */
227 function wpbc_admin_show_message( message, m_type, m_delay, is_append ){ // FixIn: 7.2.1.16.
228
229 if ( is_append === undefined) { // FixIn: 8.0.1.100.
230 is_append = true;
231 }
232
233 var alert_class = 'notice '; //'alert ';
234 if (m_type == 'error'){
235 alert_class += 'notice-error ';
236 message = '<i style="margin-right: 0.5em;color: #d63638;" class="menu_icon icon-1x wpbc_icn_report_gmailerrorred"></i>' + message;
237 } //'alert-danger ';
238 if (m_type == 'warning'){
239 alert_class += 'notice-warning ';
240 message = '<i style="margin-right: 0.5em;color: #e9aa04;" class="menu_icon icon-1x wpbc_icn_warning"></i>' + message;
241 };
242 if (m_type == 'info') alert_class += 'notice-info '; //'alert-info ';
243 if ( m_type == 'success' ){
244 alert_class += 'alert-success updated ';
245 message = '<i style="margin-right: 0.5em;color: #64aa45;" class="menu_icon icon-1x wpbc_icn_done_outline"></i>' + message;
246 }
247
248 // var ajx_working_content = '';
249 // if ( is_append )
250 // ajx_working_content = jQuery('#ajax_working').html();
251
252 var unique_div_id = new Date();
253 unique_div_id = 'wpbc_notice_' + unique_div_id.getTime();
254
255 if ( is_append ){
256
257 jQuery( '#ajax_working .wpbc_processing' ).parent().parent().parent().hide();
258
259 jQuery( '#ajax_working' ).append(
260 '<div id="' + unique_div_id + '"><div id="wpbc_alert_message" class="wpbc_alert_message">' +
261 '<div class="wpbc_inner_message ' + alert_class + '"> ' +
262 '<a class="close" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">&times;</a> ' +
263 message +
264 '</div>' +
265 '</div></div>'
266 );
267 } else
268 jQuery('#ajax_working').html(
269 '<div id="' + unique_div_id + '"><div id="wpbc_alert_message" class="wpbc_alert_message">' +
270 '<div class="wpbc_inner_message '+alert_class+'"> ' +
271 '<a class="close" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">&times;</a> ' +
272 message +
273 '</div>' +
274 '</div></div>'
275 );
276 jQuery( '#' + unique_div_id ).animate( {opacity: 1}, m_delay ).fadeOut( 500 );
277 var closed_timer2 = setTimeout( function (){
278 jQuery( '#' + unique_div_id ).trigger( 'hide' );
279 }, ( parseInt( m_delay ) + 501 ) );
280 }
281
282 /**
283 * Start: Dropdown BS List elements -------------------------------------------------------------------------------- */
284
285 function wpbc_close_dropdown_selectbox( selector_id ) {
286 jQuery('#' + selector_id + '_container li input[type=checkbox],#' + selector_id + '_container li input[type=radio]').prop('checked', false);
287 jQuery('#' + selector_id + '_container').hide();
288 }
289
290 // Show Container depend from the selected option in dropdown list.
291 function wpbc_show_selected_in_dropdown( selector_id, title, value ){
292 jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
293 jQuery('#' + selector_id ).val( value );
294 jQuery('#' + selector_id ).trigger('change');
295 }
296
297 // Show Container depend from the selected Radio Option and Selectbox value in dropdown list.
298 // Exmaple: wpbc_show_selected_in_dropdown__radio_select_option( 'wh_booking_date', 'wh_booking_date2', 'wh_booking_datedays_interval_Radios' );.
299 function wpbc_show_selected_in_dropdown__radio_select_option( selector_id, selector_id2, radio_name ){
300
301 // Get selected value in radio buttons
302 var rad_val = jQuery('input:radio[name="' + radio_name + '"]:checked').val();
303
304 if ( rad_val != 'undefined' ) {
305
306 var select_box = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select');
307 // Selectbox exist
308 if ( select_box.length > 0 ) {
309 // Get label near selected radiobutton and selected Tilte in selectbox
310 var title = jQuery('input:radio[name="' + radio_name + '"]:checked').parent().find('label').html() + ' ' +
311 jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select option:selected').text();
312 // Get Value of selected option in selectbox
313 var value = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select option:selected').val();
314 // Set Title in dropdown list
315 jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
316 // Set value of radio button
317 jQuery('#' + selector_id ).val( rad_val );
318 // Set value of selectbox
319 jQuery('#' + selector_id2 ).val( value );
320 } else {
321 // 2 Text Fields
322 var text_box = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('input[type="text"]');
323 if ( text_box.length > 0 ) {
324 var text_divs = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('.dropdown-menu-text-element');
325
326 // Check if we have 2 DIV elements with text fields
327 if ( text_box.length > 0 ) {
328
329 var id_list = [ selector_id, selector_id2 ];
330 var title = '';
331 //Loop our text DIV elements
332 jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('.dropdown-menu-text-element').each(function( i ) {
333
334 if ( title != '' )
335 title += ' - ';
336 title += jQuery(this).find('input[type="text"]').val();
337 jQuery('#' + id_list[ i ] ).val( jQuery(this).find('input[type="text"]').val() );
338 });
339 // Set Title in dropdown list
340 jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
341
342 }
343 }
344 }
345 }
346
347 jQuery('#' + selector_id ).trigger( 'change' );
348
349 // Hide dropdown list
350 jQuery('#' + selector_id + '_container').hide();
351 }
352
353 /**
354 * End: Dropdown BS List elements -------------------------------------------------------------------------------- */
355
356
357 /**
358 * Ajax Request
359 *
360 * @param {type} us_id
361 * @param {type} window_id
362 * @returns {undefined}
363 */
364 function wpbc_verify_window_opening(us_id, window_id) {
365
366 var is_closed = 0;
367
368 if ( jQuery( '#' + window_id ).hasClass( 'closed' ) == true ) {
369 jQuery( '#' + window_id ).removeClass( 'closed' );
370 } else {
371 jQuery( '#' + window_id ).addClass( 'closed' );
372 is_closed = 1;
373 }
374
375 jQuery.ajax(
376 {
377 // Start Ajax Sending.
378 url : wpbc_url_ajax,
379 type : 'POST',
380 success: function (data, textStatus) {
381 if ( textStatus == 'success' ) jQuery( '#ajax_respond' ).html( data );
382 },
383 error : function (XMLHttpRequest, textStatus, errorThrown) {
384 window.status = 'Ajax sending Error status:' + textStatus;
385 alert( XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText );
386 if ( XMLHttpRequest.status == 500 ) {
387 alert( 'Error: 500' );
388 }
389 },
390 // beforeSend: someFunction,
391 data: {
392 action : 'USER_SAVE_WINDOW_STATE',
393 user_id : us_id,
394 window : window_id,
395 is_closed : is_closed,
396 wpbc_nonce: jQuery( '#wpbc_admin_panel_nonce' ).val()
397 }
398 }
399 );
400
401 }
402
403 /**
404 * Ajax Request - Saving Custom Data for User
405 *
406 * @param {int} us_id
407 * @param {string} data_name
408 * @param {string} data_value - serialized data
409 * @param {int} is_reload - { 0 | 1 } reload or not page
410 */
411 function wpbc_save_custom_user_data( us_id, data_name, data_value , is_reload ){
412
413 wpbc_admin_show_message_processing( 'saving' );
414
415 jQuery.ajax({ // Start Ajax Sending
416 url: wpbc_url_ajax,
417 type:'POST',
418 success: function (data, textStatus){if( textStatus == 'success') jQuery('#ajax_respond').html( data );},
419 error:function (XMLHttpRequest, textStatus, errorThrown){ window.status = 'Ajax sending Error status:'+ textStatus; alert(XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText); if ( XMLHttpRequest.status == 500 ) { alert('Error: 500'); } } ,
420 // beforeSend: someFunction,
421 data:{
422 action: 'USER_SAVE_CUSTOM_DATA',
423 user_id: us_id,
424 data_name: data_name,
425 data_value: decodeURIComponent( data_value ),
426 is_reload: is_reload,
427 wpbc_nonce: jQuery('#wpbc_admin_panel_nonce').val()
428 }
429 });
430 }
431
432 // Contact Form.
433 function wpbc_submit_client_form( submit_form, wpdev_active_locale ){
434
435 var count = submit_form.elements.length;
436 var formdata = '';
437 var inp_value;
438 var element;
439 var el_type;
440
441 for (var i=0; i<count; i++) {
442 element = submit_form.elements[i];
443
444 if ( (element.type !=='button') && (element.type !=='hidden') ) {
445
446 // Get Value of Element
447 if ( element.type == 'checkbox' ){
448
449 if ( element.value == '' ) {
450 inp_value = element.checked;
451 } else {
452 if ( element.checked )
453 inp_value = element.value;
454 else
455 inp_value = '';
456 }
457
458 } else if ( element.type == 'radio' ) {
459
460 if ( element.value == '' ) {
461 inp_value = element.checked;
462 } else {
463 if ( element.checked )
464 inp_value = element.value;
465 else
466 inp_value = '';
467 }
468 /*
469 if ( element.checked )
470 inp_value = element.value;
471 else
472 continue;
473 */
474
475 } else {
476 inp_value = element.value;
477 }
478
479 // Get value in selectbox of multiple selection
480 if ( (element.type == 'selectbox-multiple') || (element.type == 'select-multiple') ){
481 inp_value = jQuery('[name="'+element.name+'"]').val() ;
482 if ( ( inp_value == null ) || ( inp_value.toString() == '' ) )
483 inp_value='';
484 }
485
486 /*if ( element.name == ('phone') ) {
487 // we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number - See more at: http://www.w3resource.com/javascript/form/phone-no-validation.php#sthash.U9FHwcdW.dpuf
488 var reg = /^\d{10}$/;
489 var message_verif_phone = "Please enter correctly phone number";
490 if ( inp_value != '' )
491 if(reg.test(inp_value) == false) {wpbc_show_error_message( element , message_verif_phone);return;}
492 }*/
493
494
495 // Validation Check -- Requred fields
496 if ( element.className.indexOf( 'wpbc-validate-required' ) !== -1 ){
497
498 if ( ( element.type =='checkbox' ) && ( element.checked === false ) ) {
499 if ( ! jQuery(':checkbox[name="'+element.name+'"]', submit_form).is(":checked") ) {
500 wpbc_show_error_message( element , _wpbc.get_message( 'message_check_required_for_check_box' ) );
501 return;
502 }
503 }
504 if ( element.type =='radio' ) {
505 if ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) {
506 wpbc_show_error_message( element , _wpbc.get_message( 'message_check_required_for_radio_box' ) );
507 return;
508 }
509 }
510 if ( ( element.type !='checkbox' ) && ( element.type !='radio' ) && ( inp_value === '' ) ) {
511 wpbc_show_error_message( element , _wpbc.get_message( 'message_check_required' ) );
512 return;
513 }
514 }
515
516 // Validation Check --- Email correct filling field
517 if ( element.className.indexOf( 'wpbc-validate-email' ) !== -1 ){
518 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/;
519 if ( ( inp_value != '' ) && ( reg.test(inp_value) == false ) ) {
520 wpbc_show_error_message( element , _wpbc.get_message( 'message_check_email' ) );
521 return;
522 }
523 }
524
525 /*
526 // Validation Check --- Same Email Field
527 if ( ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) && ( element.className.indexOf('same_as_') !== -1 ) ) {
528
529 // Get the name of Primary Email field from the "same_as_NAME" class
530 var primary_email_name = element.className.match(/same_as_([^\s])+/gi);
531 if (primary_email_name != null) { // We found
532 primary_email_name = primary_email_name[0].substr(8);
533
534 // Recehck if such primary email field exist in the booking form
535 if (jQuery('[name="' + primary_email_name + '"]').length > 0) {
536
537 // Recheck the values of the both emails, if they do not equla show warning
538 if ( jQuery('[name="' + primary_email_name + '"]').val() !== inp_value ) {
539 wpbc_show_error_message( element , _wpbc.get_message( 'message_check_same_email' ) );return;
540 }
541 }
542 }
543 // Skip one loop for the email veryfication field
544 continue;
545 } */
546
547 /*
548 // Get Form Data
549 if ( element.name !== ('captcha_input' ) ) {
550 if (formdata !=='') formdata += '~'; // next field element
551
552 el_type = element.type;
553 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email';
554 if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon';
555
556 inp_value = inp_value + '';
557 inp_value = inp_value.replace(new RegExp("\\^",'g'), '&#94;'); // replace registered characters
558 inp_value = inp_value.replace(new RegExp("~",'g'), '&#126;'); // replace registered characters
559
560 inp_value = inp_value.replace(/"/g, '&#34;'); // replace double quot
561 inp_value = inp_value.replace(/'/g, '&#39;'); // replace single quot
562
563 formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr
564 } */
565 }
566
567 } // End Fields Loop
568
569
570 submit_form.submit(); // Submit Form, if previously was no interuptions
571 }
572
573 /**
574 * Show message under specific element
575 *
576 * @param {type} element - jQuery definition of the element
577 * @param {type} errorMessage - String message
578 * @param {type} message_type "" | "alert-warning" | "alert-success" | "alert-info" | "alert-danger"
579 */
580 function wpbc_show_message_under_element( element , errorMessage , message_type) {
581
582 wpbc_scroll_to( element );
583
584 if ( jQuery( element ).attr('type') == "radio" ) {
585 jQuery( element ).parent().parent().parent()
586 .after('<span class="wpbc-near-field-message alert '+ message_type +'">'+ errorMessage +'</span>'); // Show message
587
588 } else if (jQuery( element ).attr('type') == "checkbox") {
589 jQuery( element ).parent()
590 .after('<span class="wpbc-near-field-message alert '+ message_type +'">'+ errorMessage +'</span>'); // Show message
591
592 } else {
593 jQuery( element )
594 .after('<span class="wpbc-near-field-message alert '+ message_type +'">'+ errorMessage +'</span>'); // Show message
595 }
596 jQuery(".widget_wpbc .wpbc-near-field-message")
597 .css( {'vertical-align': 'sub' } ) ;
598 jQuery(".wpbc-near-field-message")
599 .animate( {opacity: 1}, 10000 )
600 .fadeOut( 2000 );
601 }
602
603 // Show Error Message in Booking Form at Front End.
604 function wpbc_show_error_message( element , errorMessage) {
605
606 // Scroll to the element
607 wpbc_scroll_to( element );
608
609 jQuery("[name='"+ element.name +"']")
610 .fadeOut( 350 ).fadeIn( 300 )
611 .fadeOut( 350 ).fadeIn( 400 )
612 .fadeOut( 350 ).fadeIn( 300 )
613 .fadeOut( 350 ).fadeIn( 400 )
614 .animate( {opacity: 1}, 4000 )
615 ; // mark red border
616
617 if (jQuery("[name='"+ element.name +"']").attr('type') == "radio") {
618 jQuery("[name='"+ element.name +"']").parent().parent()//.parent()
619 .after('<span class="wpbc-near-field-message alert alert-warning">'+ errorMessage +'</span>'); // Show message
620
621 } else if (jQuery("[name='"+ element.name +"']").attr('type') == "checkbox") {
622 jQuery("[name='"+ element.name +"']").parent().parent()
623 .after('<span class="wpbc-near-field-message alert alert-warning">'+ errorMessage +'</span>'); // Show message
624
625 } else {
626 jQuery("[name='"+ element.name +"']")
627 .after('<span class="wpbc-near-field-message alert alert-warning">'+ errorMessage +'</span>'); // Show message
628 }
629 jQuery(".wpbc-near-field-message")
630 .css( {'padding' : '5px 5px 4px', 'margin' : '2px', 'vertical-align': 'top', 'line-height': '32px' } );
631
632 if ( element.type == 'checkbox' )
633 jQuery(".wpbc-near-field-message").css( { 'vertical-align': 'middle'} );
634
635 jQuery(".widget_wpbc .wpbc-near-field-message")
636 .css( {'vertical-align': 'sub' } ) ;
637 jQuery(".wpbc-near-field-message")
638 .animate( {opacity: 1}, 10000 )
639 .fadeOut( 2000 );
640 jQuery( element).trigger( 'focus' ); // FixIn: 8.7.11.12.
641 return;
642
643 }
644
645
646 /**
647 * Reload the page with new parameter value.
648 *
649 * @param {type} url - full URL of the page, can include or exclude that parameter
650 * @param {type} param - URL parameter name
651 * @param {type} value - URL parameter value
652 * @returns {undefined}
653 */
654 function wpbc_reload_page_with_paramater( url, param, value ) {
655 var hash = {};
656 var parser = document.createElement('a');
657
658 parser.href = url;
659
660 var parameters = parser.search.split(/\?|&/);
661
662 for(var i=0; i < parameters.length; i++) {
663 if(!parameters[i])
664 continue;
665
666 var ary = parameters[i].split('=');
667 hash[ary[0]] = ary[1];
668 }
669
670 hash[param] = value;
671
672 var list = [];
673 Object.keys(hash).forEach(function (key) {
674 list.push(key + '=' + hash[key]);
675 });
676
677 parser.search = '?' + list.join('&');
678 //return parser.href;
679 window.location.href = parser.href;
680 }
681
682 // Deprecated:.
683 jQuery( window ).on( "load", function (){ // FixIn: 8.7.9.7.
684
685 // Color Text picker ///////////////////////////////////////////////////////
686 if ( jQuery('.field-text-color').length > 0 ) {
687 jQuery('.field-text-color').iris( {
688 change: function(event, ui){
689 jQuery(this).css( { backgroundColor: ui.color.toString() } );
690 jQuery(this).closest('.fields-color-group').find('.fieldvalue').css( { color: ui.color.toString() } );
691 }
692 , hide: true
693 , border: true
694 , palettes: ['#333', '#555', '#777', '#aaa', '#fff']
695 } ).each( function() {
696 jQuery(this).css( { backgroundColor: jQuery(this).val() } );
697 })
698 .on( 'click', function(){ // FixIn: 8.7.11.12.
699 jQuery('.iris-picker').hide();
700 jQuery(this).closest('div').find('.iris-picker').show();
701 });
702 }
703 // Color Background picker /////////////////////////////////////////////////
704 if ( jQuery('.field-background-color').length > 0 ) {
705 jQuery('.field-background-color').iris( {
706 change: function(event, ui){
707 jQuery(this).css( { backgroundColor: ui.color.toString() } );
708 jQuery(this).closest('.fields-color-group').find('.fieldvalue').css( { backgroundColor: ui.color.toString() } );
709 }
710 , hide: true
711 , border: true
712 , palettes: [ '#FFEE99', '#459', '#78b', '#ab0', '#df5d5d', '#f0f']
713 } ).each( function() {
714 jQuery(this).css( { backgroundColor: jQuery(this).val() } );
715 })
716 .on( 'click', function(){ // FixIn: 8.7.11.12.
717 jQuery('.iris-picker').hide();
718 jQuery(this).closest('div').find('.iris-picker').show();
719 });
720 // FixIn: 8.7.11.12.
721 jQuery('.field-text-color, .field-background-color' ).on( 'click', function(event){
722 event.stopPropagation();
723 });
724 }
725
726 // -----------------------------------------------------------------------------------------------------------------
727 // General Color picker in settings table //////////////////////////////////
728 // -----------------------------------------------------------------------------------------------------------------
729 if ( jQuery('.wpbc_colorpick').length > 0 ) {
730 jQuery('.wpbc_colorpick').iris( {
731 change: function(event, ui){
732 jQuery(this).css( { backgroundColor: ui.color.toString() } );
733 }
734 , hide: true
735 , border: true
736 , palettes: ['#125', '#459', '#78b', '#ab0', '#de3', '#f0f']
737 } ).each( function() {
738 jQuery(this).css( { backgroundColor: jQuery(this).val() } );
739 })
740 .on( 'click', function(){ // FixIn: 8.7.11.12.
741 jQuery('.iris-picker').hide();
742 jQuery(this).closest('td').find('.iris-picker').show();
743 });
744
745 jQuery('body' ).on( 'click', function() {
746 jQuery('.iris-picker').hide();
747 });
748 // FixIn: 8.7.11.12.
749 jQuery('.wpbc_colorpick' ).on( 'click', function(event){
750 event.stopPropagation();
751 });
752 }
753 });
754
755 // -- Support Functions ------------------------------------------------------------------------------------------------
756
757 /**
758 * Reset of WP Editor or TextArea Content
759 * @param {string} editor_textarea_id - ID of element
760 * @param {string} editor_textarea_content - Content
761 */
762 function wpbc_reset_wp_editor_content( editor_textarea_id, editor_textarea_content ) {
763
764 // FixIn: 8.4.7.18.
765
766 if ( (typeof WPBC_CM !== 'undefined') && ( WPBC_CM.is_defined( '#' + editor_textarea_id ) ) ){
767
768 WPBC_CM.set_codemirror_value( '#' + editor_textarea_id , editor_textarea_content );
769 } else {
770
771 if( typeof tinymce != "undefined" ) {
772 var editor = tinymce.get( editor_textarea_id );
773 if( editor && editor instanceof tinymce.Editor ) {
774 editor.setContent( editor_textarea_content );
775 editor.save( { no_events: true } );
776 } else {
777 jQuery( '#' + editor_textarea_id ).val( editor_textarea_content );
778 }
779 } else {
780 jQuery( '#' + editor_textarea_id ).val( editor_textarea_content );
781 }
782 }
783 }
784
785 /**
786 * Dismiss window / panel in Welcome Page
787 *
788 * @param {type} us_id
789 * @param {type} window_id
790 * @returns {undefined}
791 */
792 function wpbc_dismiss_window(us_id, window_id ){
793
794 jQuery.ajax({ // Start Ajax Sending
795 url: wpbc_url_ajax,
796 type:'POST',
797 success: function (data, textStatus){if( textStatus == 'success') jQuery('#ajax_respond').html( data );},
798 error:function (XMLHttpRequest, textStatus, errorThrown){window.status = 'Ajax sending Error status:'+ textStatus;alert(XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText);if (XMLHttpRequest.status == 500) {alert('Please check at this page according this error:' + ' https://wpbookingcalendar.com/faq/#ajax-sending-error');}},
799 // beforeSend: someFunction,
800 data:{
801 //ajax_action : 'USER_SAVE_WINDOW_STATE',
802 action : 'USER_SAVE_WINDOW_STATE',
803 user_id: us_id ,
804 window: window_id,
805 is_closed: 1,
806 wpbc_nonce: document.getElementById('wpbc_admin_panel_dismiss_window_nonce').value
807 }
808 });
809 }
810
811 /**
812 * Hide HTML element with animation during 0.5 second
813 *
814 * @param window_id - HTML ID of element, such as 'wpbc_my_window' - without # symbol
815 */
816 function wpbc_hide_window(window_id) {
817 jQuery( '#' + window_id ).slideUp( 800 );
818 }
819