1 line
10 KiB
JavaScript
Executable File
1 line
10 KiB
JavaScript
Executable File
var app={id:"#app",class:"app",isMobile:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||window.innerWidth<767,darkMode:{attr:"data-bs-theme",value:"dark",eventName:"theme-reload"},rtlMode:{attr:"dir",value:"rtl"},themePanel:{class:"theme-panel",toggleAttr:'data-toggle="theme-panel-expand"',cookieName:"theme-panel-expand",activeClass:"active",themeListCLass:"theme-list",themeListItemCLass:"theme-list-item",theme:{toggleAttr:'data-toggle="theme-selector"',cookieName:"app-theme",activeClass:"active",classAttr:"data-theme-class"},themeDarkMode:{class:"dark-mode",toggleAttr:'name="app-theme-dark-mode"',cookieName:"app-theme-dark-mode"},themeRtlMode:{toggleAttr:'name="app-theme-rtl-mode"',cookieName:"app-theme-rtl-mode"}},font:{},color:{},variablePrefix:"bs-",variableFontList:["body-font-family","body-font-size","body-font-weight","body-line-height"],variableColorList:["theme","theme-rgb","theme-color","theme-color-rgb","component-color","component-color-rgb","component-bg","component-bg-rgb","component-secondary-bg","component-bg-rgb","component-tertiary-bg","component-tertiary-bg-rgb","default","default-rgb","primary","primary-rgb","primary-bg-subtle","primary-text","primary-border-subtle","secondary","secondary-rgb","secondary-bg-subtle","secondary-text","secondary-border-subtle","success","success-rgb","success-bg-subtle","success-text","success-border-subtle","warning","warning-rgb","warning-bg-subtle","warning-text","warning-border-subtle","info","info-rgb","info-bg-subtle","info-text","info-border-subtle","danger","danger-rgb","danger-bg-subtle","danger-text","danger-border-subtle","light","light-rgb","light-bg-subtle","light-text","light-border-subtle","dark","dark-rgb","dark-bg-subtle","dark-text","dark-border-subtle","black","black-rgb","blue","blue-rgb","inverse","inverse-rgb","white","white-rgb","red","red-rgb","teal","teal-rgb","indigo","indigo-rgb","orange","orange-rgb","purple","purple-rgb","yellow","yellow-rgb","green","green-rgb","pink","pink-rgb","cyan","cyan-rgb","gray","gray-rgb","lime","lime-rgb","gray-100","gray-200","gray-300","gray-400","gray-500","gray-600","gray-700","gray-800","gray-900","gray-100-rgb","gray-200-rgb","gray-300-rgb","gray-400-rgb","gray-500-rgb","gray-600-rgb","gray-700-rgb","gray-800-rgb","gray-900-rgb","muted","muted-rgb","emphasis-color","emphasis-color-rgb","heading-color","body-bg","body-bg-rgb","body-color","body-color-rgb","secondary-color","secondary-color-rgb","secondary-bg","secondary-bg-rgb","tertiary-color","tertiary-color-rgb","tertiary-bg","tertiary-bg-rgb","link-color","link-color-rgb","link-hover-color","link-hover-color-rgb","border-color","border-color-translucent"],breakpoints:{xs:0,sm:576,md:768,lg:992,xl:1200,xxl:1400,xxxl:1800}},slideUp=function(e,t=app.animation.speed){e.classList.contains("transitioning")||(e.classList.add("transitioning"),e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.boxSizing="border-box",e.style.height=e.offsetHeight+"px",e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,window.setTimeout(()=>{e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property"),e.classList.remove("transitioning")},t))},slideDown=function(t,a=app.animation.speed){if(!t.classList.contains("transitioning")){t.classList.add("transitioning"),t.style.removeProperty("display");let e=window.getComputedStyle(t).display;"none"===e&&(e="block"),t.style.display=e;var o=t.offsetHeight;t.style.overflow="hidden",t.style.height=0,t.style.paddingTop=0,t.style.paddingBottom=0,t.style.marginTop=0,t.style.marginBottom=0,t.style.boxSizing="border-box",t.style.transitionProperty="height, margin, padding",t.style.transitionDuration=a+"ms",t.style.height=o+"px",t.style.removeProperty("padding-top"),t.style.removeProperty("padding-bottom"),t.style.removeProperty("margin-top"),t.style.removeProperty("margin-bottom"),window.setTimeout(()=>{t.style.removeProperty("height"),t.style.removeProperty("overflow"),t.style.removeProperty("transition-duration"),t.style.removeProperty("transition-property"),t.classList.remove("transitioning")},a)}},slideToggle=function(e,t=app.animation.speed){return("none"===window.getComputedStyle(e).display?slideDown:slideUp)(e,t)},setCookie=function(e,t){var a=new Date,o=a.getTime();a.setTime(o+36e6),document.cookie=e+"="+t+";expires="+a.toUTCString()+";path=/"},getCookie=function(e){var a=e+"=",o=decodeURIComponent(document.cookie).split(";");for(let t=0;t<o.length;t++){let e=o[t];for(;" "==e.charAt(0);)e=e.substring(1);if(0==e.indexOf(a))return e.substring(a.length,e.length)}return""},handleHeaderFixedTop=function(){var e,t;0!==$('#header[data-fixed-top="true"]').length&&(e=$("#top-nav").height(),t=$("#header").height(),$(window).on("scroll",function(){$(window).scrollTop()>=e?($("body").css("padding-top",t),$("#header").addClass("header-fixed")):($("#header").removeClass("header-fixed"),$("body").css("padding-top","0"))}))},handleTooltipPopoverActivation=function(){0!==$("[data-bs-toggle=tooltip]").length&&$("[data-bs-toggle=tooltip]").tooltip(),0!==$("[data-bs-toggle=popover]").length&&$("[data-bs-toggle=popover]").popover()},handleThemePanel=function(){var e=document.querySelector("["+app.themePanel.toggleAttr+"]"),t=(e&&(e.onclick=function(e){e.preventDefault();var e=document.querySelector("."+app.themePanel.class),t=!e.classList.contains(app.themePanel.activeClass);e.classList.toggle(app.themePanel.activeClass),setCookie(app.themePanel.cookieName,t)}),[].slice.call(document.querySelectorAll("."+app.themePanel.class+" ["+app.themePanel.theme.toggleAttr+"]")));t&&t.map(function(o){o.onclick=function(){for(var e=this.getAttribute(app.themePanel.theme.classAttr),t=0;t<document.body.classList.length;t++){var a=document.body.classList[t];-1<a.search("theme-")&&document.body.classList.remove(a)}e&&document.body.classList.add(e),[].slice.call(document.querySelectorAll("."+app.themePanel.class+" ["+app.themePanel.theme.toggleAttr+"]")).map(function(e){e!=o?e.closest("."+app.themePanel.themeListItemCLass).classList.remove(app.themePanel.theme.activeClass):e.closest("."+app.themePanel.themeListItemCLass).classList.add(app.themePanel.theme.activeClass)}),setCookie(app.themePanel.theme.cookieName,e)}}),(t=[].slice.call(document.querySelectorAll("."+app.themePanel.class+" ["+app.themePanel.themeDarkMode.toggleAttr+"]"))).map(function(e){e.onchange=function(){this.checked?document.querySelector("html").setAttribute(app.darkMode.attr,app.darkMode.value):document.querySelector("html").removeAttribute(app.darkMode.attr),App.initVariable(),setCookie(app.themePanel.themeDarkMode.cookieName,this.checked?app.themePanel.themeDarkMode.class:""),document.dispatchEvent(new CustomEvent(app.darkMode.eventName))}}),(e=document.querySelector("."+app.themePanel.class+" ["+app.themePanel.themeRtlMode.toggleAttr+"]"))&&(e.onchange=function(){this.checked?document.querySelector("html").setAttribute(app.rtlMode.attr,app.rtlMode.value):document.querySelector("html").removeAttribute(app.rtlMode.attr),setCookie(app.themePanel.themeRtlMode.cookieName,!!this.checked)}),getCookie(app.themePanel.cookieName)&&"true"==getCookie(app.themePanel.cookieName)&&(e=document.querySelector("."+app.themePanel.class+" ["+app.themePanel.toggleAttr+"]"))&&e.click(),getCookie(app.themePanel.theme.cookieName)&&(e=document.querySelector("."+app.themePanel.class+" ["+app.themePanel.theme.toggleAttr+"]["+app.themePanel.theme.classAttr+'="'+getCookie(app.themePanel.theme.cookieName)+'"]'))&&e.click(),getCookie(app.themePanel.themeDarkMode.cookieName)&&(e=document.querySelector("."+app.themePanel.class+" ["+app.themePanel.themeDarkMode.toggleAttr+"]"))&&(e.checked=!0,e.onchange()),"true"==getCookie(app.themePanel.themeRtlMode.cookieName)&&(e=document.querySelector("."+app.themePanel.class+" ["+app.themePanel.themeRtlMode.toggleAttr+"]"))&&(e.checked=!0,e.onchange())},handlePaymentTypeSelection=function(){$(document).on("click",'[data-click="set-payment"]',function(e){e.preventDefault();var e=$(this).closest("li"),t=$(this).attr("data-value");$('[data-click="set-payment"]').closest("li").not(e).removeClass("active"),$('[data-id="payment-type"]').val(t),$(e).addClass("active")})},handleQtyControl=function(){$(document).on("click",'[data-click="increase-qty"]',function(e){e.preventDefault();var e=$(this).attr("data-target"),t=parseInt($(e).val())+1;$(e).val(t)}),$('[data-click="decrease-qty"]').click(function(e){e.preventDefault();var e=$(this).attr("data-target"),t=(t=parseInt($(e).val())-1)<0?0:t;$(e).val(t)})},handleProductImage=function(){$(document).on("click",'[data-click="show-main-image"]',function(e){e.preventDefault();var e='<img src="'+$(this).attr("data-url")+'" />',t=$(this).closest("li");$('[data-id="main-image"]').html(e),$(t).addClass("active"),$('[data-click="show-main-image"]').closest("li").not(t).removeClass("active")})},handleParoller=function(){void 0!==$.fn.paroller&&0!==$('[data-paroller="true"]').length&&$('[data-paroller="true"]').paroller()},handleCheckBootstrapVersion=function(){return parseInt($.fn.tooltip.Constructor.VERSION)},handleCssVariable=function(){var e=getComputedStyle(document.body);if(app.variableFontList&&app.variablePrefix)for(var t=0;t<app.variableFontList.length;t++)app.font[app.variableFontList[t].replace(/-([a-z|0-9])/g,(e,t)=>t.toUpperCase())]=e.getPropertyValue("--"+app.variablePrefix+app.variableFontList[t]).trim();if(app.variableColorList&&app.variablePrefix)for(t=0;t<app.variableColorList.length;t++)app.color[app.variableColorList[t].replace(/-([a-z|0-9])/g,(e,t)=>t.toUpperCase())]=e.getPropertyValue("--"+app.variablePrefix+app.variableColorList[t]).trim()},App={init:function(){handleHeaderFixedTop(),handleTooltipPopoverActivation(),handleThemePanel(),handlePaymentTypeSelection(),handleQtyControl(),handleProductImage(),handleParoller(),this.initVariable()},initVariable:function(){handleCssVariable()}};$(document).ready(function(){App.init()}); |