var ATBS = ATBS || {}; (function($){ // USE STRICT "use strict"; var $window = $(window); var $document = $(document); var $goToTopEl = $('.js-go-top-el'); var $overlayBg = $('.js-overlay-bg'); $(".single-body").fitVids(); ATBS.header = { init: function(){ ATBS.header.pageBlockHeadingInit(); ATBS.header.pagiButton(); ATBS.header.ajaxSearch(); ATBS.header.ajaxMegamenu(); ATBS.header.loginForm(); ATBS.header.offCanvasMenu(); ATBS.header.priorityNavInit(); ATBS.header.searchToggle(); ATBS.header.smartAffix.init({ fixedHeader: '.js-sticky-header', headerPlaceHolder: '.js-sticky-header-holder', }); ATBS.header.smartFooterInfo.init({ fixedFooter: '.js-sticky-article-info', }); }, pageBlockHeadingInit: function(){ if($('.site-wrapper').hasClass('ceris-block-heading-loading')) { $('.site-wrapper').removeClass('ceris-block-heading-loading'); } }, /* ============================================================================ * Fix sticky navbar padding when open modal * ==========================================================================*/ stickyNavbarPadding: function() { var oldSSB = $.fn.modal.Constructor.prototype.setScrollbar; var $stickyHeader = $('.sticky-header .navigation-bar'); $.fn.modal.Constructor.prototype.setScrollbar = function () { oldSSB.apply(this); if(this.bodyIsOverflowing && this.scrollbarWidth) { $stickyHeader.css('padding-right', this.scrollbarWidth); } } var oldRSB = $.fn.modal.Constructor.prototype.resetScrollbar; $.fn.modal.Constructor.prototype.resetScrollbar = function () { oldRSB.apply(this); $stickyHeader.css('padding-right', ''); } }, /* ============================================================================ * Header dropdown search * ==========================================================================*/ searchToggle: function() { var $headerSearchDropdown = $('#header-search-dropdown'); var $searchDropdownToggle = $('.js-search-dropdown-toggle'); var $mobileHeader = $('#atbs-ceris-mobile-header'); var $stickyHeaderNav = $('#atbs-ceris-sticky-header').find('.navigation-bar__inner'); var $staticHeaderNav = $('.site-header').find('.navigation-bar__inner'); var $headerSearchDropdownInput = $headerSearchDropdown.find('.search-form__input'); $headerSearchDropdown.on('click', function(e) { e.stopPropagation(); }); $searchDropdownToggle.on('click', function(e) { e.stopPropagation(); var $toggleBtn = $(this); var position = ''; if ($toggleBtn.hasClass('mobile-header-btn')) { position = 'mobile'; } else if ($toggleBtn.parents('.sticky-header').length) { position = 'sticky'; } else { position = 'navbar'; } if ($headerSearchDropdown.hasClass('is-in-' + position) || !$headerSearchDropdown.hasClass('is-active')) { $headerSearchDropdown.toggleClass('is-active'); } switch(position) { case 'mobile': if (!$headerSearchDropdown.hasClass('is-in-mobile')) { $headerSearchDropdown.addClass('is-in-mobile'); $headerSearchDropdown.removeClass('is-in-sticky'); $headerSearchDropdown.removeClass('is-in-navbar'); $headerSearchDropdown.appendTo($mobileHeader); } break; case 'sticky': if (!$headerSearchDropdown.hasClass('is-in-sticky')) { $headerSearchDropdown.addClass('is-in-sticky'); $headerSearchDropdown.removeClass('is-in-mobile'); $headerSearchDropdown.removeClass('is-in-navbar'); $headerSearchDropdown.insertAfter($stickyHeaderNav); } break; default: if (!$headerSearchDropdown.hasClass('is-in-navbar')) { $headerSearchDropdown.addClass('is-in-navbar'); $headerSearchDropdown.removeClass('is-in-sticky'); $headerSearchDropdown.removeClass('is-in-mobile'); $headerSearchDropdown.insertAfter($staticHeaderNav); } } if ($headerSearchDropdown.hasClass('is-active')) { setTimeout(function () { $headerSearchDropdownInput.focus(); }, 200); } }); $document.on('click', function(event) { switch (event.which) { case 1: $headerSearchDropdown.removeClass('is-active'); break; default: break; } }); $window.on('stickyHeaderHidden', function(){ if ($headerSearchDropdown.hasClass('is-in-sticky')) { $headerSearchDropdown.removeClass('is-active'); } }); }, /* ============================================================================ * AJAX search * ==========================================================================*/ ajaxSearch: function() { var $results = null; var $ajaxSearch = $('.js-ajax-search'); var ajaxStatus = ''; var noResultText = 'There is no result.'; var errorText = 'There was some error.'; $ajaxSearch.each(function() { var $this = $(this); var $searchForm = $this.find('.search-form__input'); var $resultsContainer = $this.find('.search-results'); var $resultsInner = $this.find('.search-results__inner'); var searchTerm = ''; var lastSearchTerm = ''; $searchForm.on('input', $.debounce(800, function() { searchTerm = $searchForm.val(); if (searchTerm.length > 0) { $resultsContainer.addClass('is-active'); $('.atbs-ceris-search-full').addClass("active"); if ((searchTerm != lastSearchTerm) || (ajaxStatus === 'failed' )) { $resultsContainer.removeClass('is-error').addClass('is-loading'); lastSearchTerm = searchTerm; ajaxLoad(searchTerm, $resultsContainer, $resultsInner); } } else { $resultsContainer.removeClass('is-active'); } })); }); function ajaxLoad(searchTerm, $resultsContainer, $resultsInner) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: 'ceris_ajax_search', searchTerm: searchTerm, securityCheck: cerisAjaxSecurity, }, }); ajaxCall.done(function(respond) { $results = $.parseJSON(respond); ajaxStatus = 'success'; if (!$results.length) { $results = noResultText; } $resultsInner.html($results).css('opacity', 0).animate({opacity: 1}, 500); }); ajaxCall.fail(function() { ajaxStatus = 'failed'; $resultsContainer.addClass('is-error'); $results = errorText; $resultsInner.html($results).css('opacity', 0).animate({opacity: 1}, 500); }); ajaxCall.always(function() { $resultsContainer.removeClass('is-loading'); }); } }, /* ============================================================================ * Megamenu Ajax * ==========================================================================*/ ajaxMegamenu: function() { var $results = null; var $subCatItem = $('.atbs-ceris-mega-menu ul.sub-categories > li'); $subCatItem.on('click',function(e) { e.preventDefault(); var $this = $(this); if($(this).hasClass('active')) { return; } $(this).parents('.sub-categories').find('li').removeClass('active'); var $container = $this.parents('.atbs-ceris-mega-menu__inner').find('.posts-list'); var $thisCatSplit = $this.attr('class').split('-'); var thisCatID = $thisCatSplit[$thisCatSplit.length - 1]; var megaMenuStyle = 0; $container.append('
'); $container.find('article').addClass('bk-preload-blur'); if($container.hasClass('megamenu-1st-large')) { megaMenuStyle = 2; }else if($container.hasClass('megamenu-style-3')) { megaMenuStyle = 3; }else { megaMenuStyle = 1; } $this.addClass('active'); var $htmlRestore = ajax_buff['megamenu'][thisCatID]['html']; //console.log($htmlRestore); if($htmlRestore == '') { ajaxLoad(thisCatID, megaMenuStyle, $container); }else { ajaxRestore($container, thisCatID, $htmlRestore); } }); function ajaxLoad(thisCatID, megaMenuStyle, $container) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxCall = { action: 'ceris_ajax_megamenu', thisCatID: thisCatID, megaMenuStyle : megaMenuStyle, securityCheck: cerisAjaxSecurity }; $.post(ajaxurl, ajaxCall, function (response) { $results = $.parseJSON(response); //Save HTML ajax_buff['megamenu'][thisCatID]['html'] = $results; // Append Result $container.html($results).css('opacity', 0).animate({opacity: 1}, 500); $container.find('.bk-preload-wrapper').remove(); $container.find('article').removeClass('bk-preload-blur'); }); } function ajaxRestore($container, thisCatID, $htmlRestore) { // Append Result $container.html($htmlRestore).css('opacity', 0).animate({opacity: 1}, 500); $container.find('.bk-preload-wrapper').remove(); $container.find('article').removeClass('bk-preload-blur'); } }, /* ============================================================================ * Ajax Button * ==========================================================================*/ pagiButton: function() { var $dotNextTemplate = '…'; var $dotPrevTemplate = '…'; var $buttonTemplate = '##PAGENUMBER##'; var $dotIndex_next; var $dotIndex_prev; var $pagiAction; var $results = null; $('body').on('click', '.atbs-ceris-module-pagination .atbs-ceris-pagination__links > a', function(e) { e.preventDefault(); var $this = $(this); if(($this.hasClass('disable-click')) || $this.hasClass('atbs-ceris-pagination__item-current')) return; var $pagiChildren = $this.parent().children(); var $totalPageVal = parseInt($($pagiChildren[$pagiChildren.length - 2]).text()); var $lastIndex = $this.parent().find('.atbs-ceris-pagination__item-current').index(); var $lastPageVal = parseInt($($pagiChildren[$lastIndex]).text()); var $nextButton = $this.parent().find('.atbs-ceris-pagination__item-next'); var $prevButton = $this.parent().find('.atbs-ceris-pagination__item-prev'); // Save the last active button var $lastActiveButton = $this.parent().find('.atbs-ceris-pagination__item-current'); // Save the last page var $lastActivePage = $this.parent().find('.atbs-ceris-pagination__item-current'); // Add/Remove current class $this.siblings().removeClass('atbs-ceris-pagination__item-current'); if($this.hasClass('atbs-ceris-pagination__item-prev')) { $lastActivePage.prev().addClass('atbs-ceris-pagination__item-current'); }else if($this.hasClass('atbs-ceris-pagination__item-next')) { $lastActivePage.next().addClass('atbs-ceris-pagination__item-current'); }else { $this.addClass('atbs-ceris-pagination__item-current'); } var $currentActiveButton = $this.parent().find('.atbs-ceris-pagination__item-current'); var $currentIndex = $this.parent().find('.atbs-ceris-pagination__item-current').index(); var $currentPageVal = parseInt($($pagiChildren[$currentIndex]).text()); if($currentPageVal == 1) { $($prevButton).addClass('disable-click'); $($nextButton).removeClass('disable-click'); }else if($currentPageVal == $totalPageVal) { $($prevButton).removeClass('disable-click'); $($nextButton).addClass('disable-click'); }else { $($prevButton).removeClass('disable-click'); $($nextButton).removeClass('disable-click'); } if($totalPageVal > 5) { if($this.parent().find('.atbs-ceris-pagination__dots').hasClass('atbs-ceris-pagination__dots-next')) { $dotIndex_next = $this.parent().find('.atbs-ceris-pagination__dots-next').index(); }else { $dotIndex_next = -1; } if($this.parent().find('.atbs-ceris-pagination__dots').hasClass('atbs-ceris-pagination__dots-prev')) { $dotIndex_prev = $this.parent().find('.atbs-ceris-pagination__dots-prev').index(); }else { $dotIndex_prev = -1; } if(isNaN($currentPageVal)) { if($this.hasClass('atbs-ceris-pagination__item-prev')) { $currentPageVal = parseInt($($pagiChildren[$currentIndex + 1]).text()) - 1; }else if($this.hasClass('atbs-ceris-pagination__item-next')) { $currentPageVal = parseInt($($pagiChildren[$currentIndex - 1]).text()) + 1; }else { return; } } if($currentPageVal > $lastPageVal) { $pagiAction = 'up'; }else { $pagiAction = 'down'; } if(($pagiAction == 'up')) { if(($currentIndex == ($dotIndex_next - 1)) || ($currentIndex == $dotIndex_next) || ($currentPageVal == $totalPageVal)) { $this.parent().find('.atbs-ceris-pagination__dots').remove(); //Remove ALL Dot Signal if($currentIndex == $dotIndex_next) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal))).insertAfter($lastActiveButton); $lastActiveButton.next().addClass('atbs-ceris-pagination__item-current'); $currentActiveButton = $this.parent().find('.atbs-ceris-pagination__item-current'); } while(parseInt(($this.parent().find('a:nth-child(3)')).text()) != $currentPageVal) { $this.parent().find('a:nth-child(3)').remove(); //Remove 1 button before } $($dotPrevTemplate).insertBefore($currentActiveButton); //Insert Dot Next if(($currentPageVal < ($totalPageVal - 3))) { $($dotNextTemplate).insertAfter($currentActiveButton); //Insert Dot Prev $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal + 2))).insertAfter($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal + 1))).insertAfter($currentActiveButton); }else if(($currentPageVal < ($totalPageVal - 2))) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal + 2))).insertAfter($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal + 1))).insertAfter($currentActiveButton); } else if(($currentPageVal < ($totalPageVal - 1))) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal + 1))).insertAfter($currentActiveButton); } if($currentPageVal == $totalPageVal) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 3))).insertBefore($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 2))).insertBefore($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); }else if($currentPageVal == ($totalPageVal - 1)) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 2))).insertBefore($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); }else if($currentPageVal == ($totalPageVal - 2 )) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); } } }else if($pagiAction == 'down') { if(($currentIndex == ($dotIndex_prev + 1)) || ($currentIndex == $dotIndex_prev) || (($currentPageVal == 1) && ($currentIndex < $dotIndex_prev))) { $this.parent().find('.atbs-ceris-pagination__dots').remove(); //Remove ALL Dot Signal if($currentIndex == $dotIndex_prev) { $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal))).insertBefore($lastActiveButton); $lastActiveButton.prev().addClass('atbs-ceris-pagination__item-current'); $currentActiveButton = $this.parent().find('.atbs-ceris-pagination__item-current'); while(parseInt($this.parent().find('a:nth-child('+($currentIndex + 2)+')').text()) != $totalPageVal) { $this.parent().find('a:nth-child('+($currentIndex + 2)+')').remove(); //Remove 1 button before } }else if(($currentPageVal == 1) && ($currentIndex < $dotIndex_prev)) { while(parseInt($this.parent().find('a:nth-child('+($currentIndex + 2)+')').text()) != $totalPageVal) { $this.parent().find('a:nth-child('+($currentIndex + 2)+')').remove(); //Remove 1 button before } }else { while(parseInt($this.parent().find('a:nth-child('+($currentIndex + 1)+')').text()) != $totalPageVal) { $this.parent().find('a:nth-child('+($currentIndex + 1)+')').remove(); //Remove 1 button before } } $($dotNextTemplate).insertAfter($currentActiveButton); //Insert Dot After if($currentPageVal > 4) { // <- 1 ... 5 6 7 ... 10 -> $($dotPrevTemplate).insertBefore($currentActiveButton); //Insert Dot Prev $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 2))).insertBefore($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); }else if($currentPageVal > 3) { // <- 1 ... 4 5 6 ... 10 -> $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 2))).insertBefore($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); } else if($currentPageVal > 2) { // <- 1 ... 3 4 5 ... 10 -> $($buttonTemplate.replace('##PAGENUMBER##', ($currentPageVal - 1))).insertBefore($currentActiveButton); } if($currentPageVal == 1) { $($buttonTemplate.replace('##PAGENUMBER##', 4)).insertAfter($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', 3)).insertAfter($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', 2)).insertAfter($currentActiveButton); }else if($currentPageVal == 2) { $($buttonTemplate.replace('##PAGENUMBER##', 4)).insertAfter($currentActiveButton); $($buttonTemplate.replace('##PAGENUMBER##', 3)).insertAfter($currentActiveButton); }else if($currentPageVal == 3) { $($buttonTemplate.replace('##PAGENUMBER##', 4)).insertAfter($currentActiveButton); } } } } if($currentPageVal != 1) { $this.siblings('.atbs-ceris-pagination__item-prev').css('display', 'inline-block'); }else { if($this.hasClass('atbs-ceris-pagination__item-prev')) { $this.css('display', 'none'); }else { $this.siblings('.atbs-ceris-pagination__item-prev').css('display', 'none'); } } if($currentPageVal == $totalPageVal) { if($this.hasClass('atbs-ceris-pagination__item-next')) { $this.css('display', 'none'); }else { $this.siblings('.atbs-ceris-pagination__item-next').css('display', 'none'); } }else { $this.siblings('.atbs-ceris-pagination__item-next').css('display', 'inline-block'); } if($this.closest('.atbs-ceris-module-pagination').hasClass('ceris-user-review-pagination')) { ATBS.ATBS_CustomerReview.reviewPagination($this, $currentPageVal); }else { ajaxListing($this, $currentPageVal); } }); function ajaxListing($this, $currentPageVal) { var $moduleID = $this.closest('.atbs-ceris-block').attr('id'); var moduleName = $moduleID.split("-")[0]; var args = ajax_buff['query'][$moduleID]['args']; if(moduleName == 'ceris_author_results') { var postOffset = ($currentPageVal-1)*args['number'] + parseInt(args['offset']); var $container = $this.closest('.atbs-ceris-block').find('.authors-list'); var moduleInfo = ''; }else { var postOffset = ($currentPageVal-1)*args['posts_per_page'] + parseInt(args['offset']); var $container = $this.closest('.atbs-ceris-block').find('.posts-list'); var moduleInfo = ajax_buff['query'][$moduleID]['moduleInfo']; } var parameters = { moduleName: moduleName, args: args, moduleInfo: moduleInfo, postOffset: postOffset, }; //console.log(parameters); $container.css('height', $container.height()+'px'); $container.append(''); $container.find('article').addClass('bk-preload-blur'); loadAjax(parameters, $container); var $mainCol = $this.parents('.atbs-ceris-main-col'); if($mainCol.length > 0) { var $subCol = $mainCol.siblings('.atbs-ceris-sub-col'); $subCol.css('min-height', '1px'); } var $scrollTarget = $this.parents('.atbs-ceris-block'); $('body,html').animate({ scrollTop: $scrollTarget.offset().top, }, 1100); setTimeout(function(){ $container.css('height', 'auto'); }, 1100); } function loadAjax(parameters, $container){ //console.log(parameters.moduleName); var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxCall = { action: parameters.moduleName, args: parameters.args, moduleInfo: parameters.moduleInfo, postOffset: parameters.postOffset, securityCheck: cerisAjaxSecurity }; //console.log(ajaxCall); $.post(ajaxurl, ajaxCall, function (response) { $results = $.parseJSON(response); //Save HTML // Append Result $container.html($results).css('opacity', 0).animate({opacity: 1}, 500); $container.find('.bk-preload-wrapper').remove(); $container.find('article').removeClass('bk-preload-blur'); ATBS.ATBS_Bookmark.reAddBookmark($container); }); } function checkStickySidebar($this){ var $subCol = $this.parents('.atbs-ceris-main-col').siblings('.atbs-ceris-sub-col'); if($subCol.hasClass('js-sticky-sidebar')) { return $subCol; }else { return 0; } } }, /* ============================================================================ * Login Form tabs * ==========================================================================*/ loginForm: function() { var $loginFormTabsLinks = $('.js-login-form-tabs').find('a'); $loginFormTabsLinks.on('click', function (e) { e.preventDefault() $(this).tab('show'); }); }, /* ============================================================================ * Offcanvas Menu * ==========================================================================*/ offCanvasMenu: function() { var $backdrop = $(''); var $offCanvas = $('.js-atbs-ceris-offcanvas'); var $offCanvasToggle = $('.js-atbs-ceris-offcanvas-toggle'); var $offCanvasClose = $('.js-atbs-ceris-offcanvas-close'); var $offCanvasMenuHasChildren = $('.navigation--offcanvas').find('li.menu-item-has-children > a'); var menuExpander = (' '); var check_show_more = false; $backdrop.on('click', function(){ var button_hide = $offCanvas.find('.btn-nav-show_full i'); $(this).fadeOut(0, function(){ $(this).detach(); }); var check_show_full = $offCanvas; if($(check_show_full).hasClass('show-full')){ $(check_show_full).removeClass('animation'); setTimeout(function () { $(check_show_full).removeClass('show-full'); $(check_show_full).removeClass('is-active'); },400); } else{ $(check_show_full).removeClass('show-full'); $(check_show_full).removeClass('is-active'); } setTimeout(function () { $(check_show_full).removeClass('animation'); $(check_show_full).removeClass('show-full'); $(check_show_full).removeClass('is-active'); },400); check_show_more = false; button_hide.attr('class','mdicon mdicon-chevron-thin-right'); }); $offCanvasToggle.on('click', function(e){ var check_show_full = $offCanvas; e.preventDefault(); var targetID = $(this).attr('href'); var $target = $(targetID); $target.toggleClass('is-active'); $backdrop.hide().appendTo(document.body).fadeIn(200); }); $offCanvasClose.on('click', function(e){ e.preventDefault(); // var targetID = $(this).attr('href'); // var $target = $(targetID); // $target.removeClass('is-active'); var button_hide = $offCanvas.find('.btn-nav-show_full i'); $backdrop.fadeOut(200, function(){ $(this).detach(); }); check_show_more = false; var check_show_full = $offCanvas; if($(check_show_full).hasClass('show-full')){ $(check_show_full).removeClass('animation'); setTimeout(function () { $(check_show_full).removeClass('show-full'); $(check_show_full).removeClass('is-active'); },400); } else{ $(check_show_full).removeClass('show-full'); $(check_show_full).removeClass('is-active'); } button_hide.attr('class','mdicon mdicon-chevron-thin-right'); }); $offCanvasMenuHasChildren.append(function() { return $(menuExpander).on('click', function(e){ e.preventDefault(); var $subMenu = $(this).parent().siblings('.sub-menu'); $subMenu.slideToggle(200); }); }); $(window).on('resize',function (e) { var checkExist = setInterval(function() { var elementPC = $('#atbs-ceris-offcanvas-primary'); var elementMB = $('#atbs-ceris-offcanvas-mobile'); if(elementPC.hasClass('is-active') ){ var checkDisplay = elementPC.css('display'); if(checkDisplay == 'none' ){ $backdrop.css('display','none'); clearInterval(checkExist); } } if(elementMB.hasClass('is-active')) { var checkDisplay = elementMB.css('display'); if( checkDisplay == 'none'){ $backdrop.css('display','none'); clearInterval(checkExist); } } if(elementPC.hasClass('is-active') && elementPC.css('display') != 'none' || elementMB.hasClass('is-active') && elementMB.css('display') != 'none'){ $backdrop.css('display','block'); clearInterval(checkExist); } clearInterval(checkExist); }, 100); // check every 100ms }); var btn_show_more = $('.btn-nav-show_full'); $(btn_show_more).click(function () { var $this = $(this).parents('.atbs-ceris-offcanvas'); var button_hide = $(this).find('i'); $(this).fadeOut(500); if( check_show_more == false){ // $($this).animate({'width':'1420px'},500); $($this).addClass('animation'); setTimeout(function () { $($this).addClass("show-full"); button_hide.attr('class','mdicon mdicon-chevron-thin-left'); $(btn_show_more).fadeIn(50); },600); check_show_more = true; } else { $($this).removeClass("show-full"); $(this).fadeOut(1000); setTimeout(function () { // $($this).animate({'width':'530px'},500); $($this).removeClass('animation'); $(btn_show_more).fadeIn(50); button_hide.attr('class','mdicon mdicon-chevron-thin-right'); },200); check_show_more = false; } }); }, /* ============================================================================ * Prority+ menu init * ==========================================================================*/ priorityNavInit: function() { var $menus = $('.js-priority-nav'); $menus.each(function() { ATBS.priorityNav($(this)); }) }, /* ============================================================================ * Smart sticky header * ==========================================================================*/ smartAffix: { //settings $headerPlaceHolder: null, //the affix menu (this element will get the mdAffixed) $fixedHeader: null, //the menu wrapper / placeholder isDestroyed: false, isDisabled: false, isFixed: false, //the current state of the menu, true if the menu is affix isShown: false, windowScrollTop: 0, lastWindowScrollTop: 0, //last scrollTop position, used to calculate the scroll direction offCheckpoint: 0, // distance from top where fixed header will be hidden onCheckpoint: 0, // distance from top where fixed header can show up breakpoint: 992, // media breakpoint in px that it will be disabled init : function init (options) { //read the settings this.$fixedHeader = $(options.fixedHeader); this.$headerPlaceHolder = $(options.headerPlaceHolder); // Check if selectors exist. if ( !this.$fixedHeader.length || !this.$headerPlaceHolder.length ) { this.isDestroyed = true; } else if ( !this.$fixedHeader.length || !this.$headerPlaceHolder.length || ( ATBS.documentOnResize.windowWidth <= ATBS.header.smartAffix.breakpoint ) ) { // Check if device width is smaller than breakpoint. this.isDisabled = true; } },// end init compute: function compute(){ if (ATBS.header.smartAffix.isDestroyed || ATBS.header.smartAffix.isDisabled) { return; } // Set where from top fixed header starts showing up if( !this.$headerPlaceHolder.length ) { this.offCheckpoint = 400; } else { this.offCheckpoint = $(this.$headerPlaceHolder).offset().top + 400; } this.onCheckpoint = this.offCheckpoint + 500; // Set menu top offset this.windowScrollTop = ATBS.documentOnScroll.windowScrollTop; if (this.offCheckpoint < this.windowScrollTop) { this.isFixed = true; } }, updateState: function updateState(){ //update affixed state if (this.isFixed) { this.$fixedHeader.addClass('is-fixed'); } else { this.$fixedHeader.removeClass('is-fixed'); $window.trigger('stickyHeaderHidden'); } //var reading_indicator = $('.scroll-count-percent'); //var siteHeaderOffsetTop = $('.site-header').first().offset().top; if (this.isShown) { this.$fixedHeader.addClass('is-shown'); /*reading_indicator.each( function() { $(this).css({'top': $('.sticky-header').height() + (siteHeaderOffsetTop + 60)+ 'px' }); });*/ } else { this.$fixedHeader.removeClass('is-shown'); /*reading_indicator.each( function() { $(this).css({'top': $('.sticky-header').height() + (siteHeaderOffsetTop) + 'px' }); });*/ } }, /** * called by events on scroll */ eventScroll: function eventScroll(scrollTop) { var scrollDirection = ''; var scrollDelta = 0; // check the direction if (scrollTop != this.lastWindowScrollTop) { //compute direction only if we have different last scroll top // compute the direction of the scroll if (scrollTop > this.lastWindowScrollTop) { scrollDirection = 'down'; } else { scrollDirection = 'up'; } //calculate the scroll delta scrollDelta = Math.abs(scrollTop - this.lastWindowScrollTop); this.lastWindowScrollTop = scrollTop; // update affix state if (this.offCheckpoint < scrollTop) { this.isFixed = true; } else { this.isFixed = false; } // check affix state if (this.isFixed) { // We're in affixed state, let's do some check if ((scrollDirection === 'down') && (scrollDelta > 14)) { if (this.isShown) { this.isShown = false; // hide menu } } else { if ((!this.isShown) && (scrollDelta > 14) && (this.onCheckpoint < scrollTop)) { this.isShown = true; // show menu } } } else { this.isShown = false; } this.updateState(); // update state } }, // end eventScroll function /** * called by events on resize */ eventResize: function eventResize(windowWidth) { // Check if device width is smaller than breakpoint. if ( ATBS.documentOnResize.windowWidth < ATBS.header.smartAffix.breakpoint ) { this.isDisabled = true; } else { this.isDisabled = false; ATBS.header.smartAffix.compute(); } } }, smartFooterInfo: { //settings $fixedFooter: null, //the menu wrapper / placeholder isDestroyed: false, isDisabled: false, isFixed: false, //the current state of the menu, true if the menu is affix isShown: false, windowScrollTop: 0, lastWindowScrollTop: 0, //last scrollTop position, used to calculate the scroll direction offCheckpoint: 0, // distance from top where fixed header will be hidden onCheckpoint: 0, // distance from top where fixed header can show up breakpoint: 992, // media breakpoint in px that it will be disabled init : function init (options) { //read the settings this.$fixedFooter = $(options.fixedFooter); },// end init compute: function compute(){ if (ATBS.header.smartFooterInfo.isDestroyed || ATBS.header.smartFooterInfo.isDisabled) { return; } this.offCheckpoint = 400; this.onCheckpoint = this.offCheckpoint + 500; // Set menu top offset this.windowScrollTop = ATBS.documentOnScroll.windowScrollTop; if (this.offCheckpoint < this.windowScrollTop) { this.isFixed = true; } }, updateState: function updateState(){ //update affixed state if (this.isFixed) { this.$fixedFooter.addClass('is-fixed'); } else { this.$fixedFooter.removeClass('is-fixed'); //$window.trigger('stickyHeaderHidden'); } //var reading_indicator = $('.scroll-count-percent'); //var siteHeaderOffsetTop = $('.site-header').first().offset().top; if (this.isShown) { this.$fixedFooter.addClass('is-shown'); /*reading_indicator.each( function() { $(this).css({'top': $('.sticky-header').height() + (siteHeaderOffsetTop + 60)+ 'px' }); });*/ } else { this.$fixedFooter.removeClass('is-shown'); /*reading_indicator.each( function() { $(this).css({'top': $('.sticky-header').height() + (siteHeaderOffsetTop) + 'px' }); });*/ } }, /** * called by events on scroll */ eventScroll: function eventScroll(scrollTop) { var scrollDirection = ''; var scrollDelta = 0; // check the direction if (scrollTop != this.lastWindowScrollTop) { //compute direction only if we have different last scroll top // compute the direction of the scroll if (scrollTop > this.lastWindowScrollTop) { scrollDirection = 'down'; } else { scrollDirection = 'up'; } //calculate the scroll delta scrollDelta = Math.abs(scrollTop - this.lastWindowScrollTop); this.lastWindowScrollTop = scrollTop; // update affix state if (this.offCheckpoint < scrollTop) { this.isFixed = true; } else { this.isFixed = false; } //console.log(this); // check affix state if (this.isFixed) { // We're in affixed state, let's do some check if ((scrollDirection === 'down') && (scrollDelta > 14)) { if (!this.isShown) { this.isShown = true; // hide menu } } else { if ((this.isShown) && (scrollDelta > 14) && (this.onCheckpoint < scrollTop)) { this.isShown = false; // show menu } } } else { this.isShown = false; } this.updateState(); // update state } }, // end eventScroll function /** * called by events on resize */ eventResize: function eventResize(windowWidth) { ATBS.header.smartFooterInfo.compute(); } }, }; ATBS.documentOnScroll = { ticking: false, windowScrollTop: 0, //used to store the scrollTop init: function() { window.addEventListener('scroll', function(e) { if (!ATBS.documentOnScroll.ticking) { window.requestAnimationFrame(function() { ATBS.documentOnScroll.windowScrollTop = $window.scrollTop(); // Functions to call here if (!ATBS.header.smartAffix.isDisabled && !ATBS.header.smartAffix.isDestroyed) { ATBS.header.smartAffix.eventScroll(ATBS.documentOnScroll.windowScrollTop); } ATBS.header.smartFooterInfo.eventScroll(ATBS.documentOnScroll.windowScrollTop); ATBS.documentOnScroll.goToTopScroll(ATBS.documentOnScroll.windowScrollTop); ATBS.documentOnScroll.ticking = false; }); } ATBS.documentOnScroll.ticking = true; }); }, /* ============================================================================ * Go to top scroll event * ==========================================================================*/ goToTopScroll: function(windowScrollTop){ if ($goToTopEl.length) { if(windowScrollTop > 800) { if (!$goToTopEl.hasClass('is-active')) $goToTopEl.addClass('is-active'); } else { $goToTopEl.removeClass('is-active'); } } }, /* ============================================================================ * INFINITY AJAX load more posts * ==========================================================================*/ infinityAjaxLoadPost: function() { var loadedPosts = null; var $ajaxLoadPost = $('.infinity-ajax-load-post'); var $this; function ajaxLoad(parameters, postContainer) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxStatus = '', ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: parameters.action, args: parameters.args, postOffset: parameters.postOffset, type: parameters.type, moduleInfo: parameters.moduleInfo, securityCheck: cerisAjaxSecurity // other parameters }, }); ajaxCall.done(function(respond) { loadedPosts = $.parseJSON(respond); ajaxStatus = 'success'; if(loadedPosts == 'no-result') { postContainer.closest('.infinity-ajax-load-post').addClass('disable-infinity-load'); postContainer.closest('.infinity-ajax-load-post').find('.js-ajax-load-post-trigger').addClass('hidden'); postContainer.closest('.infinity-ajax-load-post').find('.ceris-no-more-button').removeClass('hidden'); return; } if (loadedPosts) { var elToLoad = $(loadedPosts).css('opacity',0).animate({'opacity': 1}, 400); postContainer.append(elToLoad); ATBS.ATBS_Bookmark.reAddBookmark(postContainer); } $('html, body').animate({ scrollTop: $window.scrollTop() + 1 }, 0).animate({ scrollTop: $window.scrollTop() - 1 }, 0); // for recalculating of sticky sidebar // do stuff like changing parameters }); ajaxCall.fail(function() { ajaxStatus = 'failed'; }); ajaxCall.always(function() { postContainer.closest('.infinity-ajax-load-post').removeClass('ceris_loading'); postContainer.closest('.infinity-ajax-load-post').removeClass('infinity-disable'); }); } function ajaxLoadInfinitiveScroll(){ $ajaxLoadPost.each(function(index) { $this = $(this); var triggerElement = $this.find('.js-ajax-load-post-trigger'); var top_of_element = triggerElement.offset().top; var bottom_of_element = triggerElement.offset().top + triggerElement.outerHeight(); var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight(); var top_of_screen = $(window).scrollTop(); if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){ if($this.hasClass('infinity-disable') || $this.hasClass('disable-infinity-load')) return; $this.addClass('infinity-disable'); var $moduleID = $this.closest('.atbs-ceris-block').attr('id'); var moduleName = $moduleID.split("-")[0]; var args = ajax_buff['query'][$moduleID]['args']; var postContainer = $this.find('.posts-list'); var moduleInfo = ajax_buff['query'][$moduleID]['moduleInfo']; $this.addClass('ceris_loading'); var postOffset = parseInt(args['offset']) + $this.find('article').length; if($this.closest('.atbs-ceris-block').hasClass('ceris_latest_blog_posts')) { var stickPostLength = args['post__not_in'].length; postOffset = postOffset - stickPostLength; } var parameters = { action: moduleName, args: args, postOffset: postOffset, type: 'loadmore', moduleInfo: moduleInfo, }; ajaxLoad(parameters, postContainer); } }); } $(window).on('scroll', $.debounce(250, ajaxLoadInfinitiveScroll)); }, //single Scrolling /* ============================================================================ * Single INFINITY AJAX Load Posts * ==========================================================================*/ infinityAjaxLoadSinglePost: function() { var ajaxLoadPost = $('.single-infinity-scroll'); var nextArticlePopup = $('.single-next-article-info-popup'); var currentArticleInfo = $('.header-current-reading-article'); var $this; function ajaxLoad(parameters, postContainer) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxStatus = '', ajaxCall = $.ajax({ url: parameters.postURLtoLoad, type: "GET", dataType: "html" }); ajaxCall.done(function(respond) { if (respond) { var elToLoad = $($(respond).find('.single-infinity-container').html()).css('opacity',0).animate({'opacity': 1}, 400); var adsRandomCode = $(respond).find('.single-infinity-container').parents('.ceris-dedicated-single-header').data('infinity-ads'); postContainer.append(adsRandomCode); postContainer.append(elToLoad); setTimeout(function() { var $stickySidebar = $(postContainer).children().last().find('.js-sticky-sidebar'); var $stickyHeader = $('.js-sticky-header'); var marginTop = ($stickyHeader.length) ? ($stickyHeader.outerHeight() + 20) : 0; // check if there's sticky header if ( $( document.body ).hasClass( 'admin-bar' ) ) // check if admin bar is shown. marginTop += 32; if ( $.isFunction($.fn.theiaStickySidebar) ) { $stickySidebar.theiaStickySidebar({ additionalMarginTop: marginTop, additionalMarginBottom: 20, }); } //React var reactions = $(postContainer).children().last().find('.js-atbs-reaction'); ATBS.ATBS_reaction.atbs_reaction(reactions); // Remove Ajax Load var postURLnextLoad = postContainer.find('.single-infinity-inner').last().data('url-to-load'); if((typeof postURLnextLoad == 'undefined') || (postURLnextLoad == '')) { $('.infinity-single-trigger').remove(); } }, 250); // wait a bit for precise height; // Run Photorama setTimeout(function() { var galleryPhotorama = $(postContainer).children().last().find('.fotorama'); if(galleryPhotorama.length > 0) { $(galleryPhotorama).fotorama(); } }, 250); // wait a bit for precise height; // js blur single var overlayBackgroundSingle = $(postContainer).children().find('.js-overlay-bg'); if (overlayBackgroundSingle.length) { overlayBackgroundSingle.each(function() { var $mainArea = $(this).find('.js-overlay-bg-main-area'); if (!$mainArea.length) { $mainArea = $(this); } var $subArea = $(this).find('.js-overlay-bg-sub-area'); var $subBg = $(this).find('.js-overlay-bg-sub'); var leftOffset = $mainArea.offset().left - $subArea.offset().left; var topOffset = $mainArea.offset().top - $subArea.offset().top; $subBg.css('display', 'block'); $subBg.css('position', 'absolute'); $subBg.css('width', $mainArea.outerWidth() + 'px'); $subBg.css('height', $mainArea.outerHeight() + 'px'); $subBg.css('left', leftOffset + 'px'); $subBg.css('top', topOffset + 'px'); }); }; // do stuff like changing parameters var $postSliderSidebar = $(postContainer).children().last().find('.js-atbs-ceris-carousel-1i-loopdot'); $postSliderSidebar.each( function() { $(this).owlCarousel({ items: 1, margin: 0, loop: true, nav: true, dots: true, autoHeight: true, navText: ['', ''], smartSpeed: 500, responsive: { 0 : { items: 1, }, }, }); }); // Review var reviews_rating_score = $(postContainer).children().last().find('.reviews-score-list'); ATBS.ATBS_CustomerReview.reviewScoreList(reviews_rating_score); var reviews_rating_star = $(postContainer).children().last().find('.reviews-rating'); ATBS.ATBS_CustomerReview.reviewRatingStarIcon(reviews_rating_star); var userReviewContents = $(postContainer).children().last().find('.ceris-user-review-content'); ATBS.ATBS_CustomerReview.reviewReadmoreInit(userReviewContents); var reader_review_form = $(postContainer).children().last().find('.rating-form'); ATBS.ATBS_CustomerReview.userReviewFormSubmit(reader_review_form); var closeReviewPopup_1 = $(postContainer).children().last().find('.btn-close-review-popup'); var closeReviewPopup_2 = $(postContainer).children().last().find('.btn-close-review-normal'); ATBS.ATBS_CustomerReview.popupThankyouPanel(closeReviewPopup_1, closeReviewPopup_2); currentArticleInfoUpdate(); nextArticlePopupInfo(); } }); ajaxCall.fail(function() { ajaxStatus = 'failed'; }); ajaxCall.always(function() { $this.removeClass('infinity-disable'); var triggerElement = $this.find('.infinity-single-trigger'); if(!triggerElement.length) { return } //ATBS.ajaxLazyload.lazyload_start(); }); } function nextArticlePopupInfo(){ var elemnt_scroll = $('.element-scroll-percent'); elemnt_scroll.each( function() { var thisELScroll = $(this); var theJourney = $(window).scrollTop() - thisELScroll.offset().top; if((theJourney > 0) && (theJourney <= thisELScroll.height())) { var nextPostTitletoLoad = thisELScroll.data('post-title-to-load'); if(theJourney > (thisELScroll.height() - $(window).height())) { nextArticlePopup.addClass('atbs-force-hidden'); }else { if((nextArticlePopup.hasClass('atbs-force-hidden')) && (nextPostTitletoLoad != '')) { nextArticlePopup.removeClass('atbs-force-hidden'); } } if(nextPostTitletoLoad != '') { var currentPostTitleText = $.trim(nextArticlePopup.find('.post__title').html()); if((nextPostTitletoLoad !== currentPostTitleText) || (currentPostTitleText == '')) { var wcntPerMin; if(typeof ceris_wcount !== 'undefined'){ wcntPerMin = ceris_wcount[0]; }else { wcntPerMin = 130; } var postWPM = parseInt(thisELScroll.data('next-wcount')/wcntPerMin) + 1; nextArticlePopup.find('.post__title').text(nextPostTitletoLoad); nextArticlePopup.find('span.ceris-article-wpm').text(postWPM); nextArticlePopup.find('.post__title').unbind(); nextArticlePopup.find('.post__title').on('click',function(e) { e.preventDefault(); $('body,html').animate({ scrollTop: thisELScroll.offset().top + thisELScroll.height(), }, 800); }); nextArticlePopup.removeClass('atbs-force-hidden'); } }else { nextArticlePopup.addClass('atbs-force-hidden'); } } }); } function currentArticleInfoUpdate() { var elemnt_scroll = $('.element-scroll-percent'); elemnt_scroll.each( function() { var thisELScroll = $(this); var theJourney = $(window).scrollTop() - thisELScroll.offset().top; if((theJourney > 0) && (theJourney <= thisELScroll.height())) { var currentReadingPostTitle = $.trim($(currentArticleInfo.find('h5')).html()); var currentPostTitleText = $.trim(thisELScroll.find('header.single-header').find('h1.post__title').html()); currentArticleInfo.find('h5').unbind(); currentArticleInfo.find('h5').on('click',function(e) { e.preventDefault(); $('body,html').animate({ scrollTop: thisELScroll.offset().top - 70, }, 800); }); if((currentReadingPostTitle !== currentPostTitleText) || (currentReadingPostTitle == '')) { var wcntPerMin; if(typeof ceris_wcount !== 'undefined'){ wcntPerMin = ceris_wcount[0]; }else { wcntPerMin = 130; } var postWPM = parseInt(thisELScroll.data('wcount')/wcntPerMin) + 1; currentArticleInfo.find('h5').text(currentPostTitleText); currentArticleInfo.find('span.ceris-article-wpm').text(postWPM); currentArticleInfo.find('h5').unbind(); currentArticleInfo.find('h5').on('click',function(e) { e.preventDefault(); $('body,html').animate({ scrollTop: thisELScroll.offset().top - 70, }, 800); }); } } }); } function ajaxLoadInfinitiveScroll(){ $this = ajaxLoadPost; nextArticlePopupInfo(); currentArticleInfoUpdate(); var triggerElement = $this.find('.infinity-single-trigger'); if(!triggerElement.length) { return; } var top_of_element = triggerElement.offset().top; var bottom_of_element = triggerElement.offset().top + triggerElement.outerHeight(); var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight(); var top_of_screen = $(window).scrollTop(); if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){ if($this.hasClass('infinity-disable')) return; $this.addClass('infinity-disable'); var postURLtoLoad = $this.find('.single-infinity-inner').last().data('url-to-load'); var postContainer = $this.find('.single-infinity-container'); var parameters = { postURLtoLoad: postURLtoLoad, }; ajaxLoad(parameters, postContainer); } } $(window).on('scroll', $.debounce(250, ajaxLoadInfinitiveScroll)); }, }; ATBS.documentOnResize = { ticking: false, windowWidth: $window.width(), init: function() { window.addEventListener('resize', function(e) { if (!ATBS.documentOnResize.ticking) { window.requestAnimationFrame(function() { ATBS.documentOnResize.windowWidth = $window.width(); // Functions to call here if (!ATBS.header.smartAffix.isDestroyed) { ATBS.header.smartAffix.eventResize(ATBS.documentOnResize.windowWidth); } ATBS.clippedBackground(); ATBS.documentOnResize.ticking = false; }); } ATBS.documentOnResize.ticking = true; }); }, }; ATBS.ATBS_Bookmark = { init: function() { var buttonRemoveBookmark = $('.bookmark-for-user .post__button-remove-bookmark'); var buttonBookMarkUser = $('.bookmark-for-user .post__button-bookmark'); var buttonDismissBookmark = $('.ceris-dismiss-item'); var buttonBookMarkShowOption = $('.bookmark-for-guest .button-bookmark-option'); var buttonPercentWBookmark = $('.scroll-count-percent-with-bookmark'); if(buttonBookMarkUser.length) { ATBS.ATBS_Bookmark.bookmarkUser(buttonBookMarkUser); } if(buttonRemoveBookmark.length) { ATBS.ATBS_Bookmark.removebookmarkUser(buttonRemoveBookmark); } if(buttonDismissBookmark.length) { ATBS.ATBS_Bookmark.dismissArticle(buttonDismissBookmark); } if(buttonBookMarkShowOption.length) { ATBS.ATBS_Bookmark.bookmarkforGuest(buttonBookMarkShowOption); } if(buttonPercentWBookmark.length) { ATBS.ATBS_Bookmark.bookmarkSingleScrolling(buttonPercentWBookmark); } $(document).on('click',function(event){ if (!$(event.target).closest(".button-bookmark-option, .button-bookmark-option-content").length) { $(".show-bookmark-option-content").toggleClass('show-bookmark-option-content'); } }); }, /* ============================================================================ * Bookmark * ==========================================================================*/ bookmarkUser: function(buttonBookMarkUser){ buttonBookMarkUser.each(function () { $(this).off('click'); $(this).on('click',function(){ $(this).closest('.bookmark__buttons-wrap').find('.post__button-bookmark-option').removeClass('show-bookmark-option-content'); var bookmarkItem = $(this).parents('.post-has-bookmark'); $(bookmarkItem).toggleClass('active-status-bookmark'); $(this).toggleClass('show-bookmark-option-content'); var userID = $(this).closest('.bookmark-for-user').data('userid'); var postID = $(this).closest('.bookmark-for-user').data('postid'); if($(bookmarkItem).hasClass('active-status-bookmark')) { var parameters = { action: 'ceris_add_bookmark', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); }else { var parameters = { action: 'ceris_remove_bookmark', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); } }); }); }, bookmarkSingleScrolling: function(buttonPercentWBookmark){ buttonPercentWBookmark.each(function () { $(this).off('click'); $(this).on('click',function(){ var bookmarkIcon = $(this).find('.btn-bookmark-icon'); var userID = $(this).closest('.atbs-scroll-single-percent-wrap').data('userid'); var postID = $(this).closest('.atbs-scroll-single-percent-wrap').data('postid'); $(bookmarkIcon).toggleClass('is-saved'); if(bookmarkIcon.hasClass('is-saved')) { $('.atbs-ceris-block-'+postID).addClass('ceris-already-bookmarked'); }else { $('.atbs-ceris-block-'+postID).removeClass('ceris-already-bookmarked'); } $(this).toggleClass('show-bookmark-option-content'); if($(bookmarkIcon).hasClass('is-saved')) { var parameters = { action: 'ceris_add_bookmark', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); }else { var parameters = { action: 'ceris_remove_bookmark', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); } }); }); }, dismissArticle: function(buttonDismissBookmark) { buttonDismissBookmark.each(function () { $(this).off('click'); $(this).on('click',function(){ var thisobj = $(this); if($(this).parents('.site-content').hasClass('bookmark-without-dismiss')) { return; } var userID = $(this).closest('.bookmark-for-user').data('userid'); var postID = $(this).closest('.bookmark-for-user').data('postid'); if($(this).hasClass('ceris-remove-dismiss')) { var parameters = { action: 'ceris_remove_dismiss_article', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); }else { var moduleID = $(this).closest('.atbs-ceris-block').attr('id'); var args = ajax_buff['query'][moduleID]['moduleInfo']['bookmarkTmp']; args.push(postID); ajax_buff['query'][moduleID]['moduleInfo']['bookmarkTmp'] = args; var parameters = { action: 'ceris_dismiss_article', userID: userID, postID: postID }; ATBS.ATBS_Bookmark.ajaxLoad(parameters); } $(this).closest('.list-item').addClass('ceris-scale-to-zero'); var waitingCount = 3; var checkItemClassthenRemove = setInterval(function() { if(waitingCount == 0) { clearInterval(checkItemClassthenRemove); } if(thisobj.closest('.list-item').hasClass('ceris-scale-to-zero')) { thisobj.closest('.list-item').remove(); clearInterval(checkItemClassthenRemove); } waitingCount --; }, 350); // check every 100ms }); }); }, removebookmarkUser: function(buttonRemoveBookmark) { $('.post-has-bookmark').hover(function(){ }, function(){ $(this).find('.post__button-bookmark-option').removeClass('show-bookmark-option-content') }); buttonRemoveBookmark.each(function () { $(this).off('click'); $(this).on('click',function(){ //$(this).closest('.bookmark__buttons-wrap').find('.post__button-bookmark-option').removeClass('show-bookmark-option-content'); $(this).toggleClass('show-bookmark-option-content'); }); }); }, bookmarkforGuest: function(buttonBookMarkShowOption) { $('.post-has-bookmark').hover(function(){ }, function(){ $(this).find('.post__button-bookmark-option').removeClass('show-bookmark-option-content') }); buttonBookMarkShowOption.each(function () { $(this).off('click'); $(this).on('click',function(){ //$(this).closest('.bookmark__buttons-wrap').find('.post__button-bookmark-option').removeClass('show-bookmark-option-content'); $(this).closest('.post__button-bookmark-option').siblings().removeClass('show-bookmark-option-content'); $(this).closest('.post__button-bookmark-option').toggleClass('show-bookmark-option-content'); }); }); }, reAddBookmark: function(container){ var buttonBookMarkUser = $(container).find('.bookmark-for-user .post__button-bookmark'); var buttonRemoveBookmark = $(container).find('.bookmark-for-user .post__button-remove-bookmark'); var buttonDismissBookmark = $(container).find('.ceris-dismiss-item'); var buttonBookMarkShowOption = $('.bookmark-for-guest .button-bookmark-option'); if(buttonBookMarkUser.length) { ATBS.ATBS_Bookmark.bookmarkUser(buttonBookMarkUser); } if(buttonRemoveBookmark.length) { ATBS.ATBS_Bookmark.removebookmarkUser(buttonRemoveBookmark); } if(buttonDismissBookmark.length) { ATBS.ATBS_Bookmark.dismissArticle(buttonDismissBookmark); } if(buttonBookMarkShowOption.length) { ATBS.ATBS_Bookmark.bookmarkforGuest(buttonBookMarkShowOption); } container.find('.ceris-scale-to-zero').remove(); }, ajaxLoad: function(parameters) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; // console.log(parameters); var ajaxStatus = '', ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: parameters.action, userID: parameters.userID, postID: parameters.postID, securityCheck: cerisAjaxSecurity // other parameters }, }); ajaxCall.done(function(respond) { //console.log(respond); }); ajaxCall.fail(function() { }); ajaxCall.always(function() { }); }, } ATBS.ATBS_CustomerReview = { init: function() { var reviews_rating_score = $('.reviews-score-list'); var reviews_rating_star = $('.reviews-rating'); var userReviewContents = $('.ceris-user-review-content'); var reader_review_form = $('.rating-form'); var closeReviewPopup_1 = $('.btn-close-review-popup'); var closeReviewPopup_2 = $('.btn-close-review-normal'); ATBS.ATBS_CustomerReview.reviewRatingStarIcon(reviews_rating_star); ATBS.ATBS_CustomerReview.reviewScoreList(reviews_rating_score); ATBS.ATBS_CustomerReview.reviewReadmoreInit(userReviewContents); ATBS.ATBS_CustomerReview.userReviewFormSubmit(reader_review_form); ATBS.ATBS_CustomerReview.popupThankyouPanel(closeReviewPopup_1, closeReviewPopup_2); ATBS.ATBS_CustomerReview.reviewAdminDelete(); }, reviewReadmoreInit: function(userReviewContents) { ATBS.ATBS_CustomerReview.reviewReadmoreCal(userReviewContents); }, reviewReadmoreCal: function(userReviewContents){ $(userReviewContents).each(function(index, userReviewContent) { ATBS.ATBS_CustomerReview.reviewReadmoreAction(userReviewContent); }); }, reviewReadmoreAction: function(userReviewContent) { var reviewContentHeight = $(userReviewContent).find('.user__description-excerpt').height(); var ceris_html = document.getElementsByTagName('html')[0]; var ceris_rem = parseInt(window.getComputedStyle(ceris_html)['fontSize']); var checkExist = setInterval(function() { if(reviewContentHeight > 0) { if(reviewContentHeight > (6.8*ceris_rem)) { $(userReviewContent).addClass('has-more-active'); } $(userReviewContent).find('.review-readmore').on('click', function(e) { $(this).siblings('.user__description-excerpt').css({ // Set height to prevent instant jumpdown when max height is removed "height": $(userReviewContent).find('.user__description-excerpt').height(), "max-height": 9999 }).animate({ "height": reviewContentHeight }); $(userReviewContent).removeClass('has-more-active'); }); $(userReviewContent).removeClass(('review-content-loading')); clearInterval(checkExist); } }, 50); // check every 100ms }, popupThankyouPanel: function(closeReviewPopup_1, closeReviewPopup_2){ closeReviewPopup_1.on('click', function(){ $(this).closest('.ceris-user-review-popup-notification ').removeClass('enable-review-popup'); }); closeReviewPopup_2.on('click', function(){ $(this).closest('.ceris-user-review-popup-notification ').removeClass('enable-review-popup'); }); }, userReviewFormSubmit: function(reader_review_form) { reader_review_form.each(function () { $(this).submit(function(e){ e.preventDefault(); var thisFormSubmitButton; thisFormSubmitButton = $(this); thisFormSubmitButton.find('.rating-submit').addClass('ceris_loading'); var formData = $(this).serializeArray(); var userID = $(this).closest('.reviews-rating').data('userid'); var postID = $(this).closest('.reviews-rating').data('postid'); var reviewTime = new Date(); var reviewTimeStr = ATBS.ATBS_CustomerReview.reviewMonthName() + ' ' + reviewTime.getDate() + ', ' + reviewTime.getFullYear(); var formVal = {userID:userID, postID:postID, reviewTime:reviewTimeStr}; $(formData).each(function(index, field){ switch(field.name) { case 'user-star-rating': formVal.user_star_rating = field.value; break; case 'user-review-title': formVal.user_review_title = field.value; break; case 'user-review-content': formVal.user_review_content = field.value; break; } }); var parameters = { action: 'ceris_user_review', formVal: formVal, }; ATBS.ATBS_CustomerReview.ajaxLoad(parameters, thisFormSubmitButton); }); }); }, reviewMonthName: function(){ var month = new Array(); month[0] = "Jan"; month[1] = "Feb"; month[2] = "Mar"; month[3] = "Apr"; month[4] = "May"; month[5] = "Jun"; month[6] = "Jul"; month[7] = "Aug"; month[8] = "Sep"; month[9] = "Oct"; month[10] = "Nov"; month[11] = "Dec"; var d = new Date(); return month[d.getMonth()]; }, reviewRatingStarIcon: function(reviews_rating_star){ reviews_rating_star.each(function () { var theCurrentReviewForm = $(this); var rating_reviews_list = $(this).find('.rating-form'); $(rating_reviews_list).each(function () { var star_score_icon = $(this).find('.star-item'); star_score_icon.on('click',function () { $(star_score_icon).removeClass("active"); var star_score_value = $(this).index(); $(this).parents('.rating-star').siblings('.user-star-rating').attr('value', 5 - star_score_value); star_score_icon.each(function () { if ($(this).index() >= star_score_value){ //console.log($(this).index()); $(this).addClass("active"); } }) }); }); }); }, reviewScoreList: function(reviews_rating_score){ reviews_rating_score.each(function () { var score_list_item = $(this).find(".score-item"); $(score_list_item).each(function () { var percent = parseFloat( $(this).data('total') ); var percent_default = 0; var score_item = setInterval(frame, 0 ); var $this = $(this); function frame() { if (percent_default >= percent) { clearInterval(score_item); } else { percent_default++; $this.find(".score-percent").css({"width": percent_default +'%'}); $this.find(".score-number").text(percent_default / 10); // console.log(percent_default); } } }); }); }, ajaxLoad: function(parameters, thisFormSubmitButton) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxStatus = '', ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: parameters.action, formVal: parameters.formVal, securityCheck: cerisAjaxSecurity // other parameters }, }); ajaxCall.done(function(respond) { var theReview = $.parseJSON(respond); var container = $(thisFormSubmitButton).closest('.reviews-rating').siblings('.ceris-user-reviews').find('.user-reviews-list'); container.prepend(theReview); var userReviewContents = container.find('.list-item:first-child').find('.ceris-user-review-content'); ATBS.ATBS_CustomerReview.reviewReadmoreCal(userReviewContents); var ReviewPerPage = $(thisFormSubmitButton).closest('.reviews-rating').siblings('.ceris-user-reviews').data('user-review-count'); if($(thisFormSubmitButton).closest('.reviews-rating').siblings('.ceris-user-reviews').find('.list-item').length > ReviewPerPage) { $(thisFormSubmitButton).closest('.reviews-rating').siblings('.ceris-user-reviews').find('.list-item:last-child').remove(); } $(thisFormSubmitButton).closest('.reviews-rating').addClass('hidden-form'); $(thisFormSubmitButton).closest('.reviews-content').siblings('.ceris-user-review-popup-notification').addClass('enable-review-popup'); var popuploadcomplete = setInterval(function() { $(thisFormSubmitButton).closest('.ceris-reviews-section').find('.circle-loader').addClass('load-complete'); $(thisFormSubmitButton).closest('.ceris-reviews-section').find('.checkmark').toggle(); clearInterval(popuploadcomplete); },800); }); ajaxCall.fail(function() { }); ajaxCall.always(function() { thisFormSubmitButton.find('.rating-submit').removeClass('ceris_loading'); }); }, reviewPagination: function($this, currentPageVal){ var postID = $this.closest('.ceris-user-reviews').siblings('.reviews-rating').data('postid'); var reviewPerPage = $this.closest('.ceris-user-reviews').data('user-review-count'); var parameters = { action: 'ceris_user_review_pagination', currentPageVal : currentPageVal, postID: postID, reviewPerPage: reviewPerPage, }; var container = $this.closest('.ceris-user-review-pagination').siblings('.user-reviews-list'); container.css('height', container.height()+'px'); container.append(''); container.find('.list-item').addClass('bk-preload-blur'); ATBS.ATBS_CustomerReview.paginationAjaxLoad(parameters, $this); }, paginationAjaxLoad: function(parameters, $this) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxStatus = '', ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: parameters.action, currentPageVal: parameters.currentPageVal, postID: parameters.postID, reviewPerPage: parameters.reviewPerPage, securityCheck: cerisAjaxSecurity // other parameters }, }); ajaxCall.done(function(respond) { var theReviews = $.parseJSON(respond); var elToLoad = $(theReviews).css('opacity',0).animate({'opacity': 1}, 400); var container = $this.closest('.ceris-user-review-pagination').siblings('.user-reviews-list'); container.html(elToLoad); var userReviewContents = $(container).find('.ceris-user-review-content'); ATBS.ATBS_CustomerReview.reviewReadmoreCal(userReviewContents); container.find('.bk-preload-wrapper').remove(); container.find('.list-item').removeClass('bk-preload-blur'); setTimeout(function(){ container.css('height', 'auto'); }, 200); ATBS.ATBS_CustomerReview.reviewAdminDelete(); }); ajaxCall.fail(function() { }); ajaxCall.always(function() { }); }, reviewAdminDelete: function() { var reviewDelButtons = $('.ceris-admin-delete-review'); $(reviewDelButtons).each(function () { if(!$(this).hasClass('deleteBtnActive')) { $(this).on('click', function() { var userID = $(this).data('userid'); var postID = $(this).data('postid'); var formVal = {userID:userID, postID:postID}; var parameters = { action: 'ceris_user_delete_review', postID: postID, formVal: formVal }; ATBS.ATBS_CustomerReview.reviewAdminDeleteAjax(parameters, $(this)); }); $(this).addClass('deleteBtnActive'); } }); }, reviewAdminDeleteAjax: function(parameters, $this) { var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var ajaxStatus = '', ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: parameters.action, formVal: parameters.formVal, securityCheck: cerisAjaxSecurity // other parameters }, }); ajaxCall.done(function(respond) { $this.closest('.list-item').slideUp("normal", function() { $(this).remove(); } ); }); ajaxCall.fail(function() { }); ajaxCall.always(function() { }); }, } /* ============================================================================ * Reaction * ==========================================================================*/ ATBS.ATBS_reaction = { init: function() { var reactions = $('.js-atbs-reaction'); ATBS.ATBS_reaction.atbs_reaction(reactions); }, /**/ atbs_reaction: function(reactions){ reactions.each( function() { var reaction_col = $(this).find('.atbs-reactions-col'); reaction_col.on('click', function(){ var reactionType = $(this).data('reaction-type'); var reaction_content = $(this).find('.atbs-reactions-content'); var reactionStatus = ''; if($(this).find('.atbs-reactions-image').hasClass("active")){ reactionStatus = 'active'; }else{ reactionStatus = 'non-active'; } if($(this).find('.atbs-reactions-image').hasClass("active")){ $(this).find('.atbs-reactions-image').removeClass("active"); $(this).find('.atbs-reactions-image').removeClass("scale-icon"); }else{ $(this).find('.atbs-reactions-image').addClass("active"); $(this).find('.atbs-reactions-image').addClass("scale-icon"); } if(reaction_content.hasClass("active")){ reaction_content.removeClass("active"); reaction_content.removeClass("scale-count"); }else{ reaction_content.addClass("active"); reaction_content.addClass("scale-count"); } ATBS.ATBS_reaction.ajaxLoad($(this), reactionType, reactionStatus); }); }); }, ajaxLoad: function(reaction, reactionType, reactionStatus) { var $this = reaction; var reaction_content = $this.find('.atbs-reactions-content'); var cerisAjaxSecurity = ajax_buff['ceris_security']['ceris_security_code']['content']; var postID = reaction.closest('.js-atbs-reaction').data('article-id'); var ajaxCall = $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { action: 'ceris_ajax_reaction', postID: postID, reactionType: reactionType, reactionStatus: reactionStatus, securityCheck: cerisAjaxSecurity, }, }); ajaxCall.done(function(respond) { var results = $.parseJSON(respond); $this.find('.atbs-reaction-count').html(results); }); ajaxCall.fail(function() { //console.log('failed'); }); ajaxCall.always(function() { if($this.find('.atbs-reactions-image').hasClass("active")){ $this.find('.atbs-reactions-image').removeClass("scale-icon"); } if(reaction_content.hasClass("active")){ reaction_content.removeClass("scale-count"); } }); }, } ATBS.ATBS_carousel = { init: function() { var CarouselOptions; var CarouselCarouselOptionsDefault = { items: 5, }; $.fn.ATBS_Carousel = function(CarouselOptions){ if(typeof CarouselOptions === 'object' && CarouselOptions) { console.log(Object.keys(CarouselOptions).length); var thisCarouselOptions = $.extend({}, CarouselCarouselOptionsDefault, CarouselOptions); if(thisCarouselOptions.items == 1) { $(this).wrapInner(''); var theCarousel = $(this).children(); $(this).find('.list-item:first-child').addClass('carousel-item-active'); theCarousel.css('height', $(this).find('.atbs-carousel').height()+'px'); $(this).append(ATBS.ATBS_carousel.carousel_nav(thisCarouselOptions.navText)); $(this.find('.atbs-next')).on('click', function(){ var currentItem = theCarousel.find('.carousel-item-active'); if(!$(currentItem).is(':last-child')) { var nextItem = theCarousel.find('.carousel-item-active').next(); }else { var nextItem = theCarousel.children().first(); } currentItem.removeClass('carousel-item-active'); nextItem.addClass('carousel-item-active'); theCarousel.animate({height:nextItem.height()},300);; }); $(this.find('.atbs-prev')).on('click', function(){ var currentItem = theCarousel.find('.carousel-item-active'); if(!$(currentItem).is(':first-child')) { var nextItem = theCarousel.find('.carousel-item-active').prev(); }else { var nextItem = theCarousel.children().last(); } currentItem.removeClass('carousel-item-active'); nextItem.addClass('carousel-item-active'); $(this).closest('.atbs-nav').siblings('.atbs-carousel').animate({height:nextItem.height()},300); console.log('eventaaaaaaa'); }); var startX = 0; var startY = 0; var endX = 0; var endY = 0; $(theCarousel).on('dragstart', function(e) { startX = e.pageX; startY = e.pageY; }); $(theCarousel).on('dragend', function(e) { e.preventDefault(); endX = e.pageX; endY = e.pageY; if(endX < startX){ console.log('left'); }else { console.log('right'); } }); /* var startX = 0; var startY = 0; var endX = 0; var endY = 0; var thisAlert = function() { alert("Link Clicked"); }; $(theCarousel).on('mousedown', function(e){ e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); startX = e.pageX; startY = e.pageY; return false; ; console.log('aaaaaa'); }; $(theCarousel).closest('.site-content').on('mouseup', function(e){ e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); $(theCarousenmouseup=function(event){ endX = e.pageX; console.log('aaaaaaaaaaa'); console.log('bbbbbbbbbb'); // Swipe Up ifconsole.logrtY - endY > return false; event.preventDefault(); ) } } ; }; */ } } }; }, carousel_nav: function($navArray) { return '