File: /home/slyfwmm/adspray/wp-content/themes/aivons/assets/js/aivons-theme.js
(function ($) {
"use strict";
if ($(".scroll-to-target").length) {
$(".scroll-to-target").on("click", function () {
var target = $(this).attr("data-target");
$("html, body").animate({
scrollTop: $(target).offset().top,
},
1000
);
return false;
});
}
if ($(".main-menu__list").length && $(".mobile-nav__container").length) {
let navContent = document.querySelector(".main-menu__list").outerHTML;
let mobileNavContainer = document.querySelector(".mobile-nav__container");
mobileNavContainer.innerHTML = navContent;
}
if ($(".sticky-header__content").length) {
let navContent = document.querySelector(".main-menu").innerHTML;
let mobileNavContainer = document.querySelector(".sticky-header__content");
mobileNavContainer.innerHTML = navContent;
}
if ($(".mobile-nav__container .main-menu__list").length) {
let dropdownAnchor = $(
".mobile-nav__container .main-menu__list .menu-item-has-children > a"
);
dropdownAnchor.each(function () {
let self = $(this);
let toggleBtn = document.createElement("BUTTON");
toggleBtn.setAttribute("aria-label", "dropdown toggler");
toggleBtn.innerHTML = "<i class='fa fa-angle-down'></i>";
self.append(function () {
return toggleBtn;
});
self.find("button").on("click", function (e) {
e.preventDefault();
let self = $(this);
self.toggleClass("expanded");
self.parent().toggleClass("expanded");
self.parent().parent().children("ul").slideToggle();
});
});
}
if ($(".mobile-nav__toggler").length) {
$(".mobile-nav__toggler").on("click", function (e) {
e.preventDefault();
$(".mobile-nav__wrapper").toggleClass("expanded");
$("body").toggleClass("locked");
});
}
if ($(".search-toggler").length) {
$(".search-toggler").on("click", function (e) {
e.preventDefault();
$(".search-popup").toggleClass("active");
$(".mobile-nav__wrapper").removeClass("expanded");
$("body").toggleClass("locked");
});
}
if ($(".dynamic-year").length) {
let date = new Date();
$(".dynamic-year").html(date.getFullYear());
}
if ($(".wow").length) {
var wow = new WOW({
boxClass: "wow",
animateClass: "animated",
mobile: true,
live: true,
});
wow.init();
}
function projectMasonaryLayout() {
if ($('.masonary-layout').length) {
$('.masonary-layout').isotope({
layoutMode: 'masonry'
});
}
}
function SmoothMenuScroll() {
var anchor = $(".scrollToLink");
if (anchor.length) {
anchor.children("a").bind("click", function (event) {
if ($(window).scrollTop() > 10) {
var headerH = "90";
} else {
var headerH = "90";
}
var target = $(this);
$("html, body")
.stop()
.animate({
scrollTop: $(target.attr("href")).offset().top - headerH + "px"
},
1200,
"easeInOutExpo"
);
anchor.removeClass("current");
anchor.removeClass("current-menu-ancestor");
anchor.removeClass("current_page_item");
anchor.removeClass("current-menu-parent");
target.parent().addClass("current");
event.preventDefault();
});
}
}
SmoothMenuScroll();
function OnePageMenuScroll() {
var windscroll = $(window).scrollTop();
if (windscroll >= 117) {
var menuAnchor = $(".one-page-scroll-menu .scrollToLink").children("a");
menuAnchor.each(function () {
var sections = $(this).attr("href");
$(sections).each(function () {
if ($(this).offset().top <= windscroll + 100) {
var Sectionid = $(sections).attr("id");
$(".one-page-scroll-menu").find("li").removeClass("current");
$(".one-page-scroll-menu").find("li").removeClass("current-menu-ancestor");
$(".one-page-scroll-menu").find("li").removeClass("current_page_item");
$(".one-page-scroll-menu").find("li").removeClass("current-menu-parent");
$(".one-page-scroll-menu")
.find("a[href*=\\#" + Sectionid + "]")
.parent()
.addClass("current");
}
});
});
} else {
$(".one-page-scroll-menu li.current").removeClass("current");
$(".one-page-scroll-menu li:first").addClass("current");
}
}
$(window).on("load", function () {
if ($(".preloader").length) {
$(".preloader").fadeOut();
}
projectMasonaryLayout();
if ($(".post-filter").length) {
var postFilterList = $(".post-filter li");
// for first init
$(".filter-layout").isotope({
filter: ".filter-item",
animationOptions: {
duration: 500,
easing: "linear",
queue: false,
},
});
// on click filter links
postFilterList.on("click", function () {
var Self = $(this);
var selector = Self.attr("data-filter");
postFilterList.removeClass("active");
Self.addClass("active");
$(".filter-layout").isotope({
filter: selector,
animationOptions: {
duration: 500,
easing: "linear",
queue: false,
},
});
return false;
});
}
if ($(".post-filter.has-dynamic-filter-counter").length) {
var activeFilterItem = $(".post-filter.has-dynamic-filter-counter").find(
"li"
);
activeFilterItem.each(function () {
var filterElement = $(this).data("filter");
var count = $(".filter-layout").find(filterElement).length;
$(this).append("<sup>[" + count + "]</sup>");
});
}
});
$(window).on("scroll", function () {
if ($(".stricked-menu").length) {
var headerScrollPos = 130;
var stricky = $(".stricked-menu");
if ($(window).scrollTop() > headerScrollPos) {
stricky.addClass("stricky-fixed");
} else if ($(this).scrollTop() <= headerScrollPos) {
stricky.removeClass("stricky-fixed");
}
}
if ($(".scroll-to-top").length) {
var strickyScrollPos = 100;
if ($(window).scrollTop() > strickyScrollPos) {
$(".scroll-to-top").fadeIn(500);
} else if ($(this).scrollTop() <= strickyScrollPos) {
$(".scroll-to-top").fadeOut(500);
}
}
OnePageMenuScroll();
});
})(jQuery);