var TH90_SCRIPTS = (function(Mod, $) {
'use strict';
Mod.isDuringAjax = false;
Mod.$singleScrollDelay = 1;
Mod.isUriLightbox = function(uri) {
uri = uri.split("?")[0];
var parts = uri.split("."),
extension = parts[parts.length - 1],
lightboxTypes = ['jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp', 'webp'];
if (lightboxTypes.indexOf(extension) !== -1) {
return true;
} else {
return false;
}
};
Mod.init = function() {
this.offCanvas();
this.mobileMenu();
this.searchPopup();
this.newsletterPopup();
this.scrollToTop();
this.stickyHeader();
this.readingIndicator();
this.dropdownMobileMenu();
this.switchSkin('');
this.switchSkinClick();
this.ajaxBlockPagi();
this.ajaxBlockInfinite();
this.ajaxBlockFilters();
this.ajaxBlockSorts();
this.ajaxInfiniteSingle();
this.dynamicSelectOpt();
this.numberPlusMinus();
this.dropdownClick();
this.commentCollapse();
this.gutenbergAlignFull();
this.responsiveVideo();
this.sliderSwiper(jQuery('.th90-slider'));
this.newsticker(jQuery('.block-ticker'));
this.megamenu(jQuery('.have-megamenu'));
this.dropdown();
this.ajaxReload();
};
Mod.ajaxReload = function() {
this.lightbox();
this.masonryRun(jQuery('.columns-masonry'));
this.videoBgResize(jQuery('.box-holder'));
};
Mod.reinitiateFunctions = function() {
jQuery('html, body').off();
jQuery(document).off();
jQuery(window).trigger('load');
this.init();
};
Mod.gutenbergAlignFull = function() {
var self = this;
if (jQuery('.alignfull')[0]) {
jQuery('.alignfull').each(function(e) {
var scrollbarWidth = parseInt(window.innerWidth - document.documentElement.clientWidth);
jQuery(this).css('padding', '0 ' + (scrollbarWidth / 2) + 'px');
});
}
}
Mod.commentCollapse = function() {
var self = this;
jQuery('.comment-collapse').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
jQuery(this).velocity({
opacity: [0, 1],
translateY: -20,
}, {
display: 'none',
duration: 300,
complete: function() {
jQuery(this).siblings('.entry-comments').velocity({
opacity: [1, 0],
translateY: [0, -75],
}, {
duration: 300,
display: 'block',
});
}
});
});
};
Mod.offCanvas = function() {
var self = this;
jQuery(document).on('click', '.offcanvas-trigger', function(e) {
e.preventDefault();
self.showoffCanvas();
});
jQuery('.offcanvas-overlay, .offcanvas-close').on('click', function(e) {
e.preventDefault();
self.hideoffCanvas();
});
};
Mod.showoffCanvas = function() {
var self = this,
$from = '-100%';
if ('right' == th90.offcanvas_showfrom) {
if (th90.is_rtl) {
$from = '-100%';
} else {
$from = '100%';
}
} else {
if (th90.is_rtl) {
$from = '100%';
} else {
$from = '-100%';
}
}
jQuery('.offcanvas-overlay').velocity({
opacity: [1, 0]
}, {
duration: 100,
display: 'block',
complete: function() {
jQuery('.offcanvas').velocity({
translateX: [0, [0.86, 0, 0.07, 1], $from],
opacity: [1, "easeInSine", 0],
}, {
visibility: 'visible',
duration: 300,
complete: function(elements) {
jQuery(elements).css('pointer-events', 'all');
}
});
}
});
};
Mod.hideoffCanvas = function() {
var self = this;
jQuery('.offcanvas').velocity('reverse', {
visibility: 'hidden',
complete: function(elements) {
jQuery(elements).css('pointer-events', 'none');
jQuery('.offcanvas-overlay').velocity('reverse', {
display: 'none',
});
}
});
};
Mod.searchPopup = function() {
var self = this;
jQuery(document).on('click', '.search-trigger', function(e) {
e.preventDefault();
self.showSearchPopup();
});
jQuery('.search-popup-close, .search-overlay').on('click', function(e) {
e.preventDefault();
self.hideSearchPopup();
});
};
Mod.showSearchPopup = function() {
jQuery('.search-overlay').velocity({
opacity: [1, 0]
}, {
duration: 100,
display: 'flex',
complete: function() {
jQuery('.search-popup').velocity({
translateY: [0, [0.86, 0, 0.07, 1], '-100%'],
}, {
display: 'flex',
duration: 300,
complete: function() {
jQuery('.search-popup').addClass('input-ready');
jQuery('.search-popup-form input[type="search"]').focus();
}
});
}
});
};
Mod.hideSearchPopup = function() {
jQuery('.search-popup').removeClass('input-ready');
jQuery('.search-popup-form input[type="search"]').blur();
jQuery('.search-popup').velocity('reverse', {
display: 'none',
complete: function() {
jQuery('.search-overlay').velocity('reverse', {
display: 'none',
});
}
});
};
Mod.newsletterPopup = function() {
var self = this;
jQuery(document).on('click', '.subscribe-trigger', function(e) {
e.preventDefault();
self.showNewsletterPopup();
});
jQuery('.newsletter-popup-close, .newsletter-overlay').on('click', function(e) {
e.preventDefault();
self.hideNewsletterPopup();
});
};
Mod.showNewsletterPopup = function() {
jQuery('.newsletter-popup').velocity({
opacity: [1, 0]
}, {
duration: 100,
display: 'flex',
complete: function() {
jQuery('.th90-newsletter').velocity({
opacity: [1, 0],
translateY: [0, -75],
}, {
display: 'flex',
duration: 200,
});
}
});
};
Mod.hideNewsletterPopup = function() {
jQuery('.th90-newsletter').velocity('reverse', {
display: 'none',
complete: function() {
jQuery('.newsletter-popup').velocity('reverse', {
display: 'none',
});
}
});
};
Mod.mobileMenu = function() {
var self = this;
jQuery(document).on('click', '.mobilemenu-trigger', function(e) {
e.preventDefault();
self.hideNewsletterPopup();
self.hideoffCanvas();
self.hideSearchPopup();
self.showMobileMenu();
});
jQuery('.mobilemenu-close').on('click', function(e) {
e.preventDefault();
self.hideMobileMenu();
});
};
Mod.showMobileMenu = function() {
var self = this;
jQuery('.mobilemenu').velocity({
scale: [1, 0],
opacity: [1, 0],
transformOriginY: ["100%", "100%"],
transformOriginX: ["100%", "100%"],
}, {
visibility: 'visible',
duration: 300,
complete: function(elements) {
jQuery(elements).css('pointer-events', 'all');
}
});
};
Mod.hideMobileMenu = function() {
var self = this;
jQuery('.mobilemenu').velocity('reverse', {
visibility: 'hidden',
complete: function(elements) {
jQuery(elements).css('pointer-events', 'none');
}
});
};
Mod.scrollToTop = function() {
if (jQuery('.fly-trigger')[0]) {
jQuery(window).on('scroll', function() {
if (jQuery(window).scrollTop() >= jQuery('.site-header').outerHeight(true) + 60) {
jQuery('.fly-trigger').addClass('show');
} else {
jQuery('.fly-trigger').removeClass('show');
}
});
jQuery(document).on('click', '.totop-trigger', function(e) {
e.preventDefault();
jQuery('html, body').velocity('scroll', {
duration: 1000
});
});
}
};
Mod.stickyHeader = function() {
var self = this;
if (jQuery('.sticky-header')[0] && th90.is_sticky_header) {
jQuery('.sticky-header').each(function(e) {
var $this = jQuery(this),
$sticky_height = $this.outerHeight(true),
$prev = $this.prev(),
elemTop = $prev.offset().top,
elemHeight = $prev.outerHeight(true),
offset_prepare = 100,
offset_sticky = 400,
lastScrollTop = 0;
jQuery(window).on('scroll', function() {
var scroll = jQuery(window).scrollTop();
if (scroll - offset_prepare > elemTop) {
$this.addClass('sticky-start');
} else {
$this.removeClass('sticky-start');
}
if (scroll - offset_sticky > elemTop) {
$this.addClass('sticky-show');
if (scroll > lastScrollTop) {
$this.addClass('scroll-down').removeClass('scroll-up');
} else {
$this.addClass('scroll-up').removeClass('scroll-down');
}
} else {
$this.removeClass('sticky-show').removeClass('scroll-up').removeClass('scroll-down');
}
lastScrollTop = scroll;
});
});
}
}
Mod.readingIndicator = function() {
if (th90.is_singular_post) {
if (jQuery('.article-content')[0]) {
jQuery('.article-content').each(function(e) {
var $this = jQuery(this);
if ($this.length > 0) {
jQuery(window).on('scroll', function() {
var percent = 0,
content_height = $this.outerHeight(true),
window_height = jQuery(window).height(),
content_offset = $this.offset().top,
window_offset = jQuery(window).scrollTop();
if (window_offset > (content_offset - window_height) && window_offset < (content_offset + content_height + window_height)) {
percent = 100 * (window_offset - (content_offset - window_height)) / (content_height + window_height);
jQuery('.reading-indicator').css('width', percent + '%');
} else {
jQuery('.reading-indicator').css('width', '0');
}
});
}
});
}
}
}
Mod.responsiveVideo = function() {
if (jQuery('iframe')[0]) {
jQuery('iframe').each(function(e) {
var src = jQuery(this).attr('src'),
data_src = jQuery(this).attr('data-src'),
thisParent = jQuery(this).parent(),
video = false,
check_src = false;
if (typeof src !== 'undefined' && typeof data_src === 'undefined') {
check_src = src;
} else if (typeof data_src !== 'undefined' && typeof src === 'undefined') {
check_src = data_src;
}
if (check_src) {
check_src = check_src.toLowerCase();
if (check_src.indexOf('yout') >= 0 || check_src.indexOf('vime') >= 0 || check_src.indexOf('dailymo') >= 0) {
video = true;
}
if (video === false) {
return;
}
if (!thisParent.hasClass('video-container') && !thisParent.hasClass('wp-block-embed__wrapper') && !thisParent.parent().hasClass('wp-block-embed__wrapper') && !thisParent.hasClass('frame-wrap') && !thisParent.hasClass('content-custom') && !jQuery(this).hasClass('elementor-video') && !jQuery(this).hasClass('skip-video') && !thisParent.hasClass('fluid-width-video-wrapper')) {
jQuery(this).wrap('<div class="video-container"></div>');
}
}
});
}
};
Mod.videoBgResize = function(element) {
var self = this;
if (element[0]) {
element.each(function(e) {
var height = parseInt(jQuery(this).outerHeight()),
width = parseInt(jQuery(this).outerWidth()),
ratio = (height / width) * 100,
heightIframe = height,
widthIframe = height / 0.5625;
jQuery(this).find('.box-holder-video .video-container').attr('style', 'padding-bottom:' + ratio + '%');
jQuery(this).find('.box-holder-video iframe').attr('style', 'height:' + heightIframe + 'px !important; width:' + widthIframe + 'px');
});
}
}
Mod.lightbox = function() {
var self = this;
/* Check if image have caption */
jQuery('.article-content').find('figure').not('.gallery, .wp-block-gallery').each(function() {
var caption_text = jQuery(this).find('.wp-caption-text, figcaption').html();
jQuery(this).find('a').attr('title', caption_text);
});
/* Post Content Image Popup */
if (th90.lightbox_image) {
jQuery('.article-content').find('a').not('.gallery a, .wp-block-gallery a').each(function(i, el) {
if (self.isUriLightbox(this.href)) {
jQuery(this).addClass('venobox');
}
});
}
/* Post Content Gallery Popup */
if (th90.lightbox_gallery) {
jQuery('.article-content').find('.gallery, .wp-block-gallery').each(function(i, el) {
jQuery(this).find('a').each(function() {
if (self.isUriLightbox(this.href)) {
jQuery(this).attr('data-gall', 'gall-' + i).addClass('venobox');
}
});
});
}
/* WooCommerce Gallery */
if (jQuery('.woocommerce-product-gallery__wrapper')[0]) {
jQuery('.woocommerce-product-gallery__wrapper').each(function(i, el) {
jQuery(this).find('.woocommerce-product-gallery__image a').each(function() {
if (self.isUriLightbox(this.href)) {
jQuery(this).attr('data-gall', 'gall-' + i).addClass('venobox');
}
});
});
}
new VenoBox({
numeration: true,
infinigall: true,
share: true,
spinner: 'pulse',
toolsBackground: 'transparent',
toolsColor: '#f8f8f8',
});
};
Mod.newsticker = function(element) {
var self = this;
if (element[0]) {
element.each(function(e) {
jQuery(this).jConveyorTicker({
anim_duration: parseInt(jQuery(this).attr('data-speed')),
is_rtl: th90.is_rtl,
force_loop: true,
});
});
}
}
Mod.megamenu = function(element) {
var self = this;
if (element[0]) {
element.each(function(e) {
var megaMenuWidth = 0,
megaMenuLeft = 0,
elementorContainer = jQuery(this).closest('.elementor-container'),
defaultContainer = jQuery(this).closest('.container'),
megaListItem = jQuery(this).closest('li'),
megaContainer = jQuery(this).siblings('.sub-menu'),
navContainer = jQuery(this).closest('.navmain-wrap');
if (elementorContainer.width() === undefined) {
megaMenuWidth = defaultContainer.width();
megaMenuLeft = megaListItem.offset().left - defaultContainer.offset().left - 30;
} else {
megaMenuWidth = elementorContainer.width() - 30;
megaMenuLeft = megaListItem.offset().left - elementorContainer.offset().left - 30;
}
megaContainer.css('width', megaMenuWidth);
megaContainer.css('left', -(megaMenuLeft));
});
}
};
Mod.dropdown = function() {
var self = this;
jQuery(document).on({
mouseenter: function() {
var target = jQuery(this).children('.sub-menu');
target.removeClass('is_open');
target.css('pointer-events', 'none');
if (target.hasClass('is_open')) {
target.velocity('stop').velocity('reverse', {
visibility: 'hidden',
});
} else {
target.addClass('is_open');
target.css('pointer-events', 'all');
self.sliderSwiper(target.find('.th90-slider'));
target.velocity('stop').velocity({
translateY: [0, [0.86, 0, 0.07, 1], 35],
opacity: [1, 0],
}, {
visibility: 'visible',
duration: 400,
});
}
},
mouseleave: function() {
var target = jQuery(this).children('.sub-menu');
target.removeClass('is_open');
target.css('pointer-events', 'none');
target.velocity('stop').velocity('reverse', {
visibility: 'hidden',
});
}
}, '.nav-main li, .dropdown-parent');
};
Mod.dropdownClick = function() {
var self = this;
jQuery(document).on('click', '.dropdown-trigger', function(e) {
e.preventDefault();
var trigger = jQuery(this),
target = trigger.siblings('.dropdown-container');
if (target.hasClass('is_open')) {
self.dropdownClickClose(trigger);
} else {
self.dropdownClickOpen(trigger);
}
target.find('a').on('click', function() {
self.dropdownClickClose(trigger);
});
});
jQuery(document).on('click', function(e) {
if (jQuery(e.target).closest('.dropdown-click').length === 0) {
jQuery('.dropdown-container').removeClass('is_open').velocity({
opacity: [0, 1],
translateY: [20, 0],
}, {
display: 'none',
complete: function() {
jQuery('.dropdown-trigger').removeClass('is_open');
}
});
}
});
};
Mod.dropdownClickClose = function($trigger) {
var target = $trigger.siblings('.dropdown-container');
target.removeClass('is_open').velocity('reverse', {
display: 'none',
complete: function() {
$trigger.removeClass('is_open');
}
});
}
Mod.dropdownClickOpen = function($trigger) {
var target = $trigger.siblings('.dropdown-container');
target.addClass('is_open').velocity({
opacity: [1, 0],
translateY: [0, 20],
}, {
display: 'block',
duration: 200,
complete: function() {
$trigger.addClass('is_open');
}
});
}
Mod.dropdownMobileMenu = function() {
var self = this;
jQuery(document).on('click', '.sub-pointer', function(e) {
e.preventDefault();
e.stopPropagation();
if (jQuery(this).hasClass('is-active')) {
jQuery(this).removeClass('is-active').closest('a').siblings('.sub-menu').velocity('slideUp', {
display: 'none',
duration: 200,
});
} else {
jQuery(this).addClass('is-active').closest('a').siblings('.sub-menu').velocity('slideDown', {
duration: 200,
});
jQuery(this).closest('.menu-item').siblings().find('.sub-pointer').removeClass('is-active');
jQuery(this).closest('.menu-item').siblings().find('.sub-menu').velocity('slideUp', {
display: 'none',
duration: 200,
});
}
});
};
Mod.swiperConfig = function($container) {
var self = this,
$slider_config = {},
$slider_id = $container.attr('id'),
options = JSON.parse($container.attr('data-settings'));
$slider_config["speed"] = options.speed;
$slider_config["effect"] = options.effect;
$slider_config["loop"] = options.loop;
$slider_config["autoHeight"] = options.autoHeight;
if (options.autoplay) {
$slider_config["autoplay"] = {
delay: options.delay,
disableOnInteraction: false,
};
}
if (options.responsive) {
$slider_config["slidesPerView"] = options.mSlidesPerView;
$slider_config["spaceBetween"] = options.mSpaceBetween;
$slider_config["breakpoints"] = {
767: {
slidesPerView: options.tSlidesPerView,
spaceBetween: options.tSpaceBetween
},
1024: {
slidesPerView: options.slidesPerView,
spaceBetween: options.spaceBetween
},
};
} else {
$slider_config["slidesPerView"] = options.slidesPerView;
$slider_config["spaceBetween"] = options.spaceBetween;
}
if (options.navigation) {
$slider_config["navigation"] = {
nextEl: '.swiper-next-' + $slider_id,
prevEl: '.swiper-prev-' + $slider_id,
hideOnClick: true,
};
}
if (options.pagination) {
$slider_config["pagination"] = {
el: '.swiper-pagination-' + $slider_id,
bulletClass: 'swiper-pagi',
bulletActiveClass: 'active',
clickable: true,
};
}
$slider_config["on"] = {
init: function() {
$container.closest(".block-slider").addClass('slider-showed');
},
};
$slider_config["preloadImages"] = false;
return $slider_config;
}
Mod.sliderSwiper = function(element) {
var self = this;
if (element[0]) {
element.each(function(e) {
new Swiper(jQuery(this).find('.swiper-container'), self.swiperConfig(jQuery(this)));
jQuery(this).find('.box-holder').each(function(e) {
self.videoBgResize(jQuery(this));
});
});
}
}
Mod.switchSkinClick = function() {
var self = this;
jQuery(document).on('click', '.trigger-dark', function(e) {
self.switchSkin('dark');
localStorage.setItem('th90-skin', 'dark');
jQuery('.trigger-light').css('display', 'flex');
jQuery('.trigger-dark').hide();
});
jQuery(document).on('click', '.trigger-light', function(e) {
self.switchSkin('light');
localStorage.setItem('th90-skin', 'light');
jQuery('.trigger-dark').css('display', 'flex');
jQuery('.trigger-light').hide();
});
}
Mod.switchSkin = function(switchTo) {
var self = this,
tempSkin = localStorage.getItem('th90-skin'),
savedSkin = (tempSkin) ? tempSkin : '',
theSkin = (switchTo) ? switchTo : savedSkin;
if ('dark' == theSkin) {
jQuery('.trigger-light').css('display', 'flex');
jQuery('.trigger-dark').hide();
} else {
jQuery('.trigger-dark').css('display', 'flex');
jQuery('.trigger-light').hide();
}
if (jQuery('.skin-trigger').length > 0 && theSkin) {
if (theSkin == 'dark') {
jQuery('html').find('.is-skin').each(function() {
if (jQuery(this).hasClass('bg-light')) {
jQuery(this).removeClass('bg-light');
jQuery(this).addClass('bg-dark');
jQuery(this).addClass('skin-change');
}
});
jQuery('html').find('.site-skin').each(function() {
if (jQuery(this).hasClass('site-light')) {
jQuery(this).removeClass('site-light');
jQuery(this).addClass('site-dark');
jQuery(this).addClass('skin-change');
}
});
} else {
jQuery('html').find('.is-skin').each(function() {
if (jQuery(this).hasClass('skin-change')) {
jQuery(this).removeClass('bg-dark');
jQuery(this).addClass('bg-light');
}
jQuery(this).removeClass('skin-change');
});
jQuery('html').find('.site-skin').each(function() {
if (jQuery(this).hasClass('skin-change')) {
jQuery(this).removeClass('site-dark');
jQuery(this).addClass('site-light');
}
jQuery(this).removeClass('skin-change');
});
}
}
if (jQuery('.skin-trigger').length <= 0) {
localStorage.removeItem('th90-skin');
}
};
Mod.masonryRun = function(element) {
var self = this;
if (element[0]) {
element.each(function(e) {
if (!jQuery(this).closest('.navmain-wrap').length) {
// init Masonry
var $grid = jQuery(this).find('.post-list-columns').not('.post-list-parent').masonry({
itemSelector: '.post-item',
percentPosition: true,
columnWidth: '.post-item',
});
// layout Masonry after each image loads
$grid.imagesLoaded().progress(function() {
$grid.masonry();
});
}
});
}
}
Mod.ajaxBlockPagi = function() {
var self = this;
jQuery(document).on('click', '.module-pagi', function(e) {
e.preventDefault();
self.ajaxBlock(jQuery(this));
});
}
Mod.ajaxBlockInfinite = function() {
var self = this,
infiniteLoadPoint = jQuery('.module-infinite');
if (infiniteLoadPoint.length == 0) {
return;
}
infiniteLoadPoint.viewportChecker({
repeat: true,
offset: 30,
classToAdd: '',
classToAddForFullView: '',
classToRemove: '',
removeClassAfterAnimation: false,
callbackFunction: function(elem, action) {
self.ajaxBlock(elem);
},
});
}
Mod.ajaxBlock = function(pagination) {
var self = this,
pagiWrap = pagination.closest('.nav-wrap-inner'),
theBlock = pagination.closest('.posts-module'),
blockID = theBlock.get(0).id,
blockSort = theBlock.attr('data-sort'),
blockTerm = theBlock.attr('data-term'),
pageCurrent = theBlock.attr('data-current'),
postsCont = theBlock.find('.posts-container'),
postsList = theBlock.find('.posts-list'),
options = $.extend({}, window['js_' + blockID.replace('th90-', 'th90_')]),
displayItem = 'block';
if (self.isDuringAjax == true) {
return;
}
self.isDuringAjax = true;
if (pageCurrent && options) {
/* If Term Slug is set */
if (blockTerm) {
if (options['tags']) {
options['tags'] = blockTerm;
} else {
options['categories'] = blockTerm;
}
}
/* If Post Sort is set */
if (blockSort) {
options['orderby'] = blockSort;
}
// Check if the Button Disabled
if (pagination.hasClass('btn-disabled')) {
self.isDuringAjax = false;
return false;
}
// Check if the button type is Load More
if (pagination.hasClass('load-more')) {
pageCurrent++;
}
// Next page button
else if (pagination.hasClass('next-posts')) {
pageCurrent++;
theBlock.find('.prev-posts').removeClass('btn-disabled');
}
// Prev page button
else if (pagination.hasClass('prev-posts')) {
pageCurrent--;
theBlock.find('.next-posts').removeClass('btn-disabled');
}
// Ajax Call
$.ajax({
url: th90.ajaxurl,
type: 'post',
data: {
action: 'th90_blocks_load_more',
block: options,
page: pageCurrent
},
beforeSend: function(data) {
pagination.addClass('pagi-loading');
if (!pagination.hasClass('load-more')) {
postsCont.attr('style', 'min-height:' + postsCont.outerHeight() + 'px');
postsCont.append('<div class="block-loader"><span class="loader">' + th90.svg_loader + '</span></div>');
postsList.addClass('is-loading');
} else {
pagiWrap.append('<div class="pagi-loader"><span class="loader">' + th90.svg_loader + '</span></div>');
}
},
success: function(data) {
data = JSON.parse(data);
pagination.removeClass('pagi-loading');
if (pagination.hasClass('load-more')) {
pagiWrap.find('.pagi-loader').remove();
}
if (data['hide_next']) {
theBlock.find('.next-posts').addClass('btn-disabled');
if (pagination.hasClass('show-more') && !pagination.hasClass('nextprev-more')) {
pagination.find('.more-text').html(data['button']);
}
}
// Hide Prev posts button
if (data['hide_prev']) {
theBlock.find('.prev-posts').addClass('btn-disabled');
}
// Posts code
data = data['code'];
data = data.replace(/class="post-item/g, 'class="post-item post-item-' + pageCurrent + ' ');
var content = jQuery(data);
if (theBlock.hasClass('columns-masonry') && postsList.hasClass('post-list-columns') && !postsList.hasClass('post-list-parent') && !postsList.hasClass('secondary-posts-list')) {
postsCont.removeAttr('style');
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
if (pagination.hasClass('load-more')) {
postsList.append(content).masonry('appended', content);
} else {
postsList.html(content).masonry('prepended', content);
}
self.ajaxReload();
self.isDuringAjax = false;
} else {
if (pagination.hasClass('load-more')) {
postsList.append(content);
} else {
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
postsList.html(content);
}
// Animate the loaded items
theBlock.find('.post-item-' + pageCurrent).velocity('stop').velocity({
opacity: [1, 0],
}, {
duration: 500,
complete: function() {
self.ajaxReload();
postsCont.removeAttr('style');
self.isDuringAjax = false;
}
});
}
}
});
// Change the next page number
theBlock.attr('data-current', pageCurrent);
}
return false;
};
Mod.ajaxBlockFilters = function() {
var self = this;
jQuery(document).on('click', '.module-term', function(e) {
e.preventDefault();
var termButton = jQuery(this),
filtersWrap = termButton.closest('.module-filters'),
theBlock = filtersWrap.closest('.posts-module'),
pagination = theBlock.find('.module-pagi'),
blockID = theBlock.get(0).id,
blockSort = theBlock.attr('data-sort'),
termSlug = termButton.attr('data-term'),
postsCont = theBlock.find('.posts-container'),
postsList = theBlock.find('.posts-list'),
options = $.extend({}, window['js_' + blockID.replace('th90-', 'th90_')]),
displayItem = 'block';
if (self.isDuringAjax == true) {
return;
}
self.isDuringAjax = true;
if (options) {
// Set the data attr new values
theBlock.attr('data-current', 1);
if (termSlug) {
if (options['tags']) {
options['tags'] = termSlug;
} else {
options['categories'] = termSlug;
}
theBlock.attr('data-term', termSlug);
} else {
theBlock.removeAttr('data-term');
}
/* If Post Sort is set */
if (blockSort) {
options['orderby'] = blockSort;
}
// Active the selected term
filtersWrap.find('.module-term').removeClass('active');
termButton.addClass('active');
// Ajax Call
$.ajax({
url: th90.ajaxurl,
type: 'post',
data: {
action: 'th90_blocks_load_more',
block: options,
},
beforeSend: function(data) {
postsCont.attr('style', 'min-height:' + postsCont.outerHeight() + 'px');
postsCont.append('<div class="block-loader"><span class="loader">' + th90.svg_loader + '</span></div>');
postsList.addClass('is-loading');
},
success: function(data) {
data = JSON.parse(data);
// Reset the pagination
pagination.removeClass('btn-disabled');
if (pagination.hasClass('show-more') && !pagination.hasClass('nextprev-more')) {
pagination.find('.more-text').html(pagination.attr('data-text'));
}
// Hide next posts button
if (data['hide_next']) {
theBlock.find('.next-posts').addClass('btn-disabled');
if (pagination.hasClass('show-more') && !pagination.hasClass('nextprev-more')) {
pagination.find('.more-text').html(data['button']);
}
}
// Hide Prev posts button
if (data['hide_prev']) {
theBlock.find('.prev-posts').addClass('btn-disabled');
}
// Posts code
data = data['code'];
var content = jQuery(data);
if (theBlock.hasClass('columns-masonry') && postsList.hasClass('post-list-columns') && !postsList.hasClass('post-list-parent') && !postsList.hasClass('secondary-posts-list')) {
postsCont.removeAttr('style');
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
postsList.html(content).masonry('prepended', content);
self.ajaxReload();
self.isDuringAjax = false;
} else {
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
postsList.html(content);
// Animate the loaded items
postsCont.find('.post-item').velocity('stop').velocity({
opacity: [1, 0],
}, {
duration: 500,
complete: function() {
self.ajaxReload();
postsCont.removeAttr('style');
self.isDuringAjax = false;
}
});
}
}
});
}
return false;
});
};
Mod.ajaxBlockSorts = function() {
var self = this;
jQuery(document).on('click', '.module-sort', function(e) {
e.preventDefault();
var sortButton = jQuery(this),
dataSort = sortButton.attr('data-sort'),
sortsWrap = sortButton.closest('.module-sorts'),
sortsTrigger = sortsWrap.find('.dropdown-trigger'),
theBlock = sortsWrap.closest('.posts-module'),
pagination = theBlock.find('.module-pagi'),
blockID = theBlock.get(0).id,
blockTerm = theBlock.attr('data-term'),
postsCont = theBlock.find('.posts-container'),
postsList = theBlock.find('.posts-list'),
options = $.extend({}, window['js_' + blockID.replace('th90-', 'th90_')]),
displayItem = 'block';
if (self.isDuringAjax == true) {
return;
}
self.isDuringAjax = true;
sortsTrigger.text(sortButton.text());
if (options) {
// Set the data attr new values
theBlock.attr('data-current', 1);
if (dataSort) {
options['orderby'] = dataSort;
theBlock.attr('data-sort', dataSort);
} else {
theBlock.removeAttr('data-sort');
}
/* If Term Slug is set */
if (blockTerm) {
if (options['tags']) {
options['tags'] = blockTerm;
} else {
options['categories'] = blockTerm;
}
}
// Ajax Call
$.ajax({
url: th90.ajaxurl,
type: 'post',
data: {
action: 'th90_blocks_load_more',
block: options,
},
beforeSend: function(data) {
postsCont.attr('style', 'min-height:' + postsCont.outerHeight() + 'px');
postsCont.append('<div class="block-loader"><span class="loader">' + th90.svg_loader + '</span></div>');
postsList.addClass('is-loading');
},
success: function(data) {
data = JSON.parse(data);
// Reset the pagination
pagination.removeClass('btn-disabled');
if (pagination.hasClass('show-more') && !pagination.hasClass('nextprev-more')) {
pagination.find('.more-text').html(pagination.attr('data-text'));
}
// Hide next posts button
if (data['hide_next']) {
theBlock.find('.next-posts').addClass('btn-disabled');
if (pagination.hasClass('show-more') && !pagination.hasClass('nextprev-more')) {
pagination.find('.more-text').html(data['button']);
}
}
// Hide Prev posts button
if (data['hide_prev']) {
theBlock.find('.prev-posts').addClass('btn-disabled');
}
// Posts code
data = data['code'];
var content = jQuery(data);
if (theBlock.hasClass('columns-masonry') && postsList.hasClass('post-list-columns') && !postsList.hasClass('post-list-parent') && !postsList.hasClass('secondary-posts-list')) {
postsCont.removeAttr('style');
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
postsList.html(content).masonry('prepended', content);
self.isDuringAjax = false;
self.ajaxReload();
} else {
postsCont.find('.block-loader').remove();
postsList.removeClass('is-loading');
postsList.html(content);
// Animate the loaded items
postsCont.find('.post-item').velocity('stop').velocity({
opacity: [1, 0],
}, {
duration: 500,
complete: function() {
self.ajaxReload();
postsCont.removeAttr('style');
self.isDuringAjax = false;
}
});
}
}
});
}
return false;
});
};
Mod.ajaxInfiniteSingle = function() {
var self = this,
infiniteWrapper = jQuery('#single-post-ajax'),
infiniteLoadPoint = jQuery('#single-point-ajax'),
animationIcon = infiniteLoadPoint.find('.loadmore-animation');
if (infiniteWrapper.length == 0 || infiniteLoadPoint.length == 0) {
return;
}
infiniteLoadPoint.viewportChecker({
repeat: true,
offset: 60,
classToAdd: '',
classToAddForFullView: '',
classToRemove: '',
removeClassAfterAnimation: false,
callbackFunction: function(elem, action) {
if (true == self.isDuringAjax) {
return;
}
var nexturl = infiniteWrapper.data('nexturl');
if (nexturl.indexOf('?p=') > -1) {
nexturl = nexturl + '&th90_single_ajax=1';
} else {
var getParam = 'th90_single_ajax/';
if (nexturl.charAt(nexturl.length - 1) != '/')
getParam = '/' + getParam;
nexturl = nexturl + getParam;
}
self.isDuringAjax = true;
// Ajax Call
$.ajax({
url: nexturl,
type: 'GET',
dataType: 'html',
beforeSend: function(data) {
infiniteLoadPoint.append('<div class="single-loader"><span class="loader">' + th90.svg_loader + '</span></div>');
},
success: function(response) {
response = JSON.parse(JSON.stringify(response));
response = $(response);
infiniteLoadPoint.find('.single-loader').remove();
var nexturl = response.data('nexturl');
if ('undefined' != typeof(nexturl) && nexturl.length > 0) {
infiniteWrapper.data('nexturl', nexturl);
} else {
infiniteWrapper.removeAttr('id');
infiniteLoadPoint.remove();
}
if (response.data('sidebar')) {
if (jQuery.inArray(response.data('sidebar'), th90.elementor_posts_css) == -1) {
jQuery('head').append('<link rel="stylesheet" href="' + response.data('sidebar') + '">');
}
}
infiniteWrapper.append(response);
self.isDuringAjax = false;
setTimeout(function() {
self.scrollUpdateProcess(infiniteWrapper);
self.reinitiateFunctions();
}, 1);
}
});
},
});
};
Mod.scrollUpdateProcess = function(infiniteWrapper) {
var self = this,
articleData = [];
if (infiniteWrapper.length == 0) {
return;
}
var articleInner = infiniteWrapper.find('.single-inner-ajax');
if (articleInner.length > 0) {
articleInner.each(function() {
var article = jQuery(this);
articleData.push({
postID: article.data('previd'),
postURL: article.data('prevurl'),
postTitle: article.find('h1.entry-title').text(),
postImage: article.data('image'),
postDesc: article.data('desc'),
top: article.offset().top,
bottom: article.offset().top + article.outerHeight(true),
articleContentHeight: article.find('.article-content').outerHeight(true),
articleContentTop: article.find('.article-content').offset().top,
});
});
if (window.addEventListener) {
window.addEventListener('scroll', function() {
if (self.$singleScrollDelay % 3 == 1) {
self.scrollUpdateAction(articleData);
self.$singleScrollDelay = 1;
} else {
self.$singleScrollDelay++;
}
}, false);
}
}
};
Mod.scrollUpdateAction = function(articleData) {
var self = this,
percent = 0,
window_height = jQuery(window).height(),
window_offset = jQuery(window).scrollTop();
articleData.every(function(element) {
var content_height = element.articleContentHeight,
content_offset = element.articleContentTop;
if (window_offset > (content_offset - window_height) && window_offset < (content_offset + content_height + window_height)) {
percent = 100 * (window_offset - (content_offset - window_height)) / (content_height + window_height);
jQuery('.reading-indicator').css('width', percent + '%');
} else {
jQuery('.reading-indicator').css('width', '0');
}
if (window_offset > element.top && window_offset < element.bottom) {
if (element.postID != self.currentArticleID) {
self.currentArticleID = element.postID;
self.updateLocationHref(element.postURL, element.postTitle);
jQuery('meta[property="og:title"]').attr('content', element.postTitle + ' - ' + jQuery('meta[property="og:site_name"]').attr('content'));
jQuery('meta[property="og:url"]').attr('content', element.postURL);
jQuery('meta[property="og:description"]').attr('content', element.postDesc);
jQuery('meta[property="og:image"]').attr('content', element.postImage);
}
return false;
}
return true;
});
};
Mod.updateLocationHref = function(url, title) {
var self = this;
if (window.location.href !== url) {
if (url !== '') {
history.replaceState(null, null, url);
document.title = title;
}
self.updateGA(url);
}
};
Mod.updateGA = function(url) {
url = url.replace(/https?:\/\/[^\/]+/i, '');
if (typeof _gaq !== 'undefined' && _gaq !== null) {
_gaq.push(['_trackPageview', url]);
}
if (typeof ga !== 'undefined' && ga !== null) {
ga('send', 'pageview', url);
}
if (typeof __gaTracker !== 'undefined' && __gaTracker !== null) {
__gaTracker('send', 'pageview', url);
}
if (typeof googletag !== 'undefined') {
googletag.pubads().refresh();
}
};
Mod.dynamicSelectOpt = function() {
var self = this;
jQuery("#width_tmp_option").html(jQuery('#resizing_select option:selected').text());
jQuery('#resizing_select').width(jQuery("#width_tmp_select").width()).show();
jQuery('#resizing_select').on('change', function() {
jQuery("#width_tmp_option").html(jQuery('#resizing_select option:selected').text());
jQuery('#resizing_select').width(jQuery("#width_tmp_select").width()).show();
});
}
Mod.numberPlusMinus = function() {
jQuery('.quantity .minus-btn').on('click', function(e) {
e.preventDefault();
var $qty = jQuery(this).siblings('.qty'),
val = parseInt($qty.val());
$qty.val(val > 1 ? val - 1 : 1).trigger('change');
})
jQuery('.quantity .plus-btn').on('click', function(e) {
e.preventDefault();
var $qty = jQuery(this).siblings('.qty'),
val = parseInt($qty.val());
$qty.val(val > 0 ? val + 1 : 1).trigger('change');
});
};
return Mod;
}(TH90_SCRIPTS || {}, jQuery));
jQuery(document).ready(function() {
TH90_SCRIPTS.init();
});
jQuery(window).on('resize', function() {
TH90_SCRIPTS.gutenbergAlignFull();
TH90_SCRIPTS.videoBgResize(jQuery('.box-holder'));
TH90_SCRIPTS.megamenu(jQuery('.have-megamenu'));
});
jQuery(window).on('load', function() {
jQuery('.preloader').velocity({
opacity: [0, 1],
}, {
duration: 500,
delay: 300,
visibility: 'hidden',
});
});