var FPC = FPC || {}; (function ($) { // USE STRICT "use strict"; var $window = $(window); var $document = $(document); var $goToTopEl = $('.js-go-top-el'); var $overlayBg = $('.js-overlay-bg'); FPC.header = { init: function () { FPC.header.ajaxSearch(); FPC.header.loginForm(); FPC.header.offCanvasMenu(); FPC.header.priorityNavInit(); FPC.header.searchToggle(); FPC.header.smartAffix.init({ fixedHeader: '.js-sticky-header', headerPlaceHolder: '.js-sticky-header-holder', }); }, /* ============================================================================ * 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 = $('#fpc-mobile-header'); var $stickyHeaderNav = $('#fpc-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 () { $headerSearchDropdown.removeClass('is-active'); }); $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'); 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 ajaxCall = $.ajax({ url: "inc/ajax-search.html", type: 'post', dataType: 'html', data: { searchTerm: searchTerm, }, }); ajaxCall.done(function (respond) { $results = $(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'); }); } }, /* ============================================================================ * 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-fpc-offcanvas'); var $offCanvasToggle = $('.js-fpc-offcanvas-toggle'); var $offCanvasClose = $('.js-fpc-offcanvas-close'); var $offCanvasMenuHasChildren = $('.navigation--offcanvas').find('li.menu-item-has-children > a'); //var menuExpander = (' '); $backdrop.on('click', function () { $offCanvas.removeClass('is-active'); $(this).fadeOut(200, function () { $(this).detach(); }); }); $offCanvasToggle.on('click', function (e) { e.preventDefault(); var targetID = $(this).attr('href'); var $target = $(targetID); $target.toggleClass('is-active'); $backdrop.hide().appendTo(document.body).fadeIn(200); $("#menu-offcanvas-menu>li:first-child>a").focus(); }); $offCanvasClose.on('click', function (e) { e.preventDefault(); var targetID = $(this).attr('href'); var $target = $(targetID); $target.removeClass('is-active'); $backdrop.fadeOut(200, function () { $(this).detach(); }); $(".header-logo a")[0].focus(); }); $('.submenu-toggle').on('click', function (e) { e.preventDefault(); var $subMenu = $(this).siblings('.sub-menu'); $subMenu.slideToggle(200); }); }, /* ============================================================================ * Prority+ menu init * ==========================================================================*/ priorityNavInit: function () { var $menus = $('.js-priority-nav'); $menus.each(function () { FPC.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 || (FPC.documentOnResize.windowWidth <= FPC.header.smartAffix.breakpoint)) { // Check if device width is smaller than breakpoint. this.isDisabled = true; } },// end init compute: function compute() { if (FPC.header.smartAffix.isDestroyed || FPC.header.smartAffix.isDisabled) { return; } // Set where from top fixed header starts showing up if (this.$headerPlaceHolder) { 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 = FPC.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 { if (this.$fixedHeader) { this.$fixedHeader.removeClass('is-fixed'); } $window.trigger('stickyHeaderHidden'); } if (this.isShown) { this.$fixedHeader.addClass('is-shown'); } else { if (this.$fixedHeader) { this.$fixedHeader.removeClass('is-shown'); } } }, /** * 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 (FPC.documentOnResize.windowWidth < FPC.header.smartAffix.breakpoint) { this.isDisabled = true; } else { this.isDisabled = false; FPC.header.smartAffix.compute(); } } }, }; FPC.documentOnScroll = { ticking: false, windowScrollTop: 0, //used to store the scrollTop init: function () { window.addEventListener('scroll', function (e) { if (!FPC.documentOnScroll.ticking) { window.requestAnimationFrame(function () { FPC.documentOnScroll.windowScrollTop = $window.scrollTop(); // Functions to call here if (!FPC.header.smartAffix.isDisabled && !FPC.header.smartAffix.isDestroyed) { FPC.header.smartAffix.eventScroll(FPC.documentOnScroll.windowScrollTop); } FPC.documentOnScroll.goToTopScroll(FPC.documentOnScroll.windowScrollTop); FPC.documentOnScroll.ticking = false; }); } FPC.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'); } } }, }; FPC.documentOnResize = { ticking: false, windowWidth: $window.width(), init: function () { window.addEventListener('resize', function (e) { if (!FPC.documentOnResize.ticking) { window.requestAnimationFrame(function () { FPC.documentOnResize.windowWidth = $window.width(); // Functions to call here if (!FPC.header.smartAffix.isDestroyed) { FPC.header.smartAffix.eventResize(FPC.documentOnResize.windowWidth); } FPC.clippedBackground(); FPC.documentOnResize.ticking = false; }); } FPC.documentOnResize.ticking = true; }); }, }; FPC.documentOnReady = { init: function () { FPC.header.init(); FPC.header.smartAffix.compute(); FPC.documentOnScroll.init(); FPC.documentOnReady.ajaxLoadPost(); FPC.documentOnReady.countdown(); FPC.documentOnReady.goToTop(); FPC.documentOnReady.newsTicker(); FPC.documentOnReady.lightBox(); FPC.documentOnReady.perfectScrollbarInit(); FPC.documentOnReady.tooltipInit(); FPC.documentOnReady.search(); }, /* ============================================================================ * AJAX load more posts * ==========================================================================*/ ajaxLoadPost: function () { var $loadedPosts = null; var $ajaxLoadPost = $('.js-ajax-load-post'); function ajaxLoad(parameters, $postContainer) { var ajaxStatus = '', ajaxCall = $.ajax({ url: "inc/ajax-load-post.html", type: 'post', dataType: 'html', data: { // action: 'ajax_load_post', offset: parameters.offset, postsToLoad: parameters.postsToLoad, // other parameters }, }); ajaxCall.done(function (respond) { $loadedPosts = $(respond); ajaxStatus = 'success'; if ($loadedPosts) { $loadedPosts.appendTo($postContainer).css('opacity', 0).animate({ opacity: 1 }, 500); } $('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 () { // do other stuff }); } $ajaxLoadPost.each(function () { var $this = $(this); var $postContainer = $this.find('.posts-list'); var $triggerBtn = $this.find('.js-ajax-load-post-trigger'); var parameters = { offset: $this.data("offset"), postsToLoad: $this.data("posts-to-load"), layout: $this.data("layout"), }; $triggerBtn.on('click', function () { ajaxLoad(parameters, $postContainer); }); }); }, /* ============================================================================ * Countdown timer * ==========================================================================*/ countdown: function () { if ($.isFunction($.fn.countdown)) { var $countdown = $('.js-countdown'); $countdown.each(function () { var $this = $(this); var finalDate = $this.data('countdown'); $this.countdown(finalDate, function (event) { $(this).html(event.strftime('' + '