(function ($) { "use strict"; var $window = $(window), $document = $(document), $body = $("body"); // Site title and description. wp.customize("blogname", function (value) { value.bind(function (to) { $(".site-title").text(to); }); }); wp.customize("blogdescription", function (value) { value.bind(function (to) { $(".site-description").text(to); }); }); wp.customize.bind("preview-ready", function () { var defaultTarget = window.parent === window ? null : window.parent; $document.on( "click", ".site-header-focus-item .item-customizer-focus, .builder-item-focus .edit-row-action", function (e) { e.preventDefault(); e.stopPropagation(); var p = $(this).closest(".site-header-focus-item"); var section_id = p.attr("data-section") || ""; if (section_id) { if (defaultTarget.wp.customize.section(section_id)) { defaultTarget.wp.customize.section(section_id).focus(); } } } ); $document.on( "click", ".site-footer-focus-item .item-customizer-focus", function (e) { e.preventDefault(); e.stopPropagation(); var p = $(this).closest(".site-footer-focus-item"); var section_id = p.attr("data-section") || ""; if (section_id) { if (defaultTarget.wp.customize.section(section_id)) { defaultTarget.wp.customize.section(section_id).focus(); } } } ); }); document.addEventListener("DOMContentLoaded", function () { if (navigator.userAgent.toLowerCase().indexOf("safari/") != -1) { if (navigator.userAgent.toLowerCase().indexOf("chrome") > -1) { } else { // Safari doesn't want to render the iframe... This hack at least makes it render although it's not idea because of the flash. // $body.animate({ // opacity: 0, // }, 50, function() { // $body.css( 'display', 'none' ); // $body.css( 'opacity', 1 ); // }); // setTimeout(function(){ // $body.css( 'display', 'block' ); // }, 100); } } var hasSelectiveRefresh = "undefined" !== typeof wp && wp.customize && wp.customize.selectiveRefresh && wp.customize.widgetsPreview && wp.customize.widgetsPreview.WidgetPartial; if (hasSelectiveRefresh) { wp.customize.selectiveRefresh.bind( "partial-content-rendered", function (placement) { if (placement.partial.id === "header_desktop_items") { window.kadence.initToggleDrawer(); } window.kadence.initTransHeaderPadding(); if ( typeof window.kadence.initStickyHeader !== "undefined" ) { window.kadence.initStickyHeader(); window.kadence.initScrollToTop(); } } ); } }); var kadenceCustomizer = { /** * Calculate preferred value with custom viewport widths using precise calc formula * * @param {object} font Font settings object * @return {string} Calculated preferred value as calc expression */ calculate_preferred_value_with_viewports: function (font) { var min_value = font.minFontSize; var max_value = font.maxFontSize; var min_viewport = font.minScreenSize; var max_viewport = font.maxScreenSize; var unit = font.fontSizeUnit || "px"; var viewport_unit = font.screenSizeUnit || "px"; if (!min_value || !max_value || !min_viewport || !max_viewport) { return ""; } // Convert to rem if needed for consistent calculation var min_in_rem = min_value; var max_in_rem = max_value; // Convert px to rem for calculation (but keep original unit in output) var output_unit = unit; if (unit === "px") { min_in_rem = min_value / 16; max_in_rem = max_value / 16; unit = "rem"; } // For rem-based calculations, use the precise formula // The formula: preferred = a + b*vw where: // b = 1600 * (F2 - F1) / (W2 - W1) // a = F1 - (b/1600) * W1 // This ensures at W1: a + b*(W1/100) = F1 and at W2: a + b*(W2/100) = F2 if (unit === "rem" || unit === "em") { var slope = (1600 * (max_in_rem - min_in_rem)) / (max_viewport - min_viewport); var intercept = min_in_rem - (slope / 1600) * min_viewport; // Round to 4 decimal places for precision var rounded_intercept = Math.round(intercept * 10000) / 10000; var rounded_slope = Math.round(slope * 10000) / 10000; // Return clean expression without calc() return rounded_intercept + unit + " + " + rounded_slope + "vw"; } // For other units (%, vw), use a simpler approach var slope = ((max_value - min_value) / (max_viewport - min_viewport)) * 100; var intercept = min_value - (slope * min_viewport) / 100; var rounded_intercept = Math.round(intercept * 10000) / 10000; var rounded_slope = Math.round(slope * 10000) / 10000; return rounded_intercept + unit + " + " + rounded_slope + "vw"; }, /** * Generate a clamp value from mobile and desktop sizes * * @param {object} font Font settings object * @return {string} Generated clamp value */ generate_clamp_value: function (font) { var clamped = font.clamped === true; if (clamped) { var min_value = font.minFontSize; var max_value = font.maxFontSize; var unit = font.fontSizeUnit || "px"; var preferred = this.calculate_preferred_value_with_viewports(font); if (preferred && min_value && max_value) { return ( "clamp(" + min_value + unit + ", " + preferred + ", " + max_value + unit + ")" ); } } return ""; }, live_css_typography: function (key, rules, newValue) { var styleID = "kadence-customize-preview-css-" + key, $style = $("#" + styleID), css = "", media_tablet = "@media screen and (max-width: 1023px)", media_mobile = "@media screen and (max-width: 499px)", selector, cssArray = {}; // Create