').insertBefore($active_carousel_group);
$prev_carousel_group.css({ left: `-${active_carousel_width}px`, width: `${active_carousel_width}px`, 'max-width': `${active_carousel_width}px` }).show();
// this is an endless loop, so it can decide internally when to break out, so that next_position
// can get filled up, even to the extent of an element having both and current_ and next_ position
for (let x = (items.length - 1), total = (items.length - 1); ; x--, total--) {
if (total <= active_items_start && total >= active_items_end) {
$(items[x]).addClass(`changing_position current_position current_position_${current_position}`);
$(items[x]).data('current_position', current_position);
current_position--;
}
if (total <= prev_items_start && total >= prev_items_end) {
$(items[x]).data('prev_position', prev_position);
$(items[x]).addClass(`changing_position prev_position prev_position_${prev_position}`);
if (! $(items[x]).hasClass('current_position')) {
$(items[x]).addClass('container_append');
} else {
$(items[x]).clone(true).appendTo($active_carousel_group).addClass('delayed_container_append_dup')
.attr('id', `${$(items[x]).attr('id')}-dup`);
$(items[x]).addClass('delayed_container_append');
}
prev_position--;
}
if (prev_position <= 0) {
break;
}
if (0 == x) {
x = items.length;
}
}
const sorted = $portfolio_items.find('.container_append, .delayed_container_append_dup').sort((a, b) => {
const el_a_position = parseInt($(a).data('prev_position'));
const el_b_position = parseInt($(b).data('prev_position'));
return (el_a_position < el_b_position) ? - 1 : (el_a_position > el_b_position) ? 1 : 0;
});
$(sorted).show().appendTo($prev_carousel_group);
$prev_carousel_group.children().each(function() {
$(this).css({ width: `${item_width}px`, 'max-width': `${item_width}px`, position: 'absolute', left: `${(item_width * ($(this).data('prev_position') - 1))}px` });
});
$active_carousel_group.animate({
left: '100%',
}, {
duration: slide_duration,
complete() {
$portfolio_items.find('.delayed_container_append').reverse().each(function() {
$(this).css({ width: `${item_width}px`, 'max-width': `${item_width}px`, position: 'absolute', left: `${(item_width * ($(this).data('prev_position') - 1))}px` });
$(this).prependTo($prev_carousel_group);
});
$active_carousel_group.removeClass('active');
$active_carousel_group.children().each(function() {
const position = $(this).data('position');
current_position = $(this).data('current_position');
$(this).removeClass(`position_${position} ` + `changing_position current_position current_position_${current_position}`);
$(this).data('position', '');
$(this).data('current_position', '');
$(this).hide();
$(this).css({ position: '', width: '', 'max-width': '', left: '' });
$(this).appendTo($portfolio_items);
});
$active_carousel_group.remove();
},
});
$prev_carousel_group.addClass('active').css({ position: 'absolute', top: '0px', left: '-100%' });
$prev_carousel_group.animate({
left: '0%',
}, {
duration: slide_duration,
complete() {
setTimeout(() => {
$prev_carousel_group.removeClass('prev').addClass('active').css({ position: '', width: '', 'max-width': '', top: '', left: '' });
$prev_carousel_group.find('.delayed_container_append_dup').remove();
$prev_carousel_group.find('.changing_position').each(function(index) {
let position = $(this).data('position');
current_position = $(this).data('current_position');
prev_position = $(this).data('prev_position');
$(this).removeClass(`container_append delayed_container_append position_${position} ` + `changing_position current_position current_position_${current_position} prev_position prev_position_${prev_position}`);
$(this).data('current_position', '');
$(this).data('prev_position', '');
position = index + 1;
$(this).data('position', position);
$(this).addClass(`position_${position}`);
});
$portfolio_items.find('.et_pb_portfolio_item').removeClass('first_in_row last_in_row');
et_pb_set_responsive_grid($portfolio_items, '.et_pb_portfolio_item:visible');
$prev_carousel_group.children().css({ position: '', width: original_item_width, 'max-width': original_item_width, left: '' });
$the_portfolio.data('carouseling', false);
}, 100);
},
});
}
}
function set_fullwidth_portfolio_columns($the_portfolio, carousel_mode) {
let columns;
const $portfolio_items = $the_portfolio.find('.et_pb_portfolio_items');
const portfolio_items_width = $portfolio_items.width();
const $the_portfolio_items = $portfolio_items.find('.et_pb_portfolio_item');
const portfolio_item_count = $the_portfolio_items.length;
if ('undefined' === typeof $the_portfolio_items) {
return;
}
// calculate column breakpoints
if (portfolio_items_width >= 1600) {
columns = 5;
} else if (portfolio_items_width >= 1024) {
columns = 4;
} else if (portfolio_items_width >= 768) {
columns = 3;
} else if (portfolio_items_width >= 480) {
columns = 2;
} else {
columns = 1;
}
// set height of items
const portfolio_item_width = portfolio_items_width / columns;
const portfolio_item_height = portfolio_item_width * 0.75;
if (carousel_mode) {
$portfolio_items.css({ height: `${portfolio_item_height}px` });
}
$the_portfolio_items.css({ height: `${portfolio_item_height}px` });
if (columns === $portfolio_items.data('portfolio-columns')) {
return;
}
if ($the_portfolio.data('columns_setting_up')) {
return;
}
$the_portfolio.data('columns_setting_up', true);
const portfolio_item_width_percentage = `${100 / columns}%`;
$the_portfolio_items.css({ width: portfolio_item_width_percentage, 'max-width': portfolio_item_width_percentage });
// store last setup column
$portfolio_items.removeClass(`columns-${$portfolio_items.data('portfolio-columns')}`);
$portfolio_items.addClass(`columns-${columns}`);
$portfolio_items.data('portfolio-columns', columns);
if (! carousel_mode) {
return $the_portfolio.data('columns_setting_up', false);
}
// kill all previous groups to get ready to re-group
if ($portfolio_items.find('.et_pb_carousel_group').length) {
$the_portfolio_items.appendTo($portfolio_items);
$portfolio_items.find('.et_pb_carousel_group').remove();
}
// setup the grouping
const the_portfolio_items = $portfolio_items.data('items');
const $carousel_group = $('
').appendTo($portfolio_items);
if ('undefined' === typeof the_portfolio_items) {
return;
}
$the_portfolio_items.data('position', '');
if (the_portfolio_items.length <= columns) {
$portfolio_items.find('.et-pb-slider-arrows').hide();
} else {
$portfolio_items.find('.et-pb-slider-arrows').show();
}
for (let position = 1, x = 0; x < the_portfolio_items.length; x++, position++) {
if (x < columns) {
$(the_portfolio_items[x]).show();
$(the_portfolio_items[x]).appendTo($carousel_group);
$(the_portfolio_items[x]).data('position', position);
$(the_portfolio_items[x]).addClass(`position_${position}`);
} else {
position = $(the_portfolio_items[x]).data('position');
$(the_portfolio_items[x]).removeClass(`position_${position}`);
$(the_portfolio_items[x]).data('position', '');
$(the_portfolio_items[x]).hide();
}
}
$the_portfolio.data('columns_setting_up', false);
}
function et_carousel_auto_rotate($carousel) {
if ('on' === $carousel.data('auto-rotate') && $carousel.find('.et_pb_portfolio_item').length > $carousel.find('.et_pb_carousel_group .et_pb_portfolio_item').length && ! $carousel.hasClass('et_carousel_hovered')) {
const et_carousel_timer = setTimeout(() => {
fullwidth_portfolio_carousel_slide($carousel.find('.et-pb-arrow-next'));
}, $carousel.data('auto-rotate-speed'));
$carousel.data('et_carousel_timer', et_carousel_timer);
}
}
if ($et_pb_fullwidth_portfolio.length || isBuilder) {
window.et_fullwidth_portfolio_init = function($the_portfolio, $callback) {
const $portfolio_items = $the_portfolio.find('.et_pb_portfolio_items');
$portfolio_items.data('items', $portfolio_items.find('.et_pb_portfolio_item').toArray());
$the_portfolio.data('columns_setting_up', false);
if ($the_portfolio.hasClass('et_pb_fullwidth_portfolio_carousel')) {
// add left and right arrows
$portfolio_items.prepend(`${'
');
set_fullwidth_portfolio_columns($the_portfolio, true);
et_carousel_auto_rotate($the_portfolio);
// swipe support
$the_portfolio.on('swiperight', function() {
$(this).find('.et-pb-arrow-prev').trigger('click');
});
$the_portfolio.on('swipeleft', function() {
$(this).find('.et-pb-arrow-next').trigger('click');
});
$the_portfolio.on('mouseenter', function() {
$(this).addClass('et_carousel_hovered');
if (typeof $(this).data('et_carousel_timer') !== 'undefined') {
clearInterval($(this).data('et_carousel_timer'));
}
}).on('mouseleave', function() {
$(this).removeClass('et_carousel_hovered');
et_carousel_auto_rotate($(this));
});
$the_portfolio.data('carouseling', false);
$the_portfolio.on('click', '.et-pb-slider-arrows a', function(e) {
fullwidth_portfolio_carousel_slide($(this));
e.preventDefault();
return false;
});
} else {
// setup fullwidth portfolio grid
set_fullwidth_portfolio_columns($the_portfolio, false);
}
if ('function' === typeof $callback) {
$callback();
}
};
$et_pb_fullwidth_portfolio.each(function() {
et_fullwidth_portfolio_init($(this));
});
}
if ($('.et_pb_section_video').length) {
window._wpmejsSettings.pauseOtherPlayers = false;
}
if ($et_pb_filterable_portfolio.length || isBuilder) {
window.et_pb_filterable_portfolio_init = function($selector) {
if (typeof $selector !== 'undefined') {
set_filterable_portfolio_init($selector);
} else {
$et_pb_filterable_portfolio.each(function() {
set_filterable_portfolio_init($(this));
});
}
};
window.set_filterable_portfolio_init = function($the_portfolio, $callback) {
const $the_portfolio_items = $the_portfolio.find('.et_pb_portfolio_items');
const all_portfolio_items = $the_portfolio_items.clone(); // cache for all the portfolio items
$the_portfolio.show();
$the_portfolio.find('.et_pb_portfolio_item').addClass('active');
$the_portfolio.css('display', 'block');
window.set_filterable_grid_items($the_portfolio);
if ('function' === typeof $callback) {
$callback();
}
$the_portfolio.on('click', '.et_pb_portfolio_filter a', function(e) {
e.preventDefault();
const category_slug = $(this).data('category-slug');
const $the_portfolio = $(this).parents('.et_pb_filterable_portfolio');
const $the_portfolio_items = $the_portfolio.find('.et_pb_portfolio_items');
if ('all' == category_slug) {
$the_portfolio.find('.et_pb_portfolio_filter a').removeClass('active');
$the_portfolio.find('.et_pb_portfolio_filter_all a').addClass('active');
// remove all items from the portfolio items container
$the_portfolio_items.empty();
// fill the portfolio items container with cached items from memory
$the_portfolio_items.append(all_portfolio_items.find('.et_pb_portfolio_item').clone());
$the_portfolio.find('.et_pb_portfolio_item').addClass('active');
} else {
$the_portfolio.find('.et_pb_portfolio_filter_all').removeClass('active');
$the_portfolio.find('.et_pb_portfolio_filter a').removeClass('active');
$the_portfolio.find('.et_pb_portfolio_filter_all a').removeClass('active');
$(this).addClass('active');
// remove all items from the portfolio items container
$the_portfolio_items.empty();
// fill the portfolio items container with cached items from memory
$the_portfolio_items.append(all_portfolio_items.find(`.et_pb_portfolio_item.project_category_${$(this).data('category-slug')}`).clone());
$the_portfolio_items.find('.et_pb_portfolio_item').removeClass('active');
$the_portfolio_items.find(`.et_pb_portfolio_item.project_category_${$(this).data('category-slug')}`).addClass('active').removeClass('inactive');
}
window.set_filterable_grid_items($the_portfolio);
setTimeout(() => {
set_filterable_portfolio_hash($the_portfolio);
}, 500);
$the_portfolio.find('.et_pb_portfolio_item').removeClass('first_in_row last_in_row');
et_pb_set_responsive_grid($the_portfolio, '.et_pb_portfolio_item:visible');
});
$the_portfolio.on('click', '.et_pb_portofolio_pagination a', function(e) {
e.preventDefault();
let to_page = $(this).data('page');
const $the_portfolio = $(this).parents('.et_pb_filterable_portfolio');
const $the_portfolio_items = $the_portfolio.find('.et_pb_portfolio_items');
et_pb_smooth_scroll($the_portfolio, false, 800);
if ($(this).hasClass('page-prev')) {
to_page = parseInt($(this).parents('ul').find('a.active').data('page')) - 1;
} else if ($(this).hasClass('page-next')) {
to_page = parseInt($(this).parents('ul').find('a.active').data('page')) + 1;
}
$(this).parents('ul').find('a').removeClass('active');
$(this).parents('ul').find(`a.page-${to_page}`).addClass('active');
const current_index = $(this).parents('ul').find(`a.page-${to_page}`).parent()
.index();
const total_pages = $(this).parents('ul').find('li.page').length;
$(this).parent().nextUntil(`.page-${current_index + 3}`).show();
$(this).parent().prevUntil(`.page-${current_index - 3}`).show();
$(this).parents('ul').find('li.page').each(function(i) {
if (! $(this).hasClass('prev') && ! $(this).hasClass('next')) {
if (i < (current_index - 3)) {
$(this).hide();
} else if (i > (current_index + 1)) {
$(this).hide();
} else {
$(this).show();
}
if (total_pages - current_index <= 2 && total_pages - i <= 5) {
$(this).show();
} else if (current_index <= 3 && i <= 4) {
$(this).show();
}
}
});
if (to_page > 1) {
$(this).parents('ul').find('li.prev').show();
} else {
$(this).parents('ul').find('li.prev').hide();
}
if ($(this).parents('ul').find('a.active').hasClass('last-page')) {
$(this).parents('ul').find('li.next').hide();
} else {
$(this).parents('ul').find('li.next').show();
}
$the_portfolio.find('.et_pb_portfolio_item').hide();
$the_portfolio.find('.et_pb_portfolio_item').filter(function(index) {
return $(this).data('page') === to_page;
}).show();
window.et_pb_set_responsive_grid($the_portfolio.find('.et_pb_portfolio_items'), '.et_pb_portfolio_item');
setTimeout(() => {
set_filterable_portfolio_hash($the_portfolio);
}, 500);
$the_portfolio.find('.et_pb_portfolio_item').removeClass('first_in_row last_in_row');
et_pb_set_responsive_grid($the_portfolio, '.et_pb_portfolio_item:visible');
});
$(this).on('et_hashchange', event => {
const { params } = event;
$the_portfolio = $(`#${event.target.id}`);
if (! $the_portfolio.find(`.et_pb_portfolio_filter a[data-category-slug="${params[0]}"]`).hasClass('active')) {
$the_portfolio.find(`.et_pb_portfolio_filter a[data-category-slug="${params[0]}"]`).trigger('click');
}
if (params[1]) {
setTimeout(() => {
if (! $the_portfolio.find(`.et_pb_portofolio_pagination a.page-${params[1]}`).hasClass('active')) {
$the_portfolio.find(`.et_pb_portofolio_pagination a.page-${params[1]}`).addClass('active').trigger('click');
}
}, 300);
}
});
};
window.set_filterable_grid_items = function($the_portfolio) {
const active_category = $the_portfolio.find('.et_pb_portfolio_filter > a.active').data('category-slug');
let $the_portfolio_visible_items;
window.et_pb_set_responsive_grid($the_portfolio.find('.et_pb_portfolio_items'), '.et_pb_portfolio_item');
if ('all' === active_category) {
$the_portfolio_visible_items = $the_portfolio.find('.et_pb_portfolio_item');
} else {
$the_portfolio_visible_items = $the_portfolio.find(`.et_pb_portfolio_item.project_category_${active_category}`);
}
var visible_grid_items = $the_portfolio_visible_items.length;
const posts_number = $the_portfolio.data('posts-number');
const pages = 0 === posts_number ? 1 : Math.ceil(visible_grid_items / posts_number);
window.set_filterable_grid_pages($the_portfolio, pages);
var visible_grid_items = 0;
let _page = 1;
$the_portfolio.find('.et_pb_portfolio_item').data('page', '');
$the_portfolio_visible_items.each(function(i) {
visible_grid_items++;
if (0 === parseInt(visible_grid_items % posts_number)) {
$(this).data('page', _page);
_page++;
} else {
$(this).data('page', _page);
}
});
$the_portfolio_visible_items.filter(function() {
return 1 == $(this).data('page');
}).show();
$the_portfolio_visible_items.filter(function() {
return $(this).data('page') != 1;
}).hide();
};
window.set_filterable_grid_pages = function($the_portfolio, pages) {
const $pagination = $the_portfolio.find('.et_pb_portofolio_pagination');
if (! $pagination.length) {
return;
}
$pagination.html('
');
if (pages <= 1) {
return;
}
const $pagination_list = $pagination.children('ul');
$pagination_list.append(`
${et_pb_custom.prev}`);
for (let page = 1; page <= pages; page++) {
const first_page_class = 1 === page ? ' active' : '';
const last_page_class = page === pages ? ' last-page' : '';
const hidden_page_class = page >= 5 ? ' style="display:none;"' : '';
$pagination_list.append(`
${page}`);
}
$pagination_list.append(`
${et_pb_custom.next}`);
};
function set_filterable_portfolio_hash($the_portfolio) {
if (! $the_portfolio.attr('id')) {
return;
}
let this_portfolio_state = [];
this_portfolio_state.push($the_portfolio.attr('id'));
this_portfolio_state.push($the_portfolio.find('.et_pb_portfolio_filter > a.active').data('category-slug'));
if ($the_portfolio.find('.et_pb_portofolio_pagination a.active').length) {
this_portfolio_state.push($the_portfolio.find('.et_pb_portofolio_pagination a.active').data('page'));
} else {
this_portfolio_state.push(1);
}
this_portfolio_state = this_portfolio_state.join(et_hash_module_param_seperator);
et_set_hash(this_portfolio_state);
}
// init portfolio if .on('load') event was fired already, wait for the window load otherwise.
if (window.et_load_event_fired) {
et_pb_filterable_portfolio_init();
} else {
$(window).on('load', () => {
et_pb_filterable_portfolio_init();
}); // End $(window).on('load')
}
} /* end if ( $et_pb_filterable_portfolio.length ) */
if ($et_pb_gallery.length || isBuilder) {
window.set_gallery_grid_items = function($the_gallery) {
const $the_gallery_items_container = $the_gallery.find('.et_pb_gallery_items');
const $the_gallery_items = $the_gallery_items_container.find('.et_pb_gallery_item');
var total_grid_items = $the_gallery_items.length;
const posts_number_original = parseInt($the_gallery_items_container.attr('data-per_page'));
const posts_number = isNaN(posts_number_original) || 0 === posts_number_original ? 4 : posts_number_original;
const pages = Math.ceil(total_grid_items / posts_number);
window.et_pb_set_responsive_grid($the_gallery_items_container, '.et_pb_gallery_item');
set_gallery_grid_pages($the_gallery, pages);
var total_grid_items = 0;
let _page = 1;
$the_gallery_items.data('page', '');
$the_gallery_items.each(function(i) {
total_grid_items++;
// Do some caching
const $this = $(this);
if (0 === parseInt(total_grid_items % posts_number)) {
$this.data('page', _page);
_page++;
} else {
$this.data('page', _page);
}
});
const visible_items = $the_gallery_items.filter(function() {
return 1 == $(this).data('page');
}).show();
$the_gallery_items.filter(function() {
return $(this).data('page') != 1;
}).hide();
};
window.set_gallery_grid_pages = function($the_gallery, pages) {
const $pagination = $the_gallery.find('.et_pb_gallery_pagination');
if (! $pagination.length) {
return;
}
$pagination.html('
');
if (pages <= 1) {
$pagination.hide();
return;
}
const $pagination_list = $pagination.children('ul');
$pagination_list.append(`
${et_pb_custom.prev}`);
for (let page = 1; page <= pages; page++) {
const first_page_class = 1 === page ? ' active' : '';
const last_page_class = page === pages ? ' last-page' : '';
const hidden_page_class = page >= 5 ? ' style="display:none;"' : '';
$pagination_list.append(`
${page}`);
}
$pagination_list.append(`
${et_pb_custom.next}`);
};
window.set_gallery_hash = function($the_gallery) {
if (! $the_gallery.attr('id')) {
return;
}
let this_gallery_state = [];
this_gallery_state.push($the_gallery.attr('id'));
if ($the_gallery.find('.et_pb_gallery_pagination a.active').length) {
this_gallery_state.push($the_gallery.find('.et_pb_gallery_pagination a.active').data('page'));
} else {
this_gallery_state.push(1);
}
this_gallery_state = this_gallery_state.join(et_hash_module_param_seperator);
et_set_hash(this_gallery_state);
};
window.et_pb_gallery_init = function($the_gallery) {
if ($the_gallery.hasClass('et_pb_gallery_grid')) {
$the_gallery.show();
set_gallery_grid_items($the_gallery);
$the_gallery.on('et_hashchange', event => {
const { params } = event;
$the_gallery = $(`#${event.target.id}`);
const page_to = params[0];
if ((page_to)) {
if (! $the_gallery.find(`.et_pb_gallery_pagination a.page-${page_to}`).hasClass('active')) {
$the_gallery.find(`.et_pb_gallery_pagination a.page-${page_to}`).addClass('active').trigger('click');
}
}
});
}
};
$et_pb_gallery.each(function() {
const $the_gallery = $(this);
et_pb_gallery_init($the_gallery);
});
$et_pb_gallery.data('paginating', false);
window.et_pb_gallery_pagination_nav = function($the_gallery) {
$the_gallery.on('click', '.et_pb_gallery_pagination a', function(e) {
e.preventDefault();
let to_page = $(this).data('page');
const $the_gallery = $(this).parents('.et_pb_gallery');
const $the_gallery_items_container = $the_gallery.find('.et_pb_gallery_items');
const $the_gallery_items = $the_gallery_items_container.find('.et_pb_gallery_item');
if ($the_gallery.data('paginating')) {
return;
}
$the_gallery.data('paginating', true);
if ($(this).hasClass('page-prev')) {
to_page = parseInt($(this).parents('ul').find('a.active').data('page')) - 1;
} else if ($(this).hasClass('page-next')) {
to_page = parseInt($(this).parents('ul').find('a.active').data('page')) + 1;
}
$(this).parents('ul').find('a').removeClass('active');
$(this).parents('ul').find(`a.page-${to_page}`).addClass('active');
const current_index = $(this).parents('ul').find(`a.page-${to_page}`).parent()
.index();
const total_pages = $(this).parents('ul').find('li.page').length;
$(this).parent().nextUntil(`.page-${current_index + 3}`).show();
$(this).parent().prevUntil(`.page-${current_index - 3}`).show();
$(this).parents('ul').find('li.page').each(function(i) {
if (! $(this).hasClass('prev') && ! $(this).hasClass('next')) {
if (i < (current_index - 3)) {
$(this).hide();
} else if (i > (current_index + 1)) {
$(this).hide();
} else {
$(this).show();
}
if (total_pages - current_index <= 2 && total_pages - i <= 5) {
$(this).show();
} else if (current_index <= 3 && i <= 4) {
$(this).show();
}
}
});
if (to_page > 1) {
$(this).parents('ul').find('li.prev').show();
} else {
$(this).parents('ul').find('li.prev').hide();
}
if ($(this).parents('ul').find('a.active').hasClass('last-page')) {
$(this).parents('ul').find('li.next').hide();
} else {
$(this).parents('ul').find('li.next').show();
}
$the_gallery_items.hide();
const visible_items = $the_gallery_items.filter(function(index) {
return $(this).data('page') === to_page;
}).show();
$the_gallery.data('paginating', false);
window.et_pb_set_responsive_grid($the_gallery_items_container, '.et_pb_gallery_item');
setTimeout(() => {
set_gallery_hash($the_gallery);
}, 100);
});
};
et_pb_gallery_pagination_nav($et_pb_gallery);
// Frontend builder's interface wouldn't be able to use $et_pb_gallery as selector
// due to its react component's nature. Using more global selector works.
if (isBuilder) {
et_pb_gallery_pagination_nav($('#et-fb-app'));
}
} /* end if ( $et_pb_gallery.length ) */
if ($et_pb_counter_amount.length) {
$et_pb_counter_amount.each(function() {
window.et_bar_counters_init($(this));
});
} /* $et_pb_counter_amount.length */
window.et_countdown_timer = function(timer) {
const end_date = parseInt(timer.attr('data-end-timestamp'));
const current_date = new Date().getTime() / 1000;
let seconds_left = (end_date - current_date);
let days = parseInt(seconds_left / 86400);
days = days > 0 ? days : 0;
seconds_left %= 86400;
let hours = parseInt(seconds_left / 3600);
hours = hours > 0 ? hours : 0;
seconds_left %= 3600;
let minutes = parseInt(seconds_left / 60);
minutes = minutes > 0 ? minutes : 0;
let seconds = parseInt(seconds_left % 60);
seconds = seconds > 0 ? seconds : 0;
const $days_section = timer.find('.days > .value').parent('.section');
const $hours_section = timer.find('.hours > .value').parent('.section');
const $minutes_section = timer.find('.minutes > .value').parent('.section');
const $seconds_section = timer.find('.seconds > .value').parent('.section');
if (0 == days) {
if (! $days_section.hasClass('zero')) {
timer.find('.days > .value').html('000').parent('.section').addClass('zero')
.next()
.addClass('zero');
}
} else {
const days_slice = days.toString().length >= 3 ? days.toString().length : 3;
timer.find('.days > .value').html((`000${days}`).slice(- days_slice));
if ($days_section.hasClass('zero')) {
$days_section.removeClass('zero').next().removeClass('zero');
}
}
if (0 === days && 0 === hours) {
if (! $hours_section.hasClass('zero')) {
timer.find('.hours > .value').html('00').parent('.section').addClass('zero')
.next()
.addClass('zero');
}
} else {
timer.find('.hours > .value').html((`0${hours}`).slice(- 2));
if ($hours_section.hasClass('zero')) {
$hours_section.removeClass('zero').next().removeClass('zero');
}
}
if (0 === days && 0 === hours && 0 === minutes) {
if (! $minutes_section.hasClass('zero')) {
timer.find('.minutes > .value').html('00').parent('.section').addClass('zero')
.next()
.addClass('zero');
}
} else {
timer.find('.minutes > .value').html((`0${minutes}`).slice(- 2));
if ($minutes_section.hasClass('zero')) {
$minutes_section.removeClass('zero').next().removeClass('zero');
}
}
if (0 === days && 0 === hours && 0 === minutes && 0 === seconds) {
if (! $seconds_section.hasClass('zero')) {
timer.find('.seconds > .value').html('00').parent('.section').addClass('zero');
}
} else {
timer.find('.seconds > .value').html((`0${seconds}`).slice(- 2));
if ($seconds_section.hasClass('zero')) {
$seconds_section.removeClass('zero').next().removeClass('zero');
}
}
};
window.et_countdown_timer_labels = function(timer) {
if (timer.closest('.et_pb_column_3_8').length || timer.closest('.et_pb_column_1_4').length || timer.children('.et_pb_countdown_timer_container').width() <= 400) {
timer.find('.days .label').html(timer.find('.days').data('short'));
timer.find('.hours .label').html(timer.find('.hours').data('short'));
timer.find('.minutes .label').html(timer.find('.minutes').data('short'));
timer.find('.seconds .label').html(timer.find('.seconds').data('short'));
} else {
timer.find('.days .label').html(timer.find('.days').data('full'));
timer.find('.hours .label').html(timer.find('.hours').data('full'));
timer.find('.minutes .label').html(timer.find('.minutes').data('full'));
timer.find('.seconds .label').html(timer.find('.seconds').data('full'));
}
};
if ($et_pb_countdown_timer.length || isBuilder) {
window.et_pb_countdown_timer_init = function($et_pb_countdown_timer) {
$et_pb_countdown_timer.each(function() {
const timer = $(this);
et_countdown_timer_labels(timer);
et_countdown_timer(timer);
setInterval(() => {
et_countdown_timer(timer);
}, 1000);
});
};
et_pb_countdown_timer_init($et_pb_countdown_timer);
}
window.et_pb_tabs_init = function($et_pb_tabs_all) {
const init_hash_for_tab = function($et_pb_tabs) {
const { hash } = window.location;
if ('' !== hash) {
let hash_value = hash.replace( '#', '' );
hash_value = /^tab\-/.test( hash_value ) ? hash_value : `tab-${hash_value}`;
const $et_pb_hash_el = $et_pb_tabs.find(`.et_pb_tabs_controls li a[href="#${hash_value}"]`);
if ($et_pb_hash_el.length) {
$et_pb_hash_el.parent().trigger('click');
}
}
};
$et_pb_tabs_all.each(function() {
const $et_pb_tabs = $(this);
const $et_pb_tabs_li = $et_pb_tabs.find('.et_pb_tabs_controls li');
const active_slide = isTB || isBFB || isVB ? 0 : $et_pb_tabs.find('.et_pb_tab_active').index();
const slider_options = {
use_controls: false,
use_arrows: false,
slide: '.et_pb_all_tabs > div',
tabs_animation: true,
};
if (0 !== active_slide) {
slider_options.active_slide = active_slide;
}
$et_pb_tabs.et_pb_simple_slider(slider_options).on('et_hashchange', event => {
const { params } = event;
const $the_tabs = $(`#${event.target.id}`);
const active_tab = params[0];
if (! $the_tabs.find('.et_pb_tabs_controls li').eq(active_tab).hasClass('et_pb_tab_active')) {
$the_tabs.find('.et_pb_tabs_controls li').eq(active_tab).trigger('click');
}
});
$et_pb_tabs_li.on('click', function() {
const $this_el = $(this);
const $tabs_container = $this_el.closest('.et_pb_tabs').data('et_pb_simple_slider');
if ($tabs_container.et_animation_running) return false;
$this_el.addClass('et_pb_tab_active').siblings().removeClass('et_pb_tab_active');
$tabs_container.data('et_pb_simple_slider').et_slider_move_to($this_el.index());
if ($this_el.closest('.et_pb_tabs').attr('id')) {
let tab_state = [];
tab_state.push($this_el.closest('.et_pb_tabs').attr('id'));
tab_state.push($this_el.index());
tab_state = tab_state.join(et_hash_module_param_seperator);
et_set_hash(tab_state);
}
return false;
});
init_hash_for_tab($et_pb_tabs);
window.et_pb_set_tabs_height();
});
};
if ($et_pb_tabs.length || isBuilder) {
window.et_pb_tabs_init($et_pb_tabs);
}
if ($et_pb_map.length || isBuilder) {
function et_pb_init_maps() {
$et_pb_map.each(function() {
et_pb_map_init($(this));
});
}
window.et_pb_map_init = function($this_map_container) {
if ('undefined' === typeof google || 'undefined' === typeof google.maps) {
return;
}
const current_mode = et_pb_get_current_window_mode();
et_animation_breakpoint = current_mode;
const suffix = current_mode !== 'desktop' ? `-${current_mode}` : '';
const prev_suffix = 'phone' === current_mode ? '-tablet' : '';
let grayscale_value = $this_map_container.attr(`data-grayscale${suffix}`) || 0;
if (! grayscale_value) {
grayscale_value = $this_map_container.attr(`data-grayscale${prev_suffix}`) || $this_map_container.attr('data-grayscale') || 0;
}
const $this_map = $this_map_container.children('.et_pb_map');
let this_map_grayscale = grayscale_value;
const is_draggable = (et_is_mobile_device && $this_map.data('mobile-dragging') !== 'off') || ! et_is_mobile_device;
let infowindow_active;
if (this_map_grayscale !== 0) {
this_map_grayscale = `-${this_map_grayscale.toString()}`;
}
// Being saved to pass lat and lang of center location.
const data_center_lat = parseFloat($this_map.attr('data-center-lat')) || 0;
const data_center_lng = parseFloat($this_map.attr('data-center-lng')) || 0;
$this_map_container.data('map', new google.maps.Map($this_map[0], {
zoom: parseInt($this_map.attr('data-zoom')),
center: new google.maps.LatLng(data_center_lat, data_center_lng),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: 'on' == $this_map.attr('data-mouse-wheel'),
draggable: is_draggable,
panControlOptions: {
position: $this_map_container.is('.et_beneath_transparent_nav') ? google.maps.ControlPosition.LEFT_BOTTOM : google.maps.ControlPosition.LEFT_TOP,
},
zoomControlOptions: {
position: $this_map_container.is('.et_beneath_transparent_nav') ? google.maps.ControlPosition.LEFT_BOTTOM : google.maps.ControlPosition.LEFT_TOP,
},
styles: [{
stylers: [
{ saturation: parseInt(this_map_grayscale) },
],
}],
}));
$this_map_container.find('.et_pb_map_pin').each(function() {
const $this_marker = $(this);
const marker = new google.maps.Marker({
position: new google.maps.LatLng(parseFloat($this_marker.attr('data-lat')), parseFloat($this_marker.attr('data-lng'))),
map: $this_map_container.data('map'),
title: $this_marker.attr('data-title'),
icon: { url: `${et_pb_custom.builder_images_uri}/marker.png`, size: new google.maps.Size(46, 43), anchor: new google.maps.Point(16, 43) },
shape: { coord: [1, 1, 46, 43], type: 'rect' },
anchorPoint: new google.maps.Point(0, - 45),
});
if ($this_marker.find('.infowindow').length) {
const infowindow = new google.maps.InfoWindow({
content: $this_marker.html(),
});
google.maps.event.addListener($this_map_container.data('map'), 'click', () => {
infowindow.close();
});
google.maps.event.addListener(marker, 'click', () => {
if (infowindow_active) {
infowindow_active.close();
}
infowindow_active = infowindow;
infowindow.open($this_map_container.data('map'), marker);
// Trigger mouse hover event for responsive content swap.
$this_marker.closest('.et_pb_module').trigger('mouseleave');
setTimeout(() => {
$this_marker.closest('.et_pb_module').trigger('mouseenter');
}, 1);
});
}
});
};
if (window.et_load_event_fired) {
et_pb_init_maps();
} else if (typeof google !== 'undefined' && typeof google.maps !== 'undefined') {
google.maps.event.addDomListener(window, 'load', () => {
et_pb_init_maps();
});
}
}
$('.et_pb_shop, .et_pb_wc_upsells, .et_pb_wc_related_products').each(function() {
let $this_el = $(this);
let icon = isUndefined($this_el.data('icon')) || '' === $this_el.data('icon') ? '' : $this_el.data('icon');
let icon_tablet = isUndefined($this_el.data('icon-tablet')) || '' === $this_el.data('icon-tablet') ? '' : $this_el.data('icon-tablet');
let icon_phone = isUndefined($this_el.data('icon-phone')) || '' === $this_el.data('icon-phone') ? '' : $this_el.data('icon-phone');
let icon_sticky = isUndefined($this_el.data('icon-sticky')) || '' === $this_el.data('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 = isUndefined($this_el.data('icon')) || '' === $this_el.data('icon') ? '' : $this_el.data('icon');
icon_tablet = isUndefined($this_el.data('icon-tablet')) || '' === $this_el.data('icon-tablet') ? '' : $this_el.data('icon-tablet');
icon_phone = isUndefined($this_el.data('icon-phone')) || '' === $this_el.data('icon-phone') ? '' : $this_el.data('icon-phone');
icon_sticky = isUndefined($this_el.data('icon-sticky')) || '' === $this_el.data('icon-sticky') ? '' : $this_el.data('icon-sticky');
}
// 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);
}
});
});
if ($et_pb_circle_counter.length || isBuilder || $('.et_pb_ajax_pagination_container').length > 0) {
window.et_pb_circle_counter_init = function($the_counter, animate, custom_mode) {
if ($the_counter.width() <= 0) {
return;
}
// Update animation breakpoint variable and generate suffix.
const current_mode = et_pb_get_current_window_mode();
et_animation_breakpoint = current_mode;
// Custom Mode is used to pass custom preview mode such as hover. Current mode is
// actual preview mode based on current window size.
let suffix = '';
if ('undefined' !== typeof custom_mode && '' !== custom_mode) {
suffix = `-${custom_mode}`;
} else if (current_mode !== 'desktop') {
suffix = `-${current_mode}`;
}
// Update bar background color based on active mode.
let bar_color = $the_counter.data('bar-bg-color');
const mode_bar_color = $the_counter.data(`bar-bg-color${suffix}`);
if (typeof mode_bar_color !== 'undefined' && mode_bar_color !== '') {
bar_color = mode_bar_color;
}
// Update bar track color based on active mode.
let track_color = $the_counter.data('color') || '#000000';
const mode_track_color = $the_counter.data(`color${suffix}`);
if (typeof mode_track_color !== 'undefined' && mode_track_color !== '') {
track_color = mode_track_color;
}
// Update bar track color alpha based on active mode.
let track_color_alpha = $the_counter.data('alpha') || '0.1';
const mode_track_color_alpha = $the_counter.data(`alpha${suffix}`);
if ('undefined' !== typeof mode_track_color_alpha && '' !== mode_track_color_alpha && ! isNaN(mode_track_color_alpha)) {
track_color_alpha = mode_track_color_alpha;
}
$the_counter.easyPieChart({
animate: {
duration: 1800,
enabled: true,
},
size: 0 !== $the_counter.width() ? $the_counter.width() : 10, // set the width to 10 if actual width is 0 to avoid js errors
barColor: bar_color,
trackColor: track_color,
trackAlpha: track_color_alpha,
scaleColor: false,
lineWidth: 5,
onStart() {
$(this.el).find('.percent p').css({ visibility: 'visible' });
},
onStep(from, to, percent) {
$(this.el).find('.percent-value').text(Math.round(parseInt(percent)));
},
onStop(from, to) {
$(this.el).find('.percent-value').text($(this.el).data('number-value'));
},
});
};
window.et_pb_reinit_circle_counters = function($et_pb_circle_counter) {
$et_pb_circle_counter.each(function() {
let $the_counter = $(this).find('.et_pb_circle_counter_inner');
window.et_pb_circle_counter_init($the_counter, false);
// Circle Counter on Hover.
$the_counter.on('mouseover', event => {
window.et_pb_circle_counter_update($the_counter, event, 'hover');
});
// Circle Counter on "Unhover" as reset of Hover effect.
$the_counter.on('mouseleave', event => {
window.et_pb_circle_counter_update($the_counter, event);
});
$the_counter.on('containerWidthChanged', (event, custom_mode) => {
$the_counter = $(event.target);
$the_counter.find('canvas').remove();
$the_counter.removeData('easyPieChart');
window.et_pb_circle_counter_init($the_counter, true, custom_mode);
});
// Update circle counter when sticky is started / ended
const stickyId = $the_counter.attr('data-sticky-id');
if (stickyId) {
window.addEventListener('ETBuilderStickyStart', e => {
if (stickyId === e.detail.stickyId) {
window.et_pb_circle_counter_update($the_counter, event, 'sticky');
}
});
window.addEventListener('ETBuilderStickyEnd', e => {
if (stickyId === e.detail.stickyId) {
window.et_pb_circle_counter_update($the_counter, event);
}
});
}
});
};
window.et_pb_reinit_circle_counters($et_pb_circle_counter);
}
/**
* Update circle counter easyPieChart data on custom mode.
*
* @since 3.25.3
*
* @param {jQuery} $this_counter Circle counter jQuery element.
* @param {object} event Event object.
* @param {string} custom_mode Custom view mode such as hover/desktop/tablet/phone.
*/
window.et_pb_circle_counter_update = function($this_counter, event, custom_mode) {
if (! $this_counter.is(':visible') || 'undefined' === typeof $this_counter.data('easyPieChart')) {
return;
}
// Change custom mode if upon mouse leave, it returns to sticky, not standard state
if ('mouseleave' === event.type && $this_counter.closest('.et_pb_sticky').length > 0) {
custom_mode = 'sticky';
}
// Check circle attributes value for current event type.
if ($(event.target).length > 0) {
if ('mouseover' === event.type || 'mouseleave' === event.type) {
let has_field_value = false;
// Check if one of those field value exist.
const mode_bar_color = $this_counter.data('bar-bg-color-hover');
const mode_track_color = $this_counter.data('color-hover');
const mode_track_color_alpha = $this_counter.data('alpha-hover');
if (typeof mode_bar_color !== 'undefined' && mode_bar_color !== '') {
has_field_value = true;
} else if (typeof mode_track_color !== 'undefined' && mode_track_color !== '') {
has_field_value = true;
} else if (typeof mode_track_color_alpha !== 'undefined' && mode_track_color_alpha !== '') {
has_field_value = true;
}
if (! has_field_value) {
return;
}
}
}
// Reinit circle counter for current event.
let container_param = [];
if ('undefined' !== typeof custom_mode && '' !== custom_mode) {
container_param = [custom_mode];
}
$this_counter.trigger('containerWidthChanged', container_param);
// If number text hasn't been printed at all in sticky event, skip disable animation
// and updating number value data because this will overwrite entire text animation
// and causing the text not rendered; this happens if the page is not positioned
// on top document when loaded and already trigger start sticky event
const isStickyEvent = ['ETBuilderStickyStart', 'ETBuilderStickyEnd'].includes(event.type);
if (isStickyEvent && '' === $this_counter.find('.percent-value').text()) {
return;
}
// Animation should be disabled here.
$this_counter.data('easyPieChart').disableAnimation();
$this_counter.data('easyPieChart').update($this_counter.data('number-value'));
};
if ($et_pb_number_counter.length || isBuilder || $('.et_pb_ajax_pagination_container').length > 0) {
window.et_pb_reinit_number_counters = function($et_pb_number_counter) {
const is_firefox = $('body').hasClass('gecko');
function et_format_number(number_value, separator) {
return number_value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
}
if ($.fn.fitText) {
$et_pb_number_counter.find('.percent p').fitText(0.3);
}
$et_pb_number_counter.each(function() {
const $this_counter = $(this);
const separator = $this_counter.data('number-separator');
$this_counter.easyPieChart({
animate: {
duration: 1800,
enabled: true,
},
size: is_firefox ? 1 : 0, // firefox can't print page when it contains 0 sized canvas elements.
trackColor: false,
scaleColor: false,
lineWidth: 0,
onStart(from, to) {
$(this.el).addClass('active');
if (from === to) {
$(this.el).find('.percent-value').text(et_format_number($(this.el).data('number-value'), separator));
}
},
onStep(from, to, percent) {
if (percent != to) $(this.el).find('.percent-value').text(et_format_number(Math.round(parseInt(percent)), separator));
},
onStop(from, to) {
$(this.el).find('.percent-value').text(et_format_number($(this.el).data('number-value'), separator));
},
});
});
};
window.et_pb_reinit_number_counters($et_pb_number_counter);
}
window.et_apply_parallax = function() {
if (! $(this).length || 'undefined' === typeof $(this) || 'undefined' === typeof $(this).offset()) {
return;
}
let $parallaxWindow = $et_top_window;
if (isTB) {
$parallaxWindow = top_window.jQuery('#et-fb-app');
} else if (isScrollOnAppWindow()) {
$parallaxWindow = $(window);
}
const $this = $(this);
const $parent = $this.parent();
let element_top = isBuilderModeZoom() ? $this.offset().top / 2 : $this.offset().top;
const window_top = $parallaxWindow.scrollTop();
if ($parent.hasClass('et_is_animating')) {
return;
}
if (isBlockLayoutPreview) {
// Preview offset is what is changing on gutenberg due to window scroll
// happens on `.edit-post-layout__content`
const blockPreviewId = `#divi-layout-iframe-${ETBlockLayoutModulesScript.blockId}`;
const previewOffsetTop = top_window.jQuery(blockPreviewId).offset().top;
element_top += previewOffsetTop;
}
const y_pos = (((window_top + $et_top_window.height()) - element_top) * 0.3);
let main_position;
let $parallax_container;
main_position = `translate(0, ${y_pos}px)`;
// handle specific parallax container in VB
if ($this.children('.et_parallax_bg_wrap').length > 0) {
$parallax_container = $this.children('.et_parallax_bg_wrap').find('.et_parallax_bg');
} else {
$parallax_container = $this.children('.et_parallax_bg');
}
$parallax_container.css({
'-webkit-transform': main_position,
'-moz-transform': main_position,
'-ms-transform': main_position,
transform: main_position,
});
};
window.et_parallax_set_height = function() {
const $this = $(this);
const isFullscreen = isBuilder && $this.parent('.et_pb_fullscreen').length;
const parallaxHeight = isFullscreen && $et_top_window.height() > $this.innerHeight() ? $et_top_window.height() : $this.innerHeight();
let bg_height = ($et_top_window.height() * 0.3 + parallaxHeight);
// Add BFB metabox to top window offset on parallax image height to avoid parallax displays its
// background while scrolling because the image height is too short. This is required since BFB
// tracks parent window scroll event and BFB metabox has offset top to the top window
if (isBFB) {
bg_height += top_window.jQuery('#et_pb_layout .inside').offset().top;
}
$this.find('.et_parallax_bg').css({ height: `${bg_height}px` });
};
// Emulate CSS Parallax (background-attachment: fixed) effect via absolute image positioning
window.et_apply_builder_css_parallax = function() {
// This callback is for builder and layout block preview
if (! isBuilder && ! isBlockLayoutPreview) {
return;
}
const $this_parent = $(this);
const $this_parallax = $this_parent.children('.et_parallax_bg');
// Remove inline styling to avoid unwanted result first
$this_parallax.css({
width: '',
height: '',
top: '',
left: '',
backgroundAttachment: '',
});
// Bail if window scroll happens on app window (visual builder desktop mode)
if (isScrollOnAppWindow() && ! isTB) {
return;
}
let $parallaxWindow = isTB ? top_window.jQuery('#et-fb-app') : $et_top_window;
let parallaxWindowScrollTop = $parallaxWindow.scrollTop();
let backgroundOffset = isBFB ? top_window.jQuery('#et_pb_layout .inside').offset().top : 0;
const heightMultiplier = isBuilderModeZoom() ? 2 : 1;
const parentOffset = $this_parent.offset();
const parentOffsetTop = isBuilderModeZoom() ? parentOffset.top / 2 : parentOffset.top;
if (isBlockLayoutPreview) {
// Important: in gutenberg, scroll doesn't happen on window; it's here instead
$parallaxWindow = top_window.jQuery(getContentAreaSelector(top_window, true));
// Background offset is relative to block's preview iframe
backgroundOffset = top_window.jQuery(`#divi-layout-iframe-${ETBlockLayoutModulesScript.blockId}`).offset().top;
// Scroll happens on DOM which has fixed positioning. Hence
parallaxWindowScrollTop = $parallaxWindow.offset().top;
}
$this_parallax.css({
width: `${$(window).width()}px`,
height: `${$parallaxWindow.innerHeight() * heightMultiplier}px`,
top: `${(parallaxWindowScrollTop - backgroundOffset) - parentOffsetTop}px`,
left: `${0 - parentOffset.left}px`,
backgroundAttachment: 'scroll',
});
};
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' !== 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;
}
}
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(/