PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 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 All 205 releases
← All changes | includes/page-settings-themes/_src/settings_themes_page.js +141 -12 11.4.3 → 11.9 View file →
@@ -4,8 +4,14 @@
4 4 ( function ( $, w ) {
5 5 'use strict';
6 6
7 7 var cfg = w.wpbc_settings_themes_page || {};
8 + var localized_default_form_accent_color = String( cfg.form_accent_defaults && cfg.form_accent_defaults.booking_form_accent_color || '' ).trim();
9 +
10 + /** @type {string} Default accent supplied by the PHP configuration constant. */
11 + var default_form_accent_color = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test( localized_default_form_accent_color )
12 + ? localized_default_form_accent_color
13 + : '';
8 14 var preview_ajax = null;
9 15 var preview_timer = 0;
10 16 var preview_notice_timer = 0;
11 17 var preview_notice_message_timer = 0;
@@ -100,11 +106,12 @@
100 106 data[ item.name ] = item.value;
101 107 } );
102 108
103 109 data.booking_timeslot_picker = $form.find( '[name="booking_timeslot_picker"]' ).prop( 'checked' ) ? 'On' : 'Off';
110 + data.booking_form_accent_enabled = $form.find( '[name="booking_form_accent_enabled"]' ).prop( 'checked' ) ? 'On' : 'Off';
104 111 data.resource_id = $( '#wpbc_theme_resource_id' ).val() || '';
105 112 data.months_count = $( '#wpbc_theme_months_count' ).val() || '';
106 - data.preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar';
113 + data.preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form';
107 114 data.custom_booking_form = $( '#wpbc_theme_custom_form' ).val() || 'standard';
108 115
109 116 return data;
110 117 }
@@ -255,9 +262,9 @@
255 262 }
256 263
257 264 function sanitize_theme_length( value, fallback ) {
258 265 var v = String( value || '' ).trim();
259 - return /^-?\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( v ) ? v : fallback;
266 + return /^\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( v ) ? v : fallback;
260 267 }
261 268
262 269 function sanitize_theme_spacing( value, fallback ) {
263 270 var v = String( value || '' ).trim().replace( /\s+/g, ' ' );
@@ -267,9 +274,9 @@
267 274 if ( parts.length < 1 || parts.length > 4 ) {
268 275 return fallback;
269 276 }
270 277 for ( i = 0; i < parts.length; i++ ) {
271 - if ( ! /^-?\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( parts[i] ) ) {
278 + if ( ! /^\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( parts[i] ) ) {
272 279 return fallback;
273 280 }
274 281 }
275 282 return parts.join( ' ' );
@@ -274,8 +281,106 @@
274 281 }
275 282 return parts.join( ' ' );
276 283 }
277 284
285 + function mix_theme_colors( color, target, amount ) {
286 + var source = sanitize_theme_color( color, default_form_accent_color ).replace( '#', '' );
287 + var destination = sanitize_theme_color( target, '#000000' ).replace( '#', '' );
288 + var channels = [];
289 + var index;
290 +
291 + if ( 3 === source.length ) {
292 + source = source.replace( /./g, function ( value ) { return value + value; } );
293 + }
294 + for ( index = 0; index < 3; index++ ) {
295 + channels.push( Math.round( parseInt( source.substr( index * 2, 2 ), 16 ) + ( ( parseInt( destination.substr( index * 2, 2 ), 16 ) - parseInt( source.substr( index * 2, 2 ), 16 ) ) * amount ) ) );
296 + }
297 +
298 + return '#' + channels.map( function ( channel ) { return ( '0' + channel.toString( 16 ) ).slice( -2 ); } ).join( '' );
299 + }
300 +
301 + function get_theme_color_luminance( color ) {
302 + var hex = sanitize_theme_color( color, default_form_accent_color ).replace( '#', '' );
303 + var channels;
304 + if ( 3 === hex.length ) {
305 + hex = hex.replace( /./g, function ( value ) { return value + value; } );
306 + }
307 + channels = [ 0, 1, 2 ].map( function ( index ) {
308 + var channel = parseInt( hex.substr( index * 2, 2 ), 16 ) / 255;
309 + return channel <= 0.03928 ? channel / 12.92 : Math.pow( ( channel + 0.055 ) / 1.055, 2.4 );
310 + } );
311 + return ( 0.2126 * channels[0] ) + ( 0.7152 * channels[1] ) + ( 0.0722 * channels[2] );
312 + }
313 +
314 + /**
315 + * Apply the accent to preview variables while respecting Custom button controls.
316 + *
317 + * @param {Object} css_vars Resolved preview variables.
318 + * @param {boolean} preserve_custom_button_colors Whether Custom button variables remain authoritative.
319 + * @return {Object} Preview variables with the optional accent overlay.
320 + */
321 + function apply_form_accent_css_vars( css_vars, preserve_custom_button_colors ) {
322 + var enabled = get_form().find( '[name="booking_form_accent_enabled"]' ).prop( 'checked' );
323 + var accent_raw = String( get_form().find( '[name="booking_form_accent_color"]' ).val() || '' ).trim();
324 + var accent = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test( accent_raw ) ? accent_raw : default_form_accent_color;
325 + var luminance;
326 + var hover;
327 + var contrast;
328 + var hover_contrast;
329 +
330 + if ( ! enabled ) {
331 + return css_vars;
332 + }
333 + if ( ! /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test( accent ) ) {
334 + return css_vars;
335 + }
336 + luminance = get_theme_color_luminance( accent );
337 + contrast = luminance > 0.18 ? '#000000' : '#ffffff';
338 + hover = mix_theme_colors( accent, '#ffffff' === contrast ? '#000000' : '#ffffff', 0.10 );
339 + hover_contrast = contrast;
340 +
341 + var accent_overlay = {
342 + '--wpbc_form-accent-color': accent,
343 + '--wpbc_form-accent-hover-color': hover,
344 + '--wpbc_form-accent-contrast-color': contrast,
345 + '--wpbc_form-field-focus-border-color': accent,
346 + '--wpbc_form-field-focus-shadow-color': accent,
347 + '--wpbc_form-choice-checked-border-color': accent,
348 + '--wpbc_form-choice-checked-color': accent,
349 + '--wpbc_form-choice-focus-color': accent,
350 + '--wpbc_form-button-background-color': accent,
351 + '--wpbc_form-button-background-color-alt': accent,
352 + '--wpbc_form-button-border-color': accent,
353 + '--wpbc_form-button-text-color': contrast,
354 + '--wpbc_form-button-text-color-alt': contrast,
355 + '--wpbc_form-button-hover-background-color': hover,
356 + '--wpbc_form-button-hover-border-color': hover,
357 + '--wpbc_form-button-hover-text-color': hover_contrast,
358 + '--wpbc_form-button-light-hover-border-color': accent,
359 + '--wpbc_form-button-primary-hover-border-color': hover,
360 + '--wpbc_form-page-break-color': accent
361 + };
362 +
363 + if ( preserve_custom_button_colors ) {
364 + [
365 + '--wpbc_form-button-background-color',
366 + '--wpbc_form-button-background-color-alt',
367 + '--wpbc_form-button-border-color',
368 + '--wpbc_form-button-text-color',
369 + '--wpbc_form-button-text-color-alt',
370 + '--wpbc_form-button-hover-background-color',
371 + '--wpbc_form-button-hover-border-color',
372 + '--wpbc_form-button-hover-text-color',
373 + '--wpbc_form-button-light-hover-border-color',
374 + '--wpbc_form-button-primary-hover-border-color'
375 + ].forEach( function ( css_var_name ) {
376 + delete accent_overlay[ css_var_name ];
377 + } );
378 + }
379 +
380 + return $.extend( {}, css_vars, accent_overlay );
381 + }
382 +
278 383 function get_form_style_presets() {
279 384 return cfg.form_style_presets && 'object' === typeof cfg.form_style_presets ? cfg.form_style_presets : {};
280 385 }
281 386
@@ -306,9 +411,11 @@
306 411 booking_form_custom_secondary_button_text_color: '#444444',
307 412 booking_form_custom_secondary_button_border_color: '#eeeeee',
308 413 booking_form_custom_secondary_button_hover_background_color: '#fdfdfd',
309 414 booking_form_custom_secondary_button_hover_text_color: '#444444',
310 - booking_form_custom_secondary_button_hover_border_color: '#4d91cd'
415 + booking_form_custom_secondary_button_hover_border_color: '#4d91cd',
416 + booking_form_custom_button_border_width: '1px',
417 + booking_form_custom_button_border_radius: '3px'
311 418 }, cfg.custom_form_style_defaults && 'object' === typeof cfg.custom_form_style_defaults ? cfg.custom_form_style_defaults : {} );
312 419 }
313 420
314 421 function get_custom_form_style_css_vars() {
@@ -332,8 +439,11 @@
332 439 '--wpbc_form-field-border-color-spare': sanitize_theme_color( values.booking_form_custom_field_border_color, defaults.booking_form_custom_field_border_color ),
333 440 '--wpbc_form-field-focus-border-color': '#066aab',
334 441 '--wpbc_form-field-focus-shadow-color': '#066aab',
335 442 '--wpbc_form-field-disabled-color' : 'rgba(0, 0, 0, 0.2)',
443 + '--wpbc_form-button-border-radius' : sanitize_theme_length( values.booking_form_custom_button_border_radius, defaults.booking_form_custom_button_border_radius ),
444 + '--wpbc_form-button-border-style' : 'solid',
445 + '--wpbc_form-button-border-size' : sanitize_theme_length( values.booking_form_custom_button_border_width, defaults.booking_form_custom_button_border_width ),
336 446 '--wpbc_form-button-background-color' : sanitize_theme_color( values.booking_form_custom_button_background_color, defaults.booking_form_custom_button_background_color ),
337 447 '--wpbc_form-button-background-color-alt': sanitize_theme_color( values.booking_form_custom_button_background_color, defaults.booking_form_custom_button_background_color ),
338 448 '--wpbc_form-button-border-color' : sanitize_theme_color( values.booking_form_custom_button_border_color, defaults.booking_form_custom_button_border_color ),
339 449 '--wpbc_form-button-text-color' : sanitize_theme_color( values.booking_form_custom_button_text_color, defaults.booking_form_custom_button_text_color ),
@@ -345,8 +455,9 @@
345 455 '--wpbc_form-choice-checked-color' : '#066aab',
346 456 '--wpbc_form-choice-focus-color' : '#066aab',
347 457 '--wpbc_form-button-light-background-color': sanitize_theme_color( values.booking_form_custom_secondary_button_background_color, defaults.booking_form_custom_secondary_button_background_color ),
348 458 '--wpbc_form-button-light-border-color': sanitize_theme_color( values.booking_form_custom_secondary_button_border_color, defaults.booking_form_custom_secondary_button_border_color ),
459 + '--wpbc_form-button-light-border-size': sanitize_theme_length( values.booking_form_custom_button_border_width, defaults.booking_form_custom_button_border_width ),
349 460 '--wpbc_form-button-light-text-color' : sanitize_theme_color( values.booking_form_custom_secondary_button_text_color, defaults.booking_form_custom_secondary_button_text_color ),
350 461 '--wpbc_form-button-light-box-shadow' : '0 2px 10px 2px #ffffff54',
351 462 '--wpbc_form-button-light-hover-background-color': sanitize_theme_color( values.booking_form_custom_secondary_button_hover_background_color, defaults.booking_form_custom_secondary_button_hover_background_color ),
352 463 '--wpbc_form-button-light-hover-border-color': sanitize_theme_color( values.booking_form_custom_secondary_button_hover_border_color, defaults.booking_form_custom_secondary_button_hover_border_color ),
@@ -389,12 +500,12 @@
389 500 var presets = get_form_style_presets();
390 501 var preset = presets[ style ] || presets.light_bordered || {};
391 502
392 503 if ( 'custom' === style || preset.custom ) {
393 - return get_custom_form_style_css_vars();
504 + return apply_form_accent_css_vars( get_custom_form_style_css_vars(), true );
394 505 }
395 506
396 - return preset.css_vars && 'object' === typeof preset.css_vars ? preset.css_vars : {};
507 + return apply_form_accent_css_vars( preset.css_vars && 'object' === typeof preset.css_vars ? preset.css_vars : {} );
397 508 }
398 509
399 510 function apply_form_style_to_preview() {
400 511 var style = get_current_form_style();
@@ -538,9 +649,9 @@
538 649 }
539 650
540 651 function ensure_calendar_only_days_selection() {
541 652 var $preview = $( '[data-wpbc-theme-preview="1"]' ).first();
542 - var preview_mode = $preview.attr( 'data-preview-mode' ) || $( '#wpbc_theme_preview_mode' ).val() || 'calendar';
653 + var preview_mode = $preview.attr( 'data-preview-mode' ) || $( '#wpbc_theme_preview_mode' ).val() || 'form';
543 654 var resource_id = parseInt( $preview.attr( 'data-resource-id' ) || 0, 10 );
544 655 var expected = cfg.days_selection || {};
545 656 var expected_mode = String( expected.days_select_mode || 'multiple' );
546 657 var current_mode = null;
@@ -567,9 +678,9 @@
567 678 }
568 679
569 680 function apply_related_skins_for_theme( theme ) {
570 681 var calendar_skin = theme ? '/css/skins/24_9__dark_1.css' : '/css/skins/25_5__square_1.css';
571 - var time_skin = theme ? '/css/time_picker_skins/black.css' : '/css/time_picker_skins/light__24_8.css';
682 + var time_skin = '/css/time_picker_skins/form_style.css';
572 683
573 684 select_if_option_exists( $( '[data-wpbc-theme-calendar-skin="1"]' ), calendar_skin );
574 685 select_if_option_exists( $( '[data-wpbc-theme-time-skin="1"]' ), time_skin );
575 686 }
@@ -596,9 +707,9 @@
596 707 }
597 708
598 709 function maybe_show_preview_notice( $source ) {
599 710 var notice_type = $source.attr( 'data-wpbc-theme-preview-notice' ) || '';
600 - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar';
711 + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form';
601 712 var message = get_preview_notice_message( notice_type );
602 713 var $control = $( '.wpbc_theme_control_preview_mode' ).first();
603 714
604 715 if ( ! message ) {
@@ -618,9 +729,9 @@
618 729 show_highlighted_notice( message, 'warning', 9000, $control );
619 730 }
620 731
621 732 function show_calendar_only_theme_notice() {
622 - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar';
733 + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form';
623 734
624 735 if ( 'calendar' !== preview_mode ) {
625 736 return;
626 737 }
@@ -647,8 +758,12 @@
647 758 w.wpbc_hook__init_timeselector();
648 759 }
649 760 return;
650 761 }
762 + if ( typeof w.wpbc_hook__destroy_timeselector === 'function' ) {
763 + w.wpbc_hook__destroy_timeselector( $preview.get( 0 ) );
764 + return;
765 + }
651 766
652 767 $preview.find( '.wpbc_times_selector' ).remove();
653 768 $preview.find( time_selectors ).show();
654 769 }
@@ -653,9 +768,9 @@
653 768 $preview.find( time_selectors ).show();
654 769 }
655 770
656 771 function refresh_preview_mode_controls() {
657 - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar';
772 + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form';
658 773 $( '[data-wpbc-theme-form-control="1"]' ).toggleClass( 'is-visible', 'form' === preview_mode );
659 774 }
660 775
661 776 function set_calendar_loading( is_loading ) {
@@ -802,12 +917,18 @@
802 917 schedule_preview_refresh();
803 918 } );
804 919
805 920 $( document ).on( 'input change', '[data-wpbc-theme-appearance-control]', function () {
921 + // Coloris emits continuous input events. Accent and appearance values are
922 + // CSS-only, so update the existing preview without rebuilding it by AJAX.
806 923 apply_form_appearance();
807 - schedule_preview_refresh();
808 924 } );
809 925
926 + $( document ).on( 'change', '[data-wpbc-theme-accent-toggle="1"]', function () {
927 + $( '[data-wpbc-theme-accent-dependent="1"]' ).toggle( $( this ).prop( 'checked' ) );
928 + apply_form_appearance();
929 + } );
930 +
810 931 $( document ).on( 'change', '[data-wpbc-theme-calendar-skin="1"]', function () {
811 932 apply_calendar_skin();
812 933 } );
813 934
@@ -839,8 +960,16 @@
839 960 return;
840 961 }
841 962
842 963 bind_events();
964 + if ( w.Coloris ) {
965 + w.Coloris( {
966 + el: '.wpbc_theme_coloris',
967 + alpha: false,
968 + format: 'hex',
969 + themeMode: 'auto'
970 + } );
971 + }
843 972 refresh_preview_mode_controls();
844 973 apply_form_theme();
845 974 apply_form_appearance();
846 975 ensure_calendar_only_days_selection();