formatted main.js

This commit is contained in:
Karma Riuk 2023-09-02 15:07:03 +02:00
parent 1c4cdb5155
commit a30c03c88c

View File

@ -1,254 +1,269 @@
/** /**
* Template Name: Laura * Template Name: Laura
* Updated: Jul 27 2023 with Bootstrap v5.3.1 * Updated: Jul 27 2023 with Bootstrap v5.3.1
* Template URL: https://bootstrapmade.com/laura-free-creative-bootstrap-theme/ * Template URL: https://bootstrapmade.com/laura-free-creative-bootstrap-theme/
* Author: BootstrapMade.com * Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/ * License: https://bootstrapmade.com/license/
*/ */
(function() { (function() {
"use strict"; "use strict";
/** /**
* Easy selector helper function * Easy selector helper function
*/ */
const select = (el, all = false) => { const select = (el, all = false) => {
el = el.trim() el = el.trim();
if (all) { if (all) {
return [...document.querySelectorAll(el)] return [...document.querySelectorAll(el)];
} else { } else {
return document.querySelector(el) return document.querySelector(el);
} }
} };
/** /**
* Easy event listener function * Easy event listener function
*/ */
const on = (type, el, listener, all = false) => { const on = (type, el, listener, all = false) => {
let selectEl = select(el, all) let selectEl = select(el, all);
if (selectEl) { if (selectEl) {
if (all) { if (all) {
selectEl.forEach(e => e.addEventListener(type, listener)) selectEl.forEach((e) => e.addEventListener(type, listener));
} else { } else {
selectEl.addEventListener(type, listener) selectEl.addEventListener(type, listener);
} }
} }
} };
/** /**
* Easy on scroll event listener * Easy on scroll event listener
*/ */
const onscroll = (el, listener) => { const onscroll = (el, listener) => {
el.addEventListener('scroll', listener) el.addEventListener("scroll", listener);
} };
/** /**
* Navbar links active state on scroll * Navbar links active state on scroll
*/ */
let navbarlinks = select('#navbar .scrollto', true) let navbarlinks = select("#navbar .scrollto", true);
const navbarlinksActive = () => { const navbarlinksActive = () => {
let position = window.scrollY + 200 let position = window.scrollY + 200;
navbarlinks.forEach(navbarlink => { navbarlinks.forEach((navbarlink) => {
if (!navbarlink.hash) return if (!navbarlink.hash) return;
let section = select(navbarlink.hash) let section = select(navbarlink.hash);
if (!section) return if (!section) return;
if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) { if (
navbarlink.classList.add('active') position >= section.offsetTop &&
} else { position <= section.offsetTop + section.offsetHeight
navbarlink.classList.remove('active') ) {
} navbarlink.classList.add("active");
}) } else {
} navbarlink.classList.remove("active");
window.addEventListener('load', navbarlinksActive) }
onscroll(document, navbarlinksActive) });
};
/** window.addEventListener("load", navbarlinksActive);
* Scrolls to an element with header offset onscroll(document, navbarlinksActive);
*/
const scrollto = (el) => { /**
let header = select('#header') * Scrolls to an element with header offset
let offset = header.offsetHeight */
const scrollto = (el) => {
if (!header.classList.contains('header-scrolled')) { let header = select("#header");
offset -= 20 let offset = header.offsetHeight;
}
if (!header.classList.contains("header-scrolled")) {
let elementPos = select(el).offsetTop offset -= 20;
window.scrollTo({ }
top: elementPos - offset,
behavior: 'smooth' let elementPos = select(el).offsetTop;
}) window.scrollTo({
} top: elementPos - offset,
behavior: "smooth",
/** });
* Toggle .header-scrolled class to #header when page is scrolled };
*/
let selectHeader = select('#header') /**
if (selectHeader) { * Toggle .header-scrolled class to #header when page is scrolled
const headerScrolled = () => { */
if (window.scrollY > 100) { let selectHeader = select("#header");
selectHeader.classList.add('header-scrolled') if (selectHeader) {
} else { const headerScrolled = () => {
selectHeader.classList.remove('header-scrolled') if (window.scrollY > 100) {
} selectHeader.classList.add("header-scrolled");
} } else {
window.addEventListener('load', headerScrolled) selectHeader.classList.remove("header-scrolled");
onscroll(document, headerScrolled) }
} };
window.addEventListener("load", headerScrolled);
/** onscroll(document, headerScrolled);
* Back to top button }
*/
let backtotop = select('.back-to-top') /**
if (backtotop) { * Back to top button
const toggleBacktotop = () => { */
if (window.scrollY > 100) { let backtotop = select(".back-to-top");
backtotop.classList.add('active') if (backtotop) {
} else { const toggleBacktotop = () => {
backtotop.classList.remove('active') if (window.scrollY > 100) {
} backtotop.classList.add("active");
} } else {
window.addEventListener('load', toggleBacktotop) backtotop.classList.remove("active");
onscroll(document, toggleBacktotop) }
} };
window.addEventListener("load", toggleBacktotop);
/** onscroll(document, toggleBacktotop);
* Mobile nav toggle }
*/
on('click', '.mobile-nav-toggle', function(e) { /**
select('#navbar').classList.toggle('navbar-mobile') * Mobile nav toggle
this.classList.toggle('bi-list') */
this.classList.toggle('bi-x') on("click", ".mobile-nav-toggle", function(e) {
}) select("#navbar").classList.toggle("navbar-mobile");
this.classList.toggle("bi-list");
/** this.classList.toggle("bi-x");
* Mobile nav dropdowns activate });
*/
on('click', '.navbar .dropdown > a', function(e) { /**
if (select('#navbar').classList.contains('navbar-mobile')) { * Mobile nav dropdowns activate
e.preventDefault() */
this.nextElementSibling.classList.toggle('dropdown-active') on(
} "click",
}, true) ".navbar .dropdown > a",
function(e) {
/** if (select("#navbar").classList.contains("navbar-mobile")) {
* Scrool with ofset on links with a class name .scrollto e.preventDefault();
*/ this.nextElementSibling.classList.toggle("dropdown-active");
on('click', '.scrollto', function(e) { }
if (select(this.hash)) { },
e.preventDefault() true,
);
let navbar = select('#navbar')
if (navbar.classList.contains('navbar-mobile')) { /**
navbar.classList.remove('navbar-mobile') * Scrool with ofset on links with a class name .scrollto
let navbarToggle = select('.mobile-nav-toggle') */
navbarToggle.classList.toggle('bi-list') on(
navbarToggle.classList.toggle('bi-x') "click",
} ".scrollto",
scrollto(this.hash) function(e) {
} if (select(this.hash)) {
}, true) e.preventDefault();
/** let navbar = select("#navbar");
* Scroll with ofset on page load with hash links in the url if (navbar.classList.contains("navbar-mobile")) {
*/ navbar.classList.remove("navbar-mobile");
window.addEventListener('load', () => { let navbarToggle = select(".mobile-nav-toggle");
if (window.location.hash) { navbarToggle.classList.toggle("bi-list");
if (select(window.location.hash)) { navbarToggle.classList.toggle("bi-x");
scrollto(window.location.hash) }
} scrollto(this.hash);
} }
}); },
true,
/** );
* Skills animation
*/ /**
let skilsContent = select('.skills-content'); * Scroll with ofset on page load with hash links in the url
if (skilsContent) { */
new Waypoint({ window.addEventListener("load", () => {
element: skilsContent, if (window.location.hash) {
offset: '80%', if (select(window.location.hash)) {
handler: function(direction) { scrollto(window.location.hash);
let progress = select('.progress .progress-bar', true); }
progress.forEach((el) => { }
el.style.width = el.getAttribute('aria-valuenow') + '%' });
});
} /**
}) * Skills animation
} */
let skilsContent = select(".skills-content");
/** if (skilsContent) {
* Testimonials slider new Waypoint({
*/ element: skilsContent,
new Swiper('.testimonials-slider', { offset: "80%",
speed: 600, handler: function(direction) {
loop: true, let progress = select(".progress .progress-bar", true);
autoplay: { progress.forEach((el) => {
delay: 5000, el.style.width = el.getAttribute("aria-valuenow") + "%";
disableOnInteraction: false });
}, },
slidesPerView: 'auto', });
pagination: { }
el: '.swiper-pagination',
type: 'bullets', /**
clickable: true * Testimonials slider
} */
}); new Swiper(".testimonials-slider", {
speed: 600,
/** loop: true,
* Porfolio isotope and filter autoplay: {
*/ delay: 5000,
window.addEventListener('load', () => { disableOnInteraction: false,
let portfolioContainer = select('.portfolio-container'); },
if (portfolioContainer) { slidesPerView: "auto",
let portfolioIsotope = new Isotope(portfolioContainer, { pagination: {
itemSelector: '.portfolio-item' el: ".swiper-pagination",
}); type: "bullets",
clickable: true,
let portfolioFilters = select('#portfolio-flters li', true); },
});
on('click', '#portfolio-flters li', function(e) {
e.preventDefault(); /**
portfolioFilters.forEach(function(el) { * Porfolio isotope and filter
el.classList.remove('filter-active'); */
}); window.addEventListener("load", () => {
this.classList.add('filter-active'); let portfolioContainer = select(".portfolio-container");
if (portfolioContainer) {
portfolioIsotope.arrange({ let portfolioIsotope = new Isotope(portfolioContainer, {
filter: this.getAttribute('data-filter') itemSelector: ".portfolio-item",
}); });
}, true); let portfolioFilters = select("#portfolio-flters li", true);
}
on(
}); "click",
"#portfolio-flters li",
/** function(e) {
* Initiate portfolio lightbox e.preventDefault();
*/ portfolioFilters.forEach(function(el) {
const portfolioLightbox = GLightbox({ el.classList.remove("filter-active");
selector: '.portfolio-lightbox' });
}); this.classList.add("filter-active");
/** portfolioIsotope.arrange({
* Portfolio details slider filter: this.getAttribute("data-filter"),
*/ });
new Swiper('.portfolio-details-slider', { },
speed: 400, true,
loop: true, );
autoplay: { }
delay: 5000, });
disableOnInteraction: false
}, /**
pagination: { * Initiate portfolio lightbox
el: '.swiper-pagination', */
type: 'bullets', const portfolioLightbox = GLightbox({
clickable: true selector: ".portfolio-lightbox",
} });
});
/**
/** * Portfolio details slider
* Initiate Pure Counter */
*/ new Swiper(".portfolio-details-slider", {
new PureCounter(); speed: 400,
loop: true,
})() autoplay: {
delay: 5000,
disableOnInteraction: false,
},
pagination: {
el: ".swiper-pagination",
type: "bullets",
clickable: true,
},
});
/**
* Initiate Pure Counter
*/
new PureCounter();
})();