/* * Version: 3.0 * Template: Qloud - Qloud Computing, Apps & Server HTML, WHMCS, Vue & Angular Template * Author: iqonic.design * Design and Developed by: iqonic.design * NOTE: This file contains the script for initialize & listener Template. */ /*---------------------------------------------- Index Of Script ------------------------------------------------ ------- Plugin Init -------- :: LoaderInit :: Sticky-Header :: Popover :: Tooltip :: CopyToClipboard :: Range Flatpickr :: Wrap Flatpickr :: Time Flatpickr :: Inline Flatpickr :: CounterUp 2 :: SliderTab :: Resize Plugins :: Back To Top :: DOMContentLoaded :: Window Resize :: Form Validation ------------------------------------------------ Index Of Script ----------------------------------------------*/ (function () { "use strict"; /*------------LoaderInit----------------*/ const loaderInit = () => { const loader = document.querySelector('.loader') if (loader !== null) { loader.classList.add('animate__animated', 'animate__fadeOut') setTimeout(() => { loader.classList.add('d-none') }, 200) } } /*----------Sticky-Header-----------*/ jQuery(window).scroll(function () { var sticky = jQuery('header .iq-navbar'), scroll = jQuery(window).scrollTop(); if (scroll >= 100) sticky.addClass('fixed'); else sticky.removeClass('fixed'); }); /*------------Popover--------------*/ const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')) if (typeof bootstrap !== typeof undefined) { popoverTriggerList.map(function (popoverTriggerEl) { return new bootstrap.Popover(popoverTriggerEl) }) } /*-------------Tooltip--------------------*/ if (typeof bootstrap !== typeof undefined) { const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }) const sidebarTooltipTriggerList = [].slice.call(document.querySelectorAll('[data-sidebar-toggle="tooltip"]')) sidebarTooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }) } /*------------Copy To Clipboard---------------*/ const copy = document.querySelectorAll('[data-toggle="copy"]') if (typeof copy !== typeof undefined) { Array.from(copy, (elem) => { elem.addEventListener('click', (e) => { const target = elem.getAttribute("data-copy-target"); let value = elem.getAttribute("data-copy-value"); const container = document.querySelector(target); if (container !== undefined && container !== null) { if (container.value !== undefined && container.value !== null) { value = container.value; } else { value = container.innerHTML; } } if (value !== null) { const elem = document.createElement("textarea"); document.querySelector("body").appendChild(elem); elem.value = value; elem.select(); document.execCommand("copy"); elem.remove(); } elem.setAttribute('data-bs-original-title', 'Copied!'); let btn_tooltip = bootstrap.Tooltip.getInstance(elem); btn_tooltip.show(); // reset the tooltip title elem.setAttribute('data-bs-original-title', 'Copy'); setTimeout(() => { btn_tooltip.hide(); }, 500) }) }); } /*-------------CounterUp 2--------------*/ if (window.counterUp !== undefined) { const counterUp = window.counterUp["default"]; const counterUp2 = document.querySelectorAll('.counter') Array.from(counterUp2, (el) => { if (typeof Waypoint !== typeof undefined) { const waypoint = new Waypoint({ element: el, handler: function () { counterUp(el, { duration: 1000, delay: 10, }); this.destroy(); }, offset: "bottom-in-view", }); } }) } /*----------------SliderTab------------------*/ Array.from(document.querySelectorAll('[data-toggle="slider-tab"]'), (elem) => { if (typeof SliderTab !== typeof undefined) { new SliderTab(elem) } }) let Scrollbar if (typeof Scrollbar !== typeof null) { if (document.querySelectorAll(".data-scrollbar").length) { Scrollbar = window.Scrollbar Scrollbar.init(document.querySelector('.data-scrollbar'), { continuousScrolling: false, }) } } /*------------Resize Plugins--------------*/ const resizePlugins = () => { // For sidebar-mini & responsive const tabs = document.querySelectorAll('.nav') if (window.innerWidth < 1025) { Array.from(tabs, (elem) => { if (!elem.classList.contains('flex-column') && elem.classList.contains('nav-tabs') && elem.classList.contains('nav-pills')) { elem.classList.add('flex-column', 'on-resize'); } }) } else { Array.from(tabs, (elem) => { if (elem.classList.contains('on-resize')) { elem.classList.remove('flex-column', 'on-resize'); } }) } } /*----------------Back To Top--------------------*/ const backToTop = document.getElementById("back-to-top") if (backToTop !== null && backToTop !== undefined) { document.getElementById("back-to-top").classList.add("animate__animated", "animate__fadeOut") window.addEventListener('scroll', (e) => { if (document.documentElement.scrollTop > 250) { document.getElementById("back-to-top").classList.remove("animate__fadeOut") document.getElementById("back-to-top").classList.add("animate__fadeIn") } else { document.getElementById("back-to-top").classList.remove("animate__fadeIn") document.getElementById("back-to-top").classList.add("animate__fadeOut") } }) // scroll body to 0px on click document.querySelector('#top').addEventListener('click', (e) => { e.preventDefault() window.scrollTo({ top: 0, behavior: 'smooth' }); }) } /*------------DOMContentLoaded--------------*/ document.addEventListener('DOMContentLoaded', (event) => { resizePlugins() loaderInit() }); /*------------Window Resize------------------*/ window.addEventListener('resize', function (event) { resizePlugins() }); /*--------DropDown--------*/ function darken_screen(yesno) { if (yesno == true) { if (document.querySelector('.screen-darken') !== null) { document.querySelector('.screen-darken').classList.add('active'); } } else if (yesno == false) { if (document.querySelector('.screen-darken') !== null) { document.querySelector('.screen-darken').classList.remove('active'); } } } function close_offcanvas() { darken_screen(false); if (document.querySelector('.mobile-offcanvas.show') !== null) { document.querySelector('.mobile-offcanvas.show').classList.remove('show'); document.body.classList.remove('offcanvas-active'); } } function show_offcanvas(offcanvas_id) { darken_screen(true); if (document.getElementById(offcanvas_id) !== null) { document.getElementById(offcanvas_id).classList.add('show'); document.body.classList.add('offcanvas-active'); } } document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll('[data-trigger]').forEach(function (everyelement) { let offcanvas_id = everyelement.getAttribute('data-trigger'); everyelement.addEventListener('click', function (e) { e.preventDefault(); show_offcanvas(offcanvas_id); }); }); if (document.querySelectorAll('.btn-close')) { document.querySelectorAll('.btn-close').forEach(function (everybutton) { everybutton.addEventListener('click', function (e) { close_offcanvas(); }); }); } if (document.querySelector('.screen-darken')) { document.querySelector('.screen-darken').addEventListener('click', function (event) { close_offcanvas(); }); } }); if (document.querySelector('#navbarSideCollapse')) { document.querySelector('#navbarSideCollapse').addEventListener('click', function () { document.querySelector('.offcanvas-collapse').classList.toggle('open') }) } /*---------------Form Validation--------------------*/ // Example starter JavaScript for disabling form submissions if there are invalid fields window.addEventListener('load', function () { // Fetch all the forms we want to apply custom Bootstrap validation styles to var forms = document.getElementsByClassName('needs-validation'); // Loop over them and prevent submission var validation = Array.prototype.filter.call(forms, function (form) { form.addEventListener('submit', function (event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add('was-validated'); }, false); }); }, false); })();