// External dependencies import get from 'lodash/get'; import set from 'lodash/set'; // Internal dependencies import { isBuilder, isDiviTheme, isExtraTheme, } from '../utils/utils'; /*! ET frontend-builder-scripts.js */ (function($) { const isBlockLayoutPreview = 'undefined' !== typeof window.ETBlockLayoutModulesScript && $('body').hasClass('et-block-layout-preview'); const top_window = isBuilder || isBlockLayoutPreview ? ET_Builder.Frames.top : window; const $et_window = $(window); const $fullscreenSectionWindow = isBlockLayoutPreview ? $(top_window) : $(window); const isTB = $('body').hasClass('et-tb'); const isBFB = $('body').hasClass('et-bfb'); const isVB = isBuilder && ! isBFB; const isInsideVB = function($node) { return $node.closest('#et-fb-app').length > 0; }; window.et_load_event_fired = false; window.et_is_transparent_nav = $('body').hasClass('et_transparent_nav'); window.et_is_vertical_nav = $('body').hasClass('et_vertical_nav'); window.et_is_fixed_nav = $('body').hasClass('et_fixed_nav'); window.et_force_width_container_change = false; jQuery.fn.reverse = [].reverse; jQuery.fn.closest_descendent = function(selector) { let $found; let $current_children = this.children(); while ($current_children.length) { $found = $current_children.filter(selector); if ($found.length) { break; } $current_children = $current_children.children(); } return $found; }; $(window).on('et_pb_init_modules', function () { $(() => { /** * Provide event listener for plugins to hook up to. */ $(window).trigger('et_pb_before_init_modules'); const $et_pb_slider = $('.et_pb_slider'); const $et_pb_map = $('.et_pb_map_container'); const $et_pb_parallax = $('.et_parallax_bg'); const $et_pb_background_layout_hoverable = $('[data-background-layout][data-background-layout-hover]'); const et_is_mobile_device = navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/) !== null || 'standalone' in window.navigator && ! window.navigator.standalone; const et_is_ipad = navigator.userAgent.match(/iPad/); const et_is_ie9 = navigator.userAgent.match(/MSIE 9.0/) !== null; const et_all_rows = $('.et_pb_row'); const $et_container = window.et_pb_custom && ! window.et_pb_custom.is_builder_plugin_used ? $('body') : et_all_rows; let et_container_width = $et_container.width(); const et_hide_nav = $('body').hasClass('et_hide_nav'); const $top_header = $('#top-header'); const $et_main_content_first_row = $('#main-content .container:first-child'); const $et_sticky_image = $('.et_pb_image_sticky'); const $et_pb_counter_amount = $('.et_pb_counter_amount'); const $et_menu_selector = window.et_pb_custom && window.et_pb_custom.is_divi_theme_used ? $('ul.nav') : $('.et_pb_fullwidth_menu ul.nav'); const et_pb_ab_bounce_rate = window.et_pb_custom && window.et_pb_custom.ab_bounce_rate * 1000; const et_pb_ab_logged_status = {}; let et_animation_breakpoint = ''; const recaptchaApi = get(window, 'etCore.api.spam.recaptcha'); $.each(et_pb_custom.ab_tests, (index, test) => { et_pb_ab_logged_status[test.post_id] = { read_page: false, read_goal: false, view_goal: false, click_goal: false, con_goal: false, con_short: false, }; }); const grid_containers = $('.et_pb_grid_item').parent().get(); const $hover_gutter_modules = $('.et_pb_gutter_hover'); const $et_top_menu = $et_menu_selector; // log the conversion if visitor is on Thank You page and comes from the Shop module which is the Goal if ($('.et_pb_ab_shop_conversion').length && typeof et_pb_get_cookie_value('et_pb_ab_shop_log') !== 'undefined' && '' !== et_pb_get_cookie_value('et_pb_ab_shop_log')) { const shop_log_data = et_pb_get_cookie_value('et_pb_ab_shop_log').split('_'); const page_id = shop_log_data[0]; const subject_id = shop_log_data[1]; const test_id = shop_log_data[2]; et_pb_ab_update_stats('con_goal', page_id, subject_id, test_id); // remove the cookie after conversion is logged et_pb_set_cookie(0, 'et_pb_ab_shop_log=true'); } // log the conversion if visitor is on page with tracking shortcode if ($('.et_pb_ab_split_track').length) { $('.et_pb_ab_split_track').each(function() { const tracking_test = $(this).data('test_id'); const cookies_name = `et_pb_ab_shortcode_track_${tracking_test}`; if (typeof et_pb_get_cookie_value(cookies_name) !== 'undefined' && '' !== et_pb_get_cookie_value(cookies_name)) { const track_data = et_pb_get_cookie_value(cookies_name).split('_'); const page_id = track_data[0]; const subject_id = track_data[1]; const test_id = track_data[2]; et_pb_ab_update_stats('con_short', page_id, subject_id, test_id); // remove the cookie after conversion is logged et_pb_set_cookie(0, `${cookies_name}=true`); } }); } // Handle gutter hover options if ($hover_gutter_modules.length > 0) { $hover_gutter_modules.each(function() { const $thisEl = $(this); const originalGutter = $thisEl.data('original_gutter'); const hoverGutter = $thisEl.data('hover_gutter'); $thisEl.on('mouseenter', () => { $thisEl.removeClass(`et_pb_gutters${originalGutter}`); $thisEl.addClass(`et_pb_gutters${hoverGutter}`); }).on('mouseleave', () => { $thisEl.removeClass(`et_pb_gutters${hoverGutter}`); $thisEl.addClass(`et_pb_gutters${originalGutter}`); }); }); } // init AB Testing if enabled if (window.et_pb_custom && window.et_pb_custom.is_ab_testing_active) { $.each(et_pb_custom.ab_tests, (index, test) => { et_pb_init_ab_test(test); }); } if (et_all_rows.length) { et_all_rows.each(function() { const $this_row = $(this); let row_class = ''; row_class = et_get_column_types($this_row.find('>.et_pb_column')); if ('' !== row_class) { $this_row.addClass(row_class); } if ($this_row.find('.et_pb_row_inner').length) { $this_row.find('.et_pb_row_inner').each(function() { const $this_row_inner = $(this); row_class = et_get_column_types($this_row_inner.find('.et_pb_column')); if ('' !== row_class) { $this_row_inner.addClass(row_class); } }); } // Fix z-index for menu modules const zIndexIncreaseMax = $this_row.parents('.et_pb_section.section_has_divider').length ? 6 : 3; const zIndexShouldIncrease = isNaN($this_row.css('z-index')) || $this_row.css('z-index') < zIndexIncreaseMax; if ($this_row.find('.et_pb_module.et_pb_menu').length && zIndexShouldIncrease) { $this_row.css('z-index', zIndexIncreaseMax); } }); } function et_get_column_types($columns) { let row_class = ''; if ($columns.length) { $columns.each(function() { const $column = $(this); const column_type = $column.attr('class').split('et_pb_column_')[1]; const column_type_clean = typeof column_type !== 'undefined' ? column_type.split(' ', 1)[0] : '4_4'; const column_type_updated = column_type_clean.replace('_', '-').trim(); row_class += `_${column_type_updated}`; }); if ((row_class.indexOf('1-4') !== - 1) || (row_class.indexOf('1-5_1-5') !== - 1) || (row_class.indexOf('1-6_1-6') !== - 1)) { switch (row_class) { case '_1-4_1-4_1-4_1-4': row_class = 'et_pb_row_4col'; break; case '_1-5_1-5_1-5_1-5_1-5': row_class = 'et_pb_row_5col'; break; case '_1-6_1-6_1-6_1-6_1-6_1-6': row_class = 'et_pb_row_6col'; break; default: row_class = `et_pb_row${row_class}`; } } else { row_class = ''; } } return row_class; } window.et_pb_init_nav_menu($et_top_menu); $et_sticky_image.each(function() { window.et_pb_apply_sticky_image_effect($(this)); }); if (et_is_mobile_device) { $('.et_pb_section_video_bg').each(function() { const $this_el = $(this); $this_el.closest('.et_pb_preload').removeClass('et_pb_preload'); // Only remove when it has opened class. if ($this_el.hasClass('opened')) { $this_el.remove(); } }); $('body').addClass('et_mobile_device'); if (! et_is_ipad) { $('body').addClass('et_mobile_device_not_ipad'); } } if (et_is_ie9) { $('body').addClass('et_ie9'); } if (grid_containers.length || isBuilder) { $(grid_containers).each(function() { window.et_pb_set_responsive_grid($(this), '.et_pb_grid_item'); }); } if ($et_pb_counter_amount.length) { $et_pb_counter_amount.each(function() { window.et_bar_counters_init($(this)); }); } /* $et_pb_counter_amount.length */ $('.et_pb_shop, .et_pb_wc_upsells, .et_pb_wc_related_products').each(function() { let $this_el = $(this); let icon = $this_el.data('icon') || ''; let icon_tablet = $this_el.data('icon-tablet') || ''; let icon_phone = $this_el.data('icon-phone') || ''; let icon_sticky = $this_el.data('icon-sticky') || ''; let $overlay = $this_el.find('.et_overlay'); // Handle Extra theme. if (! $overlay.length && $this_el.hasClass('et_pb_wc_related_products')) { $overlay = $this_el.find('.et_pb_extra_overlay'); $this_el = $overlay.closest('.et_pb_module_inner').parent(); icon = $this_el.attr('data-icon') || ''; icon_tablet = $this_el.attr('data-icon-tablet') || ''; icon_phone = $this_el.attr('data-icon-phone') || ''; icon_sticky = $this_el.attr('data-icon-phone') || ''; } // Set data icon and inline icon class. if (icon !== '') { $overlay.attr('data-icon', icon).addClass('et_pb_inline_icon'); } if (icon_tablet !== '') { $overlay.attr('data-icon-tablet', icon_tablet).addClass('et_pb_inline_icon_tablet'); } if (icon_phone !== '') { $overlay.attr('data-icon-phone', icon_phone).addClass('et_pb_inline_icon_phone'); } if (icon_sticky !== '') { $overlay.attr('data-icon-sticky', icon_sticky).addClass('et_pb_inline_icon_sticky'); } if ($this_el.hasClass('et_pb_shop')) { const $shopItems = $this_el.find('li.product'); const shop_index = $this_el.attr('data-shortcode_index'); const itemClass = `et_pb_shop_item_${shop_index}`; if ($shopItems.length > 0) { $shopItems.each((idx, $item) => { $($item).addClass(`${itemClass}_${idx}`); }); } } }); $et_pb_background_layout_hoverable.each(function() { let $this_el = $(this); const background_layout = $this_el.data('background-layout'); const background_layout_hover = $this_el.data('background-layout-hover'); const background_layout_tablet = $this_el.data('background-layout-tablet'); const background_layout_phone = $this_el.data('background-layout-phone'); let $this_el_item; let $this_el_parent; // Switch the target element for some modules. if ($this_el.hasClass('et_pb_button_module_wrapper')) { // Button, change the target to main button block. $this_el = $this_el.find('> .et_pb_button'); } else if ($this_el.hasClass('et_pb_gallery')) { // Gallery, add gallery item as target element. $this_el_item = $this_el.find('.et_pb_gallery_item'); $this_el = $this_el.add($this_el_item); } else if ($this_el.hasClass('et_pb_post_slider')) { // Post Slider, add slide item as target element. $this_el_item = $this_el.find('.et_pb_slide'); $this_el = $this_el.add($this_el_item); } else if ($this_el.hasClass('et_pb_slide')) { // Slider, add slider as target element. $this_el_parent = $this_el.closest('.et_pb_slider'); $this_el = $this_el.add($this_el_parent); } let layout_class_list = 'et_pb_bg_layout_light et_pb_bg_layout_dark et_pb_text_color_dark'; let layout_class = `et_pb_bg_layout_${background_layout}`; let layout_class_hover = `et_pb_bg_layout_${background_layout_hover}`; let text_color_class = 'light' === background_layout ? 'et_pb_text_color_dark' : ''; let text_color_class_hover = 'light' === background_layout_hover ? 'et_pb_text_color_dark' : ''; // Only includes tablet class if it's needed. if (background_layout_tablet) { layout_class_list += ' et_pb_bg_layout_light_tablet et_pb_bg_layout_dark_tablet et_pb_text_color_dark_tablet'; layout_class += ` et_pb_bg_layout_${background_layout_tablet}_tablet`; layout_class_hover += ` et_pb_bg_layout_${background_layout_hover}_tablet`; text_color_class += 'light' === background_layout_tablet ? ' et_pb_text_color_dark_tablet' : ''; text_color_class_hover += 'light' === background_layout_hover ? ' et_pb_text_color_dark_tablet' : ''; } // Only includes phone class if it's needed. if (background_layout_phone) { layout_class_list += ' et_pb_bg_layout_light_phone et_pb_bg_layout_dark_phone et_pb_text_color_dark_phone'; layout_class += ` et_pb_bg_layout_${background_layout_phone}_phone`; layout_class_hover += ` et_pb_bg_layout_${background_layout_hover}_phone`; text_color_class += 'light' === background_layout_phone ? ' et_pb_text_color_dark_phone' : ''; text_color_class_hover += 'light' === background_layout_hover ? ' et_pb_text_color_dark_phone' : ''; } $this_el.on('mouseenter', () => { $this_el.removeClass(layout_class_list); $this_el.addClass(layout_class_hover); if ($this_el.hasClass('et_pb_audio_module') && '' !== text_color_class_hover) { $this_el.addClass(text_color_class_hover); } }); $this_el.on('mouseleave', () => { $this_el.removeClass(layout_class_list); $this_el.addClass(layout_class); if ($this_el.hasClass('et_pb_audio_module') && '' !== text_color_class) { $this_el.addClass(text_color_class); } }); }); window.et_reinit_waypoint_modules = et_pb_debounce(() => { const $et_pb_circle_counter = $('.et_pb_circle_counter'); const $et_pb_number_counter = $('.et_pb_number_counter'); const $et_pb_video_background = $('.et_pb_section_video_bg video'); // if waypoint is available and we are not ignoring them. if ($.fn.waypoint && window.et_pb_custom && 'yes'!==window.et_pb_custom.ignore_waypoints && !isBuilder) { if ('undefined'!== typeof et_process_animation_data) { window.et_process_animation_data(true); } // get all of our waypoint things. const modules = $('.et-waypoint'); modules.each(function () { window.et_waypoint($(this), { offset: et_get_offset($(this), '100%'), handler() { // what actually triggers the animation. $(this.element).addClass('et-animated'); }, }, 2); }); // Set waypoint for circle counter module. if ($et_pb_circle_counter.length) { // iterate over each. $et_pb_circle_counter.each(function () { const $this_counter = $(this).find('.et_pb_circle_counter_inner'); if (!$this_counter.is(':visible') || et_has_animation_data($this_counter)) { return; } window.et_waypoint($this_counter, { offset: window.et_get_offset($(this), '100%'), handler() { if ($this_counter.data('PieChartHasLoaded') || 'undefined'=== typeof $this_counter.data('easyPieChart')) { return; } // No need to update animated circle counter as soon as it hits // bottom of the page in layout block preview page since layout // block preview page is being rendered in 100% height inside // Block Editor if (isBlockLayoutPreview) { return; } $this_counter.data('easyPieChart').update($this_counter.data('number-value')); $this_counter.data('PieChartHasLoaded', true); }, }, 2); }); } // Set waypoint for number counter module. if ($et_pb_number_counter.length) { $et_pb_number_counter.each(function () { const $this_counter = $(this); if (et_has_animation_data($this_counter)) { return; } window.et_waypoint($this_counter, { offset: et_get_offset($(this), '100%'), handler() { $this_counter.data('easyPieChart').update($this_counter.data('number-value')); }, }); }); } } else { // if no waypoints supported then apply all the animations right away if ('undefined'!== typeof et_process_animation_data) { window.et_process_animation_data(false); } const animated_class = isBuilder ? 'et-animated--vb':'et-animated'; $('.et-waypoint').addClass(animated_class); // While in the builder, trigger all animations instantly as otherwise // TB layouts that are displayed but are not the currently edited post // will have their animated modules invisible due to .et-waypoint. $('.et-waypoint').each(function () { window.et_animate_element($(this)); }); if ($et_pb_circle_counter.length) { $et_pb_circle_counter.each(function () { const $this_counter = $(this).find('.et_pb_circle_counter_inner'); if (!$this_counter.is(':visible')) { return; } if ($this_counter.data('PieChartHasLoaded') || 'undefined'=== typeof $this_counter.data('easyPieChart')) { return; } $this_counter.data('easyPieChart').update($this_counter.data('number-value')); $this_counter.data('PieChartHasLoaded', true); }); } if ($et_pb_number_counter.length) { $et_pb_number_counter.each(function () { const $this_counter = $(this); $this_counter.data('easyPieChart').update($this_counter.data('number-value')); }); } } // End checking of waypoints. if ($et_pb_video_background.length) { $et_pb_video_background.each(function () { const $this_video_background = $(this); et_pb_video_background_init($this_video_background, this); }); } // End of et_pb_debounce(). }, 100); /** * Get current active device based on window width size. * * @returns {string} View mode. */ window.et_pb_get_current_window_mode = function() { const window_width = $et_window.width(); let current_mode = 'desktop'; if (window_width <= 980 && window_width > 479) { current_mode = 'tablet'; } else if (window_width <= 479) { current_mode = 'phone'; } return current_mode; } function et_toggle_animation_callback(initial_toggle_state, $module, $section) { if ('closed' === initial_toggle_state) { $module.removeClass('et_pb_toggle_close').addClass('et_pb_toggle_open'); } else { $module.removeClass('et_pb_toggle_open').addClass('et_pb_toggle_close'); } if ($section.hasClass('et_pb_section_parallax') && ! $section.children().hasClass('et_pb_parallax_css')) { et_parallax_set_height.bind($section)(); } window.et_reinit_waypoint_modules(); } // Disable hover event when user opening toggle on mobile. $('.et_pb_accordion').on('touchstart', e => { // Ensure to disable only on mobile. if ('desktop' !== window.et_pb_get_current_window_mode()) { const $target = $(e.target); // Only disable when user click to open the toggle. if ($target.hasClass('et_pb_toggle_title') || $target.hasClass('et_fb_toggle_overlay')) { e.preventDefault(); // Trigger click event to open the toggle. $target.trigger('click'); } } }); $('body').on('click', '.et_pb_toggle_title, .et_fb_toggle_overlay', function() { const $this_heading = $(this); const $module = $this_heading.closest('.et_pb_toggle'); const $section = $module.parents('.et_pb_section'); const $content = $module.find('.et_pb_toggle_content'); const $accordion = $module.closest('.et_pb_accordion'); const is_accordion = $accordion.length; const is_accordion_toggling = $accordion.hasClass('et_pb_accordion_toggling'); const window_offset_top = $(window).scrollTop(); let fixed_header_height = 0; const initial_toggle_state = $module.hasClass('et_pb_toggle_close') ? 'closed' : 'opened'; let $accordion_active_toggle; let module_offset; if (is_accordion) { if ($module.hasClass('et_pb_toggle_open') || is_accordion_toggling) { return false; } $accordion.addClass('et_pb_accordion_toggling'); $accordion_active_toggle = $module.siblings('.et_pb_toggle_open'); } if ($content.is(':animated')) { return; } $content.slideToggle(700, () => { et_toggle_animation_callback(initial_toggle_state, $module, $section); }); if (is_accordion) { const accordionCompleteTogglingCallback = function() { $accordion_active_toggle.removeClass('et_pb_toggle_open').addClass('et_pb_toggle_close'); $accordion.removeClass('et_pb_accordion_toggling'); module_offset = $module.offset(); // Calculate height of fixed nav if ($('#wpadminbar').length) { fixed_header_height += $('#wpadminbar').height(); } if ($('#top-header').length) { fixed_header_height += $('#top-header').height(); } if ($('#main-header').length && ! window.et_is_vertical_nav) { fixed_header_height += $('#main-header').height(); } // Compare accordion offset against window's offset and adjust accordingly if ((window_offset_top + fixed_header_height) > module_offset.top) { $('html, body').animate({ scrollTop: (module_offset.top - fixed_header_height - 50), }); } }; // slideToggle collapsing mechanism (display:block, sliding, then display: none) // doesn't work if the DOM is not "visible" (no height / width at all) which can // happen if the accordion item has no content on desktop mode but has in hover if ($accordion_active_toggle.find('.et_pb_toggle_content').is(':visible')) { $accordion_active_toggle.find('.et_pb_toggle_content').slideToggle(700, accordionCompleteTogglingCallback); } else { $accordion_active_toggle.find('.et_pb_toggle_content').hide(); accordionCompleteTogglingCallback(); } } }); // Email Validation // Use the regex defined in the HTML5 spec for input[type=email] validation // (see https://www.w3.org/TR/2016/REC-html51-20161101/sec-forms.html#email-state-typeemail) const et_email_reg_html5 = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; /** * Verifies that an email is valid similar to how WordPress `is_email()` method works. * * Does not grok i18n domains. Not RFC compliant. * * @param string email Email address to verify. * @return bool Valid true on success, false on failure. */ var et_is_email = function(email) { // Test for the minimum length the email can be. if (6 > email.length) { return false; } // Test for an @ character after the first position. if (false === php_strpos(email, '@', 1)) { return false; } // Split out the local and domain parts. var parts = email.split('@', 2); var local = parts[0]; var domain = parts[1]; // LOCAL PART // Test for invalid characters. if (!/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/.test(local)) { return false; } // DOMAIN PART // Test for sequences of periods. if (/\.{2,}/.test(domain)) { return false; } // Test for leading and trailing periods and whitespace. if (php_trim(domain, " \t\n\r\0\x0B.") !== domain) { return false; } // Split the domain into subs. var subs = domain.split('.'); // Assume the domain will have at least two subs. if (2 > subs.length) { return false; } // Loop through each sub. for (var i in subs) { var sub = subs[i]; // Test for leading and trailing hyphens and whitespace. if (php_trim(sub, " \t\n\r\0\x0B-") !== sub) { return false; } // Test for invalid characters if (!/^[a-z0-9-]+$/i.test(sub)) { return false; } } // Congratulations. return true; // Analog of PHP function `trim` (https://www.php.net/manual/en/function.trim.php) written in JavaScript function php_trim(str, charlist) { var whitespace = [ ' ', '\n', '\r', '\t', '\f', '\x0b', '\xa0', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u200b', '\u2028', '\u2029', '\u3000' ].join(''); var l = 0; var i = 0; str += ''; if (charlist) { whitespace = (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '$1'); } l = str.length for (i = 0; i < l; i++) { if (whitespace.indexOf(str.charAt(i)) === -1) { str = str.substring(i); break } } l = str.length for (i = l - 1; i >= 0; i--) { if (whitespace.indexOf(str.charAt(i)) === -1) { str = str.substring(0, i + 1); break } } return whitespace.indexOf(str.charAt(0)) === -1 ? str : ''; } // Analog of PHP function `strpos` written in JavaScript function php_strpos(haystack, needle, offset) { var i = (haystack+'').indexOf(needle, (offset || 0)); return i === -1 ? false : i; } } /** * Get safe form redirect URL limited to web schemes. * * @param {string} url * @returns {string} */ var et_get_safe_redirect_url = function(url) { if ('string' !== typeof url) { return ''; } const trimmed_url = url.trim(); if ('' === trimmed_url) { return ''; } const anchor = document.createElement('a'); anchor.href = trimmed_url; const protocol = `${anchor.protocol}`.toLowerCase(); if ('http:' !== protocol && 'https:' !== protocol) { return ''; } return anchor.href; }; const $et_contact_container = $('.et_pb_contact_form_container'); const is_recaptcha_enabled = ! isBuilder && $('.et_pb_module.et_pb_recaptcha_enabled').length > 0; const $recaptchaScripts = document.body.innerHTML.match(/