← All changes
|
includes/page-settings-themes/_src/settings_themes_page.js
+486
-11
11.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; |
| @@ -90,34 +96,469 @@ | ||
| 90 | 96 | function collect_payload() { |
| 91 | 97 | var $form = get_form(); |
| 92 | 98 | var data = {}; |
| 93 | 99 | |
| 100 | + sync_form_style_choice(); | |
| 101 | + | |
| 94 | 102 | $.each( $form.serializeArray(), function ( index, item ) { |
| 103 | + if ( 0 === String( item.name || '' ).indexOf( 'wpbc_setup' ) ) { | |
| 104 | + return; | |
| 105 | + } | |
| 95 | 106 | data[ item.name ] = item.value; |
| 96 | 107 | } ); |
| 97 | 108 | |
| 98 | 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'; | |
| 99 | 111 | data.resource_id = $( '#wpbc_theme_resource_id' ).val() || ''; |
| 100 | 112 | data.months_count = $( '#wpbc_theme_months_count' ).val() || ''; |
| 101 | - data.preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar'; | |
| 113 | + data.preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form'; | |
| 102 | 114 | data.custom_booking_form = $( '#wpbc_theme_custom_form' ).val() || 'standard'; |
| 103 | 115 | |
| 104 | 116 | return data; |
| 105 | 117 | } |
| 106 | 118 | |
| 119 | + function map_form_style_choice( value ) { | |
| 120 | + var choice = String( value || 'light_bordered' ); | |
| 121 | + var current_theme = $( '#booking_form_theme' ).val() || ''; | |
| 122 | + var parts; | |
| 123 | + var preset; | |
| 124 | + | |
| 125 | + if ( 'custom' === choice ) { | |
| 126 | + return { | |
| 127 | + theme : current_theme, | |
| 128 | + preset: 'custom' | |
| 129 | + }; | |
| 130 | + } | |
| 131 | + | |
| 132 | + parts = choice.split( '_' ); | |
| 133 | + preset = parts[1] || 'bordered'; | |
| 134 | + if ( [ 'bordered', 'none', 'soft' ].indexOf( preset ) === -1 ) { | |
| 135 | + preset = 'bordered'; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return { | |
| 139 | + theme : ( 'dark' === parts[0] ) ? 'wpbc_theme_dark_1' : '', | |
| 140 | + preset: preset | |
| 141 | + }; | |
| 142 | + } | |
| 143 | + | |
| 144 | + function get_form_style_choice_from_values() { | |
| 145 | + var theme = $( '#booking_form_theme' ).val() || ''; | |
| 146 | + var preset = $( '#booking_form_appearance_preset' ).val() || 'bordered'; | |
| 147 | + var prefix = theme ? 'dark' : 'light'; | |
| 148 | + | |
| 149 | + if ( 'custom' === preset ) { | |
| 150 | + return 'custom'; | |
| 151 | + } | |
| 152 | + if ( [ 'bordered', 'none', 'soft' ].indexOf( preset ) === -1 ) { | |
| 153 | + preset = 'bordered'; | |
| 154 | + } | |
| 155 | + | |
| 156 | + return prefix + '_' + preset; | |
| 157 | + } | |
| 158 | + | |
| 159 | + function sync_form_style_choice() { | |
| 160 | + var $checked = get_form().find( '[name="booking_form_style"]:checked' ); | |
| 161 | + var mapped; | |
| 162 | + | |
| 163 | + if ( ! $checked.length ) { | |
| 164 | + return; | |
| 165 | + } | |
| 166 | + | |
| 167 | + mapped = map_form_style_choice( $checked.val() ); | |
| 168 | + $( '#booking_form_theme' ).val( mapped.theme ); | |
| 169 | + $( '#booking_form_appearance_preset' ).val( mapped.preset ); | |
| 170 | + } | |
| 171 | + | |
| 172 | + function sync_form_style_choice_selection() { | |
| 173 | + var choice = get_form_style_choice_from_values(); | |
| 174 | + var $choices = get_form().find( '[name="booking_form_style"]' ); | |
| 175 | + | |
| 176 | + $choices.prop( 'checked', false ); | |
| 177 | + $choices.filter( '[value="' + choice + '"]' ).prop( 'checked', true ); | |
| 178 | + | |
| 179 | + $( '.wpbc_theme_choice' ).removeClass( 'is-selected' ); | |
| 180 | + $choices.filter( ':checked' ).closest( '.wpbc_theme_choice' ).addClass( 'is-selected' ); | |
| 181 | + } | |
| 182 | + | |
| 107 | 183 | function apply_form_theme() { |
| 108 | - var theme = get_form().find( '[name="booking_form_theme"]:checked' ).val() || ''; | |
| 184 | + var theme = $( '#booking_form_theme' ).val() || ''; | |
| 109 | 185 | var $preview = $( '[data-wpbc-theme-preview="1"]' ); |
| 186 | + var $theme_targets = $preview.add( $preview.find( '.wpbc_container.wpbc_form, .wpbc_container_booking_form' ) ); | |
| 110 | 187 | |
| 111 | - $preview.removeClass( 'wpbc_theme_dark_1' ); | |
| 188 | + $theme_targets.each( function () { | |
| 189 | + var $target = $( this ); | |
| 190 | + var classes = String( this.className || '' ).split( /\s+/ ); | |
| 191 | + | |
| 192 | + $.each( classes, function ( index, class_name ) { | |
| 193 | + if ( /^wpbc_theme_/.test( class_name ) && ! /^wpbc_theme_preview/.test( class_name ) ) { | |
| 194 | + $target.removeClass( class_name ); | |
| 195 | + } | |
| 196 | + } ); | |
| 197 | + } ); | |
| 112 | 198 | if ( theme ) { |
| 113 | - $preview.addClass( theme ); | |
| 199 | + $theme_targets.addClass( theme ); | |
| 114 | 200 | } |
| 115 | 201 | |
| 116 | - $( '.wpbc_theme_choice' ).removeClass( 'is-selected' ); | |
| 117 | - get_form().find( '[name="booking_form_theme"]:checked' ).closest( '.wpbc_theme_choice' ).addClass( 'is-selected' ); | |
| 202 | + sync_form_style_choice_selection(); | |
| 118 | 203 | } |
| 119 | 204 | |
| 205 | + function get_form_appearance_presets() { | |
| 206 | + return { | |
| 207 | + bordered: { | |
| 208 | + background : '#ffffff', | |
| 209 | + borderColor: '#cccccc', | |
| 210 | + borderWidth: '1px', | |
| 211 | + radius : '2px', | |
| 212 | + padding : '10px 30px', | |
| 213 | + shadow : 'rgba(0, 0, 0, 0.05) 0px 2px 6px 0px' | |
| 214 | + }, | |
| 215 | + none : { | |
| 216 | + background : 'transparent', | |
| 217 | + borderColor: 'transparent', | |
| 218 | + borderWidth: '0px', | |
| 219 | + radius : '0px', | |
| 220 | + padding : '0px', | |
| 221 | + shadow : 'none' | |
| 222 | + }, | |
| 223 | + soft : { | |
| 224 | + background : '#f9f9fa', | |
| 225 | + borderColor: '#fff', | |
| 226 | + borderWidth: '3px', | |
| 227 | + radius : '8px', | |
| 228 | + padding : '20px', | |
| 229 | + shadow : 'rgba(15, 23, 42, 0.06) 0px 4px 16px 0px' | |
| 230 | + } | |
| 231 | + }; | |
| 232 | + } | |
| 233 | + | |
| 234 | + function is_dark_form_theme() { | |
| 235 | + return 'wpbc_theme_dark_1' === String( $( '#booking_form_theme' ).val() || '' ); | |
| 236 | + } | |
| 237 | + | |
| 238 | + function get_form_appearance_preset_for_theme( preset ) { | |
| 239 | + var presets = get_form_appearance_presets(); | |
| 240 | + | |
| 241 | + if ( ! is_dark_form_theme() ) { | |
| 242 | + return presets[preset] || presets.bordered; | |
| 243 | + } | |
| 244 | + | |
| 245 | + if ( 'soft' === preset ) { | |
| 246 | + return { | |
| 247 | + background : '#1f2937', | |
| 248 | + borderColor: '#334155', | |
| 249 | + borderWidth: '3px', | |
| 250 | + radius : '8px', | |
| 251 | + padding : '20px', | |
| 252 | + shadow : 'rgba(0, 0, 0, 0.24) 0px 4px 16px 0px' | |
| 253 | + }; | |
| 254 | + } | |
| 255 | + | |
| 256 | + return presets[preset] || presets.bordered; | |
| 257 | + } | |
| 258 | + | |
| 259 | + function sanitize_theme_color( value, fallback ) { | |
| 260 | + var v = String( value || '' ).trim(); | |
| 261 | + return /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test( v ) || 'transparent' === v ? v : fallback; | |
| 262 | + } | |
| 263 | + | |
| 264 | + function sanitize_theme_length( value, fallback ) { | |
| 265 | + var v = String( value || '' ).trim(); | |
| 266 | + return /^\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( v ) ? v : fallback; | |
| 267 | + } | |
| 268 | + | |
| 269 | + function sanitize_theme_spacing( value, fallback ) { | |
| 270 | + var v = String( value || '' ).trim().replace( /\s+/g, ' ' ); | |
| 271 | + var parts = v ? v.split( ' ' ) : []; | |
| 272 | + var i; | |
| 273 | + | |
| 274 | + if ( parts.length < 1 || parts.length > 4 ) { | |
| 275 | + return fallback; | |
| 276 | + } | |
| 277 | + for ( i = 0; i < parts.length; i++ ) { | |
| 278 | + if ( ! /^\d+(?:\.\d+)?(?:px|rem|em|%)$/i.test( parts[i] ) ) { | |
| 279 | + return fallback; | |
| 280 | + } | |
| 281 | + } | |
| 282 | + return parts.join( ' ' ); | |
| 283 | + } | |
| 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 | + | |
| 383 | + function get_form_style_presets() { | |
| 384 | + return cfg.form_style_presets && 'object' === typeof cfg.form_style_presets ? cfg.form_style_presets : {}; | |
| 385 | + } | |
| 386 | + | |
| 387 | + function get_current_form_style() { | |
| 388 | + var $checked = get_form().find( '[name="booking_form_style"]:checked' ); | |
| 389 | + return $checked.length ? String( $checked.val() || 'light_bordered' ) : 'light_bordered'; | |
| 390 | + } | |
| 391 | + | |
| 392 | + function get_custom_form_style_defaults() { | |
| 393 | + return $.extend( { | |
| 394 | + booking_form_custom_background_color : '#ffffff', | |
| 395 | + booking_form_custom_border_color : '#cccccc', | |
| 396 | + booking_form_custom_border_width : '1px', | |
| 397 | + booking_form_custom_border_radius : '2px', | |
| 398 | + booking_form_custom_padding_vertical : '10px', | |
| 399 | + booking_form_custom_padding_horizontal : '30px', | |
| 400 | + booking_form_custom_text_color : '#1d2327', | |
| 401 | + booking_form_custom_field_background_color : '#ffffff', | |
| 402 | + booking_form_custom_field_text_color : '#3c434a', | |
| 403 | + booking_form_custom_field_border_color : '#cccccc', | |
| 404 | + booking_form_custom_button_background_color: '#066aab', | |
| 405 | + booking_form_custom_button_text_color : '#ffffff', | |
| 406 | + booking_form_custom_button_border_color : '#066aab', | |
| 407 | + booking_form_custom_button_hover_background_color: '#055589', | |
| 408 | + booking_form_custom_button_hover_text_color: '#ffffff', | |
| 409 | + booking_form_custom_button_hover_border_color: '#055589', | |
| 410 | + booking_form_custom_secondary_button_background_color: '#fdfdfd', | |
| 411 | + booking_form_custom_secondary_button_text_color: '#444444', | |
| 412 | + booking_form_custom_secondary_button_border_color: '#eeeeee', | |
| 413 | + booking_form_custom_secondary_button_hover_background_color: '#fdfdfd', | |
| 414 | + booking_form_custom_secondary_button_hover_text_color: '#444444', | |
| 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' | |
| 418 | + }, cfg.custom_form_style_defaults && 'object' === typeof cfg.custom_form_style_defaults ? cfg.custom_form_style_defaults : {} ); | |
| 419 | + } | |
| 420 | + | |
| 421 | + function get_custom_form_style_css_vars() { | |
| 422 | + var defaults = get_custom_form_style_defaults(); | |
| 423 | + var values = $.extend( {}, defaults, cfg.settings && 'object' === typeof cfg.settings ? cfg.settings : {} ); | |
| 424 | + | |
| 425 | + return { | |
| 426 | + '--wpbc-bfb-form-background' : sanitize_theme_color( values.booking_form_custom_background_color, defaults.booking_form_custom_background_color ), | |
| 427 | + '--wpbc-bfb-form-border-color' : sanitize_theme_color( values.booking_form_custom_border_color, defaults.booking_form_custom_border_color ), | |
| 428 | + '--wpbc-bfb-form-border-width' : sanitize_theme_length( values.booking_form_custom_border_width, defaults.booking_form_custom_border_width ), | |
| 429 | + '--wpbc-bfb-form-border-radius' : sanitize_theme_length( values.booking_form_custom_border_radius, defaults.booking_form_custom_border_radius ), | |
| 430 | + '--wpbc-bfb-form-padding' : sanitize_theme_length( values.booking_form_custom_padding_vertical, defaults.booking_form_custom_padding_vertical ) + ' ' + sanitize_theme_length( values.booking_form_custom_padding_horizontal, defaults.booking_form_custom_padding_horizontal ), | |
| 431 | + '--wpbc-bfb-form-box-shadow' : 'rgba(0, 0, 0, 0.05) 0px 2px 6px 0px', | |
| 432 | + '--wpbc_form-label-color' : sanitize_theme_color( values.booking_form_custom_text_color, defaults.booking_form_custom_text_color ), | |
| 433 | + '--wpbc_form-label-sublabel-color' : sanitize_theme_color( values.booking_form_custom_text_color, defaults.booking_form_custom_text_color ), | |
| 434 | + '--wpbc_form-label-error-color' : '#d63637', | |
| 435 | + '--wpbc_form-field-background-color' : sanitize_theme_color( values.booking_form_custom_field_background_color, defaults.booking_form_custom_field_background_color ), | |
| 436 | + '--wpbc_form-field-menu-color' : sanitize_theme_color( values.booking_form_custom_field_background_color, defaults.booking_form_custom_field_background_color ), | |
| 437 | + '--wpbc_form-field-text-color' : sanitize_theme_color( values.booking_form_custom_field_text_color, defaults.booking_form_custom_field_text_color ), | |
| 438 | + '--wpbc_form-field-border-color' : sanitize_theme_color( values.booking_form_custom_field_border_color, defaults.booking_form_custom_field_border_color ), | |
| 439 | + '--wpbc_form-field-border-color-spare': sanitize_theme_color( values.booking_form_custom_field_border_color, defaults.booking_form_custom_field_border_color ), | |
| 440 | + '--wpbc_form-field-focus-border-color': '#066aab', | |
| 441 | + '--wpbc_form-field-focus-shadow-color': '#066aab', | |
| 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 ), | |
| 446 | + '--wpbc_form-button-background-color' : sanitize_theme_color( values.booking_form_custom_button_background_color, defaults.booking_form_custom_button_background_color ), | |
| 447 | + '--wpbc_form-button-background-color-alt': sanitize_theme_color( values.booking_form_custom_button_background_color, defaults.booking_form_custom_button_background_color ), | |
| 448 | + '--wpbc_form-button-border-color' : sanitize_theme_color( values.booking_form_custom_button_border_color, defaults.booking_form_custom_button_border_color ), | |
| 449 | + '--wpbc_form-button-text-color' : sanitize_theme_color( values.booking_form_custom_button_text_color, defaults.booking_form_custom_button_text_color ), | |
| 450 | + '--wpbc_form-button-text-color-alt' : sanitize_theme_color( values.booking_form_custom_button_text_color, defaults.booking_form_custom_button_text_color ), | |
| 451 | + '--wpbc_form-button-hover-background-color': sanitize_theme_color( values.booking_form_custom_button_hover_background_color, defaults.booking_form_custom_button_hover_background_color ), | |
| 452 | + '--wpbc_form-button-hover-border-color': sanitize_theme_color( values.booking_form_custom_button_hover_border_color, defaults.booking_form_custom_button_hover_border_color ), | |
| 453 | + '--wpbc_form-button-hover-text-color' : sanitize_theme_color( values.booking_form_custom_button_hover_text_color, defaults.booking_form_custom_button_hover_text_color ), | |
| 454 | + '--wpbc_form-choice-checked-border-color': '#066aab', | |
| 455 | + '--wpbc_form-choice-checked-color' : '#066aab', | |
| 456 | + '--wpbc_form-choice-focus-color' : '#066aab', | |
| 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 ), | |
| 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 ), | |
| 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 ), | |
| 461 | + '--wpbc_form-button-light-box-shadow' : '0 2px 10px 2px #ffffff54', | |
| 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 ), | |
| 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 ), | |
| 464 | + '--wpbc_form-button-light-hover-text-color': sanitize_theme_color( values.booking_form_custom_secondary_button_hover_text_color, defaults.booking_form_custom_secondary_button_hover_text_color ), | |
| 465 | + '--wpbc_form-button-light-hover-box-shadow': '0 2px 10px 2px #ffffff54', | |
| 466 | + '--wpbc_form-button-primary-hover-border-color': sanitize_theme_color( values.booking_form_custom_button_hover_border_color, defaults.booking_form_custom_button_hover_border_color ), | |
| 467 | + '--wpbc_form-page-break-color' : '#066aab' | |
| 468 | + }; | |
| 469 | + } | |
| 470 | + | |
| 471 | + function get_form_style_css_var_names() { | |
| 472 | + var keys = []; | |
| 473 | + var presets; | |
| 474 | + | |
| 475 | + if ( Array.isArray( cfg.form_style_css_var_names ) && cfg.form_style_css_var_names.length ) { | |
| 476 | + return cfg.form_style_css_var_names; | |
| 477 | + } | |
| 478 | + | |
| 479 | + presets = get_form_style_presets(); | |
| 480 | + $.each( presets, function ( preset_key, preset ) { | |
| 481 | + if ( preset && preset.css_vars && 'object' === typeof preset.css_vars ) { | |
| 482 | + $.each( preset.css_vars, function ( var_name ) { | |
| 483 | + if ( -1 === keys.indexOf( var_name ) ) { | |
| 484 | + keys.push( var_name ); | |
| 485 | + } | |
| 486 | + } ); | |
| 487 | + } | |
| 488 | + } ); | |
| 489 | + | |
| 490 | + $.each( get_custom_form_style_css_vars(), function ( var_name ) { | |
| 491 | + if ( -1 === keys.indexOf( var_name ) ) { | |
| 492 | + keys.push( var_name ); | |
| 493 | + } | |
| 494 | + } ); | |
| 495 | + | |
| 496 | + return keys; | |
| 497 | + } | |
| 498 | + | |
| 499 | + function resolve_form_style_css_vars( style ) { | |
| 500 | + var presets = get_form_style_presets(); | |
| 501 | + var preset = presets[ style ] || presets.light_bordered || {}; | |
| 502 | + | |
| 503 | + if ( 'custom' === style || preset.custom ) { | |
| 504 | + return apply_form_accent_css_vars( get_custom_form_style_css_vars(), true ); | |
| 505 | + } | |
| 506 | + | |
| 507 | + return apply_form_accent_css_vars( preset.css_vars && 'object' === typeof preset.css_vars ? preset.css_vars : {} ); | |
| 508 | + } | |
| 509 | + | |
| 510 | + function apply_form_style_to_preview() { | |
| 511 | + var style = get_current_form_style(); | |
| 512 | + var presets = get_form_style_presets(); | |
| 513 | + var preset = presets[ style ] || presets.light_bordered || {}; | |
| 514 | + var css_vars = resolve_form_style_css_vars( style ); | |
| 515 | + var css_var_names = get_form_style_css_var_names(); | |
| 516 | + var is_custom = ( 'custom' === style || preset.custom ); | |
| 517 | + var $preview = $( '[data-wpbc-theme-preview="1"]' ); | |
| 518 | + var $targets = $preview.find( '.wpbc_container.wpbc_form, .wpbc_bfb_form, .wpbc_bfb__form_preview_section_container' ); | |
| 519 | + | |
| 520 | + $( '[data-wpbc-theme-custom-appearance-notice="1"]' ).toggle( is_custom ); | |
| 521 | + | |
| 522 | + if ( ! $targets.length ) { | |
| 523 | + return; | |
| 524 | + } | |
| 525 | + | |
| 526 | + $targets | |
| 527 | + .removeClass( 'wpbc_bfb_form_appearance_custom' ) | |
| 528 | + .each( function () { | |
| 529 | + var style_obj = this.style; | |
| 530 | + | |
| 531 | + $.each( css_var_names, function ( index, var_name ) { | |
| 532 | + style_obj.removeProperty( var_name ); | |
| 533 | + } ); | |
| 534 | + | |
| 535 | + $.each( css_vars, function ( var_name, value ) { | |
| 536 | + if ( '' !== String( value || '' ) ) { | |
| 537 | + style_obj.setProperty( var_name, value ); | |
| 538 | + } | |
| 539 | + } ); | |
| 540 | + } ); | |
| 541 | + | |
| 542 | + if ( is_custom ) { | |
| 543 | + $targets.filter( '.wpbc_container.wpbc_form, .wpbc_bfb_form' ).addClass( 'wpbc_bfb_form_appearance_custom' ); | |
| 544 | + } | |
| 545 | + } | |
| 546 | + | |
| 547 | + function resolve_form_appearance() { | |
| 548 | + var preset = $( '#booking_form_appearance_preset' ).val() || 'bordered'; | |
| 549 | + | |
| 550 | + if ( 'custom' === preset ) { | |
| 551 | + return get_form_appearance_presets().bordered; | |
| 552 | + } | |
| 553 | + | |
| 554 | + return get_form_appearance_preset_for_theme( preset ); | |
| 555 | + } | |
| 556 | + | |
| 557 | + function apply_form_appearance() { | |
| 558 | + apply_form_style_to_preview(); | |
| 559 | + } | |
| 560 | + | |
| 120 | 561 | function apply_calendar_skin() { |
| 121 | 562 | var $select = $( '[data-wpbc-theme-calendar-skin="1"]' ); |
| 122 | 563 | var value = $select.find( 'option:selected' ).attr( 'data-wpbc-calendar-skin-url' ) || $select.val() || ''; |
| 123 | 564 | var skin_url = value ? make_asset_url( value ) : ''; |
| @@ -208,9 +649,9 @@ | ||
| 208 | 649 | } |
| 209 | 650 | |
| 210 | 651 | function ensure_calendar_only_days_selection() { |
| 211 | 652 | var $preview = $( '[data-wpbc-theme-preview="1"]' ).first(); |
| 212 | - 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'; | |
| 213 | 654 | var resource_id = parseInt( $preview.attr( 'data-resource-id' ) || 0, 10 ); |
| 214 | 655 | var expected = cfg.days_selection || {}; |
| 215 | 656 | var expected_mode = String( expected.days_select_mode || 'multiple' ); |
| 216 | 657 | var current_mode = null; |
| @@ -237,9 +678,9 @@ | ||
| 237 | 678 | } |
| 238 | 679 | |
| 239 | 680 | function apply_related_skins_for_theme( theme ) { |
| 240 | 681 | var calendar_skin = theme ? '/css/skins/24_9__dark_1.css' : '/css/skins/25_5__square_1.css'; |
| 241 | - 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'; | |
| 242 | 683 | |
| 243 | 684 | select_if_option_exists( $( '[data-wpbc-theme-calendar-skin="1"]' ), calendar_skin ); |
| 244 | 685 | select_if_option_exists( $( '[data-wpbc-theme-time-skin="1"]' ), time_skin ); |
| 245 | 686 | } |
| @@ -266,9 +707,9 @@ | ||
| 266 | 707 | } |
| 267 | 708 | |
| 268 | 709 | function maybe_show_preview_notice( $source ) { |
| 269 | 710 | var notice_type = $source.attr( 'data-wpbc-theme-preview-notice' ) || ''; |
| 270 | - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar'; | |
| 711 | + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form'; | |
| 271 | 712 | var message = get_preview_notice_message( notice_type ); |
| 272 | 713 | var $control = $( '.wpbc_theme_control_preview_mode' ).first(); |
| 273 | 714 | |
| 274 | 715 | if ( ! message ) { |
| @@ -288,9 +729,9 @@ | ||
| 288 | 729 | show_highlighted_notice( message, 'warning', 9000, $control ); |
| 289 | 730 | } |
| 290 | 731 | |
| 291 | 732 | function show_calendar_only_theme_notice() { |
| 292 | - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar'; | |
| 733 | + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form'; | |
| 293 | 734 | |
| 294 | 735 | if ( 'calendar' !== preview_mode ) { |
| 295 | 736 | return; |
| 296 | 737 | } |
| @@ -317,8 +758,12 @@ | ||
| 317 | 758 | w.wpbc_hook__init_timeselector(); |
| 318 | 759 | } |
| 319 | 760 | return; |
| 320 | 761 | } |
| 762 | + if ( typeof w.wpbc_hook__destroy_timeselector === 'function' ) { | |
| 763 | + w.wpbc_hook__destroy_timeselector( $preview.get( 0 ) ); | |
| 764 | + return; | |
| 765 | + } | |
| 321 | 766 | |
| 322 | 767 | $preview.find( '.wpbc_times_selector' ).remove(); |
| 323 | 768 | $preview.find( time_selectors ).show(); |
| 324 | 769 | } |
| @@ -323,9 +768,9 @@ | ||
| 323 | 768 | $preview.find( time_selectors ).show(); |
| 324 | 769 | } |
| 325 | 770 | |
| 326 | 771 | function refresh_preview_mode_controls() { |
| 327 | - var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'calendar'; | |
| 772 | + var preview_mode = $( '#wpbc_theme_preview_mode' ).val() || 'form'; | |
| 328 | 773 | $( '[data-wpbc-theme-form-control="1"]' ).toggleClass( 'is-visible', 'form' === preview_mode ); |
| 329 | 774 | } |
| 330 | 775 | |
| 331 | 776 | function set_calendar_loading( is_loading ) { |
| @@ -362,8 +807,9 @@ | ||
| 362 | 807 | if ( response.data.days_selection ) { |
| 363 | 808 | cfg.days_selection = response.data.days_selection; |
| 364 | 809 | } |
| 365 | 810 | apply_form_theme(); |
| 811 | + apply_form_appearance(); | |
| 366 | 812 | apply_calendar_skin(); |
| 367 | 813 | apply_time_skin(); |
| 368 | 814 | ensure_calendar_only_days_selection(); |
| 369 | 815 | sync_time_picker_preview(); |
| @@ -461,8 +907,28 @@ | ||
| 461 | 907 | apply_related_skins_for_theme( $( this ).val() || '' ); |
| 462 | 908 | show_calendar_only_theme_notice(); |
| 463 | 909 | } ); |
| 464 | 910 | |
| 911 | + $( document ).on( 'change', '[name="booking_form_style"]', function () { | |
| 912 | + sync_form_style_choice(); | |
| 913 | + apply_form_theme(); | |
| 914 | + apply_form_appearance(); | |
| 915 | + apply_related_skins_for_theme( $( '#booking_form_theme' ).val() || '' ); | |
| 916 | + show_calendar_only_theme_notice(); | |
| 917 | + schedule_preview_refresh(); | |
| 918 | + } ); | |
| 919 | + | |
| 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. | |
| 923 | + apply_form_appearance(); | |
| 924 | + } ); | |
| 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 | + | |
| 465 | 931 | $( document ).on( 'change', '[data-wpbc-theme-calendar-skin="1"]', function () { |
| 466 | 932 | apply_calendar_skin(); |
| 467 | 933 | } ); |
| 468 | 934 | |
| @@ -494,10 +960,19 @@ | ||
| 494 | 960 | return; |
| 495 | 961 | } |
| 496 | 962 | |
| 497 | 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 | + } | |
| 498 | 972 | refresh_preview_mode_controls(); |
| 499 | 973 | apply_form_theme(); |
| 974 | + apply_form_appearance(); | |
| 500 | 975 | ensure_calendar_only_days_selection(); |
| 501 | 976 | sync_time_picker_preview(); |
| 502 | 977 | } ); |
| 503 | 978 | }( jQuery, window ) ); |