/**
* @version 1.0
* @package Support Functions
* @subpackage BackEnd Main Script Lib
* @category Scripts
* @author wpdevelop
*
* @web-site https://wpbookingcalendar.com/
* @email info@wpbookingcalendar.com
*
* @modified 2015-04-09
*/
function wpbc_ui_settings__panel__click( left_vert_nav_menu_a, section_id_to_show, text_for_path ){
// Update text in Top Menu
jQuery( '.wpbc_settings_path_el_active' ).html(
'' + text_for_path + ''
);
// Show / Hide section and enable Left Vert Menu item
wpbc_navigation_click_show_section( left_vert_nav_menu_a, section_id_to_show , '.postbox' , false);
//wpbc_scroll_to( '.wpbc_settings_path_el_active' ); // Scroll to path
wpbc_scroll_to( '.wpbc_page_top__header_tabs' ); // Scroll to Top
}
/**
* When click on Navigation Column menu
*/
function wpbc_navigation_click_show_section( _this, section_id_to_show ){
var container_to_hide_class = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.postbox';
var is_scroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
// -- Set Left Nav Active ------------------------------------------------------------------------------------------
jQuery( _this ).parents( '.wpbc_settings_flex_container' ).find( '.wpbc_settings_navigation_item_active' ).removeClass( 'wpbc_settings_navigation_item_active' );
jQuery( _this ).parents( '.wpbc_settings_navigation_item' ).addClass( 'wpbc_settings_navigation_item_active' );
// -- Hide all and show selected ----------------------------------------------------------------------------------
jQuery( _this ).parents( '.wpbc_settings_flex_container' ).find( container_to_hide_class ).hide();
jQuery( '.wpbc_container_always_hide__on_left_nav_click' ).hide();
jQuery( section_id_to_show ).show();
// -- Scroll -------------------------------------------------------------------------------------------------------
//jQuery( _this ).trigger( 'blur' );
if ( is_scroll ) {
var targetOffset = wpbc_scroll_to( section_id_to_show );
}
// -- Set Value to Input about selected Nav element --------------------------------------------------------------- // FixIn: 9.8.6.1.
var section_id_tab = section_id_to_show.substring( 0, section_id_to_show.length - 8 ) + '_tab';
if ( container_to_hide_class == section_id_to_show ){
section_id_tab = '#wpbc_general_settings_all_tab'
}
if ('#wpbc_general_settings_capacity_metabox,#wpbc_general_settings_capacity_upgrade_metabox'== section_id_to_show){
section_id_tab = '#wpbc_general_settings_capacity_tab'
}
jQuery( '#form_visible_section' ).val( section_id_tab );
}
/**
* Scroll to specific HTML element
*
* @param {type} object_name
* @returns {undefined}
*/
function wpbc_scroll_to( object_name ) {
if ( jQuery( object_name ).length > 0 ) {
var targetOffset = jQuery( object_name ).offset().top;
// targetOffset = targetOffset - 50;
if (targetOffset<0) targetOffset = 0;
if ( jQuery('#wpadminbar').length > 0 ) targetOffset = targetOffset - 50;
else targetOffset = targetOffset - 20;
jQuery('html,body').animate({scrollTop: targetOffset}, 500);
return targetOffset;
}
return 0;
}
jQuery( document ).ready(function(){
setTimeout(function() {
wpbc_scroll_to( window.location.hash );
}, 100)
});
function wpbc_animate_border( element, time, colors, x ) {
if ( x >= colors.length ) {
x = 0;
} else {
x++;
var color;
if ( colors[ x ] === '' ) {
color = '';
} else {
color = '#' + colors[ x ];
}
element.css( 'border-color', color );
element.css( 'color', color );
setTimeout( function () {
wpbc_animate_border( element, time, colors, x );
}, time );
}
}
function wpbc_field_highlight( object_name ) {
if ( jQuery( object_name ).length > 0 ) {
wpbc_scroll_to( object_name );
wpbc_animate_border(
jQuery( object_name ) // Element
, 200 // Time in ms
, ['d63637', '', 'd63637', '', 'd63637', '', 'd63637', '', 'd63637', '', 'd63637', ''] // Colors Array
, 0
);
}
}
/**
* Show Yes/No dialog
*
* @param {type} message_question
* @returns {Boolean}
*/
function wpbc_are_you_sure( message_question ){
var answer = confirm( message_question );
if ( answer) { return true; }
else { return false;}
}
function wpbc_admin_show_message_processing( message_type ){
var message = '' ;
if ( message_type == 'saving' )
message += _wpbc.get_message( 'message_saving' );
else if ( message_type == 'updating' )
message += _wpbc.get_message( 'message_updating' );
else if ( message_type == 'deleting' )
message += _wpbc.get_message( 'message_deleting' );
else
message += _wpbc.get_message( 'message_processing' );
if ( message == 'undefined' )
message = 'Processing'
message = ' ' + message + '...';
wpbc_admin_show_message( message, 'info', 10000 );
}
/**
* Show Alert Messages
*
* @param {string} message
* @param {string} m_type - notice (default) | error | warning | info | success
* @param {tyintpe} m_delay - microseconds
* @param {bool} is_append (default true) - append notice instead of replacing
* @returns {undefined}
*/
function wpbc_admin_show_message( message, m_type, m_delay, is_append ){ // FixIn: 7.2.1.16.
if ( is_append === undefined) { // FixIn: 8.0.1.100.
is_append = true;
}
var alert_class = 'notice '; //'alert ';
if (m_type == 'error'){
alert_class += 'notice-error ';
message = '' + message;
} //'alert-danger ';
if (m_type == 'warning'){
alert_class += 'notice-warning ';
message = '' + message;
};
if (m_type == 'info') alert_class += 'notice-info '; //'alert-info ';
if ( m_type == 'success' ){
alert_class += 'alert-success updated ';
message = '' + message;
}
// var ajx_working_content = '';
// if ( is_append )
// ajx_working_content = jQuery('#ajax_working').html();
var unique_div_id = new Date();
unique_div_id = 'wpbc_notice_' + unique_div_id.getTime();
if ( is_append ){
jQuery( '#ajax_working .wpbc_processing' ).parent().parent().parent().hide();
jQuery( '#ajax_working' ).append(
'
'
);
} else
jQuery('#ajax_working').html(
''
);
jQuery( '#' + unique_div_id ).animate( {opacity: 1}, m_delay ).fadeOut( 500 );
var closed_timer2 = setTimeout( function (){
jQuery( '#' + unique_div_id ).trigger( 'hide' );
}, ( parseInt( m_delay ) + 501 ) );
}
/**
* Start: Dropdown BS List elements -------------------------------------------------------------------------------- */
function wpbc_close_dropdown_selectbox( selector_id ) {
jQuery('#' + selector_id + '_container li input[type=checkbox],#' + selector_id + '_container li input[type=radio]').prop('checked', false);
jQuery('#' + selector_id + '_container').hide();
}
// Show Container depend from the selected option in dropdown list
function wpbc_show_selected_in_dropdown( selector_id, title, value ){
jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
jQuery('#' + selector_id ).val( value );
jQuery('#' + selector_id ).trigger('change');
}
// Show Container depend from the selected Radio Option and Selectbox value in dropdown list
// Exmaple: wpbc_show_selected_in_dropdown__radio_select_option( 'wh_booking_date', 'wh_booking_date2', 'wh_booking_datedays_interval_Radios' );
function wpbc_show_selected_in_dropdown__radio_select_option( selector_id, selector_id2, radio_name ){
// Get selected value in radio buttons
var rad_val = jQuery('input:radio[name="' + radio_name + '"]:checked').val();
if ( rad_val != 'undefined' ) {
var select_box = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select');
// Selectbox exist
if ( select_box.length > 0 ) {
// Get label near selected radiobutton and selected Tilte in selectbox
var title = jQuery('input:radio[name="' + radio_name + '"]:checked').parent().find('label').html() + ' ' +
jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select option:selected').text();
// Get Value of selected option in selectbox
var value = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.input-group').find('select option:selected').val();
// Set Title in dropdown list
jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
// Set value of radio button
jQuery('#' + selector_id ).val( rad_val );
// Set value of selectbox
jQuery('#' + selector_id2 ).val( value );
} else {
// 2 Text Fields
var text_box = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('input[type="text"]');
if ( text_box.length > 0 ) {
var text_divs = jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('.dropdown-menu-text-element');
// Check if we have 2 DIV elements with text fields
if ( text_box.length > 0 ) {
var id_list = [ selector_id, selector_id2 ];
var title = '';
//Loop our text DIV elements
jQuery('input:radio[name="' + radio_name + '"]:checked').parents('.text-group').find('.dropdown-menu-text-element').each(function( i ) {
if ( title != '' )
title += ' - ';
title += jQuery(this).find('input[type="text"]').val();
jQuery('#' + id_list[ i ] ).val( jQuery(this).find('input[type="text"]').val() );
});
// Set Title in dropdown list
jQuery('#' + selector_id + '_selector .wpbc_selected_in_dropdown').html( title );
}
}
}
}
jQuery('#' + selector_id ).trigger( 'change' );
// Hide dropdown list
jQuery('#' + selector_id + '_container').hide();
}
/**
* End: Dropdown BS List elements -------------------------------------------------------------------------------- */
// FixIn: 9.6.3.5.
/* Mark rows in listing as selected by adding specific CLASS*/
( function( $ ){
$( document ).ready(function(){
$('.wpbc-listing-row input[type="checkbox"]').on( 'change', function(){
$('.wpbc-listing-row').find('.check-column').find(':checkbox').each( function() {
if ( $(this).is(':checked') ) {
$(this).parent().parent().parent().parent().addClass('row_selected_color');
} else {
$(this).parent().parent().parent().parent().removeClass('row_selected_color');
}
});
} );
});
}( jQuery ) );
/**
* Ajax Request
*
* @param {type} us_id
* @param {type} window_id
* @returns {undefined}
*/
//
/**
* Ajax Request - Saving Custom Data for User
*
* @param {int} us_id
* @param {string} data_name
* @param {string} data_value - serialized data
* @param {int} is_reload - { 0 | 1 } reload or not page
*/
//
////////////////////////////////////////////////////////////////////////////////
// Contact Form
////////////////////////////////////////////////////////////////////////////////
function wpbc_submit_client_form( submit_form, wpdev_active_locale ){
var count = submit_form.elements.length;
var formdata = '';
var inp_value;
var element;
var el_type;
for (var i=0; i 0) {
// Recheck the values of the both emails, if they do not equla show warning
if ( jQuery('[name="' + primary_email_name + '"]').val() !== inp_value ) {
wpbc_show_error_message( element , _wpbc.get_message( 'message_check_same_email' ) );return;
}
}
}
// Skip one loop for the email veryfication field
continue;
} */
/*
// Get Form Data
if ( element.name !== ('captcha_input' ) ) {
if (formdata !=='') formdata += '~'; // next field element
el_type = element.type;
if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email';
if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon';
inp_value = inp_value + '';
inp_value = inp_value.replace(new RegExp("\\^",'g'), '^'); // replace registered characters
inp_value = inp_value.replace(new RegExp("~",'g'), '~'); // replace registered characters
inp_value = inp_value.replace(/"/g, '"'); // replace double quot
inp_value = inp_value.replace(/'/g, '''); // replace single quot
formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr
} */
}
} // End Fields Loop
submit_form.submit(); // Submit Form, if previously was no interuptions
}
/**
* Show message under specific element
*
* @param {type} element - jQuery definition of the element
* @param {type} errorMessage - String message
* @param {type} message_type "" | "alert-warning" | "alert-success" | "alert-info" | "alert-danger"
*/
function wpbc_show_message_under_element( element , errorMessage , message_type) {
wpbc_scroll_to( element );
if ( jQuery( element ).attr('type') == "radio" ) {
jQuery( element ).parent().parent().parent()
.after(''+ errorMessage +''); // Show message
} else if (jQuery( element ).attr('type') == "checkbox") {
jQuery( element ).parent()
.after(''+ errorMessage +''); // Show message
} else {
jQuery( element )
.after(''+ errorMessage +''); // Show message
}
jQuery(".widget_wpbc .wpbc-near-field-message")
.css( {'vertical-align': 'sub' } ) ;
jQuery(".wpbc-near-field-message")
.animate( {opacity: 1}, 10000 )
.fadeOut( 2000 );
}
// Show Error Message in Booking Form at Front End
function wpbc_show_error_message( element , errorMessage) {
// Scroll to the element
wpbc_scroll_to( element );
jQuery("[name='"+ element.name +"']")
.fadeOut( 350 ).fadeIn( 300 )
.fadeOut( 350 ).fadeIn( 400 )
.fadeOut( 350 ).fadeIn( 300 )
.fadeOut( 350 ).fadeIn( 400 )
.animate( {opacity: 1}, 4000 )
; // mark red border
if (jQuery("[name='"+ element.name +"']").attr('type') == "radio") {
jQuery("[name='"+ element.name +"']").parent().parent()//.parent()
.after(''+ errorMessage +''); // Show message
} else if (jQuery("[name='"+ element.name +"']").attr('type') == "checkbox") {
jQuery("[name='"+ element.name +"']").parent().parent()
.after(''+ errorMessage +''); // Show message
} else {
jQuery("[name='"+ element.name +"']")
.after(''+ errorMessage +''); // Show message
}
jQuery(".wpbc-near-field-message")
.css( {'padding' : '5px 5px 4px', 'margin' : '2px', 'vertical-align': 'top', 'line-height': '32px' } );
if ( element.type == 'checkbox' )
jQuery(".wpbc-near-field-message").css( { 'vertical-align': 'middle'} );
jQuery(".widget_wpbc .wpbc-near-field-message")
.css( {'vertical-align': 'sub' } ) ;
jQuery(".wpbc-near-field-message")
.animate( {opacity: 1}, 10000 )
.fadeOut( 2000 );
jQuery( element).trigger( 'focus' ); // FixIn: 8.7.11.12.
return;
}
/**
* Reload the page with new parameter value.
*
* @param {type} url - full URL of the page, can include or exclude that parameter
* @param {type} param - URL parameter name
* @param {type} value - URL parameter value
* @returns {undefined}
*/
function wpbc_reload_page_with_paramater( url, param, value ) {
var hash = {};
var parser = document.createElement('a');
parser.href = url;
var parameters = parser.search.split(/\?|&/);
for(var i=0; i < parameters.length; i++) {
if(!parameters[i])
continue;
var ary = parameters[i].split('=');
hash[ary[0]] = ary[1];
}
hash[param] = value;
var list = [];
Object.keys(hash).forEach(function (key) {
list.push(key + '=' + hash[key]);
});
parser.search = '?' + list.join('&');
//return parser.href;
window.location.href = parser.href;
}
// jQuery(window).load(function(){
jQuery( window ).on( "load", function (){ // FixIn: 8.7.9.7.
// Color Text picker ///////////////////////////////////////////////////////
if ( jQuery('.field-text-color').length > 0 ) {
jQuery('.field-text-color').iris( {
change: function(event, ui){
jQuery(this).css( { backgroundColor: ui.color.toString() } );
jQuery(this).closest('.fields-color-group').find('.fieldvalue').css( { color: ui.color.toString() } );
}
, hide: true
, border: true
, palettes: ['#333', '#555', '#777', '#aaa', '#fff']
} ).each( function() {
jQuery(this).css( { backgroundColor: jQuery(this).val() } );
})
.on( 'click', function(){ // FixIn: 8.7.11.12.
jQuery('.iris-picker').hide();
jQuery(this).closest('div').find('.iris-picker').show();
});
}
// Color Background picker /////////////////////////////////////////////////
if ( jQuery('.field-background-color').length > 0 ) {
jQuery('.field-background-color').iris( {
change: function(event, ui){
jQuery(this).css( { backgroundColor: ui.color.toString() } );
jQuery(this).closest('.fields-color-group').find('.fieldvalue').css( { backgroundColor: ui.color.toString() } );
}
, hide: true
, border: true
, palettes: [ '#FFEE99', '#459', '#78b', '#ab0', '#df5d5d', '#f0f']
} ).each( function() {
jQuery(this).css( { backgroundColor: jQuery(this).val() } );
})
.on( 'click', function(){ // FixIn: 8.7.11.12.
jQuery('.iris-picker').hide();
jQuery(this).closest('div').find('.iris-picker').show();
});
// FixIn: 8.7.11.12.
jQuery('.field-text-color, .field-background-color' ).on( 'click', function(event){
event.stopPropagation();
});
}
// -----------------------------------------------------------------------------------------------------------------
// General Color picker in settings table //////////////////////////////////
// -----------------------------------------------------------------------------------------------------------------
if ( jQuery('.wpbc_colorpick').length > 0 ) {
jQuery('.wpbc_colorpick').iris( {
change: function(event, ui){
jQuery(this).css( { backgroundColor: ui.color.toString() } );
}
, hide: true
, border: true
, palettes: ['#125', '#459', '#78b', '#ab0', '#de3', '#f0f']
} ).each( function() {
jQuery(this).css( { backgroundColor: jQuery(this).val() } );
})
.on( 'click', function(){ // FixIn: 8.7.11.12.
jQuery('.iris-picker').hide();
jQuery(this).closest('td').find('.iris-picker').show();
});
jQuery('body' ).on( 'click', function() {
jQuery('.iris-picker').hide();
});
// FixIn: 8.7.11.12.
jQuery('.wpbc_colorpick' ).on( 'click', function(event){
event.stopPropagation();
});
}
});
////////////////////////////////////////////////////////////////////////////
// Support Functions
////////////////////////////////////////////////////////////////////////////
/**
* Reset of WP Editor or TextArea Content
* @param {string} editor_textarea_id - ID of element
* @param {string} editor_textarea_content - Content
*/
function wpbc_reset_wp_editor_content( editor_textarea_id, editor_textarea_content ) {
// FixIn: 8.4.7.18.
if ( (typeof WPBC_CM !== 'undefined') && ( WPBC_CM.is_defined( '#' + editor_textarea_id ) ) ){
WPBC_CM.set_codemirror_value( '#' + editor_textarea_id , editor_textarea_content );
} else {
if( typeof tinymce != "undefined" ) {
var editor = tinymce.get( editor_textarea_id );
if( editor && editor instanceof tinymce.Editor ) {
editor.setContent( editor_textarea_content );
editor.save( { no_events: true } );
} else {
jQuery( '#' + editor_textarea_id ).val( editor_textarea_content );
}
} else {
jQuery( '#' + editor_textarea_id ).val( editor_textarea_content );
}
}
}
/**
* Dismiss window / panel in Welcome Page
*
* @param {type} us_id
* @param {type} window_id
* @returns {undefined}
*/
//
/**
* Hide HTML element with animation during 0.5 second
*
* @param window_id - HTML ID of element, such as 'wpbc_my_window' - without # symbol
*/
function wpbc_hide_window( window_id ){
jQuery( '#' + window_id ).slideUp( 800 );
}