var resourceQueue = []; var interactionDetected = false; var callbacksMap = new Map(); //---------------------------------- function Spectro_LoadJS(scriptUrl, callback) { var script = document.createElement('script'); script.src = scriptUrl; script.async = false; script.onload = function() { if (callback) callback(); if (scriptUrl.includes('spectro-js')) Spectro_Start(); }; script.onerror = function() { console.error('Failed to load script: ' + scriptUrl); }; document.head.appendChild(script); } //---------------------------------- function Spectro_LoadCSS(cssUrl, callback) { var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = cssUrl; link.onload = function() { document.body.classList.remove('preload'); if (callback) callback(); }; link.onerror = function() { console.error('Failed to load CSS: ' + cssUrl); }; document.head.appendChild(link); } //---------------------------------- function Spectro_PostLoad() { if (interactionDetected) return; interactionDetected = true; document.removeEventListener('mousemove', Spectro_PostLoad); document.removeEventListener('scroll', Spectro_PostLoad); document.removeEventListener('touchstart', Spectro_PostLoad); while (resourceQueue.length > 0) { var url = resourceQueue.shift(); var callback = callbacksMap.get(url); var fileType = url.split('?')[0].split('.').pop().toLowerCase(); if (fileType === 'js' || url.includes('spectro-js') || url.includes('spectrocms-js')) Spectro_LoadJS(url, callback); else if (fileType === 'css') Spectro_LoadCSS(url, callback); } } //---------------------------------- function Spectro_Include(fileUrl, callback = false) { var fileType = fileUrl.split('?')[0].split('.').pop().toLowerCase(); if (interactionDetected) { if (fileType === 'js') { Spectro_LoadJS(fileUrl, callback); } else if (fileType === 'css') { Spectro_LoadCSS(fileUrl, callback); } } else { resourceQueue.push(fileUrl); callbacksMap.set(fileUrl, callback); } } //---------------------------------- document.addEventListener('mousemove', Spectro_PostLoad, { once: true }); document.addEventListener('scroll', Spectro_PostLoad, { once: true, passive: true }); document.addEventListener('touchstart', Spectro_PostLoad, { once: true, passive: true }); //---------------------------------- Spectro_Include('https://temp1.siteconst.ru/spectro-js/1/'); Spectro_Include('https://temp1.siteconst.ru/spectro.css'); Spectro_Include('https://temp1.siteconst.ru/blocks1.css'); Spectro_Include('https://temp1.siteconst.ru/sitecss-style1-min.css'); Spectro_Include('https://temp1.siteconst.ru/sitecss-flexslider-min.css'); Spectro_Include('https://temp1.siteconst.ru/js/jquery.flexslider.js'); Spectro_Include('https://temp1.siteconst.ru/js/jquery.easing.compatibility.js'); Spectro_Include('https://temp1.siteconst.ru/js/menu.js'); //----------------------------------