forked from eatvio/eatvio-infra
1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
(()=>{"use strict";const e=document.body;function t(t){let n=t||"lock",o=e.classList.contains(n)?"0px":window.innerWidth-document.querySelector(".wrapper").offsetWidth+"px";e.style.setProperty("--lock-padding",o),e.classList.toggle(n)}const n=()=>{document.querySelectorAll(".dropdown").forEach((function(e){const t=e.querySelector(".dropdown__button"),n=e.querySelector(".dropdown__list"),o=n.querySelectorAll(".dropdown__list-item"),i=e.querySelector(".dropdown__input");t.addEventListener("click",(function(){n.classList.toggle("visible"),this.classList.toggle("active")})),o.forEach((function(e){e.addEventListener("click",(function(e){o.forEach((function(e){e.classList.remove("active")})),e.target.classList.add("active"),t.innerHTML=this.innerHTML,i.value=this.dataset.value,n.classList.remove("visible"),t.classList.remove("active")}))})),document.addEventListener("click",(function(e){e.target!==t&&(t.classList.remove("active"),n.classList.remove("visible"))})),document.addEventListener("keydown",(function(e){"Tab"!==e.key&&"Escape"!==e.key||(t.classList.remove("active"),n.classList.remove("visible"))}))}))},o=()=>{function e(e,t,n,o){void 0===t&&(t=400),void 0===o&&(o=!1),e.style.overflow="hidden",o&&(e.style.display="block");var i,l=window.getComputedStyle(e),s=parseFloat(l.getPropertyValue("height")),r=parseFloat(l.getPropertyValue("padding-top")),a=parseFloat(l.getPropertyValue("padding-bottom")),c=parseFloat(l.getPropertyValue("margin-top")),d=parseFloat(l.getPropertyValue("margin-bottom")),u=s/t,p=r/t,m=a/t,g=c/t,y=d/t;window.requestAnimationFrame((function l(f){void 0===i&&(i=f);var v=f-i;o?(e.style.height=u*v+"px",e.style.paddingTop=p*v+"px",e.style.paddingBottom=m*v+"px",e.style.marginTop=g*v+"px",e.style.marginBottom=y*v+"px"):(e.style.height=s-u*v+"px",e.style.paddingTop=r-p*v+"px",e.style.paddingBottom=a-m*v+"px",e.style.marginTop=c-g*v+"px",e.style.marginBottom=d-y*v+"px"),v>=t?(e.style.height="",e.style.paddingTop="",e.style.paddingBottom="",e.style.marginTop="",e.style.marginBottom="",e.style.overflow="",o||(e.style.display="none"),"function"==typeof n&&n()):window.requestAnimationFrame(l)}))}HTMLElement.prototype.slideToggle=function(t,n){0===this.clientHeight?e(this,t,n,!0):e(this,t,n)},HTMLElement.prototype.slideUp=function(t,n){e(this,t,n)},HTMLElement.prototype.slideDown=function(t,n){e(this,t,n,!0)}};document.addEventListener("DOMContentLoaded",(()=>{(()=>{function e(e){const n=document.querySelector('[data-modal="open"]');e.classList.remove("open"),e.removeAttribute("tabindex"),e.setAttribute("aria-hidden",!0),n.setAttribute("aria-expanded",!0),n.setAttribute("data-modal",""),t()}document.addEventListener("click",(n=>{const o=n.target;if(o.closest("[data-modal]")){const i=o.closest("[data-modal]"),l=i.getAttribute("href").replace("#",""),s=document.getElementById(l);s&&function(n,o){const i=document.querySelector(".popup.open");i?e(i):t(),n.classList.add("open"),n.setAttribute("aria-hidden",!1),n.setAttribute("tabindex","-1"),o.setAttribute("aria-expanded",!1),o.setAttribute("data-modal","open")}(s,i),n.preventDefault()}o.closest("[data-close-modal]")&&(e(o.closest(".popup")),n.preventDefault()),o.classList.contains("popup__content")&&e(o.closest(".popup"))})),document.addEventListener("keydown",(function(t){if("Escape"===t.key){const t=document.querySelector(".popup.open");t&&e(t)}"Enter"===t.key&&document.querySelector(".popup.open")&&t.preventDefault()}))})(),(()=>{let e;document.onmouseover=function(t){let n=t.target,o=n.dataset.tooltip;if(!o)return;e=document.createElement("div"),e.className="tooltip",e.innerHTML=o,document.body.append(e);let i=n.getBoundingClientRect(),l=i.left+(n.offsetWidth-e.offsetWidth)/2;l<0&&(l=0);let s=i.top-e.offsetHeight-5;s<0&&(s=i.top+n.offsetHeight+5),e.style.left=l+"px",e.style.top=s+"px"},document.onmouseout=function(t){e&&(e.remove(),e=null)}})(),(()=>{const e=document.querySelectorAll("[data-maxlength]");!e.length>0||e.forEach((e=>{const t=e.getAttribute("maxlength"),n=document.getElementById(e.dataset.maxlength),o=n.querySelector(".label__quantity-current");n.querySelector(".label__quantity-total").innerHTML=t,e.addEventListener("input",(e=>{o.innerHTML=e.target.value.length,e.target.value.slice(0,t)}))}))})(),n(),(()=>{const e=document.querySelectorAll("[data-checking-item]");if(!e.length>0)return;const t=document.querySelector("[data-checking-value]");function n(){let t=0;return e.forEach((e=>{e.checked&&t++})),t}t.innerHTML=n(),e.forEach((e=>{e.addEventListener("change",(()=>{t.innerHTML=n()}))}))})(),(()=>{const e=document.querySelector(".announcement__carousel");if(!e)return;let t,n,o=!1;e.addEventListener("pointerdown",(i=>{o=!0,e.classList.add("active"),t=i.pageX-e.offsetLeft,n=e.scrollLeft})),e.addEventListener("pointerleave",(()=>{o=!1,e.classList.remove("active")})),e.addEventListener("pointerup",(()=>{o=!1,e.classList.remove("active")})),e.addEventListener("pointermove",(i=>{if(!o)return;i.preventDefault();const l=2*(i.pageX-e.offsetLeft-t);e.scrollLeft=n-l,console.log(l)}))})(),(()=>{const e=document.querySelector(".icon-menu"),t=document.querySelector(".header__menu");e&&e.addEventListener("click",(function(n){document.body.classList.toggle("lock"),e.classList.toggle("active"),t.classList.toggle("active")}))})(),(()=>{const e=document.querySelector(".fixed-columns");if(!e)return;let t=e.parentElement,n=e.cloneNode(!0);n.classList.add("clone"),t.appendChild(n);let o=e.rows;for(let e=0;e<o.length;e++){const t=o[e].children;for(let e=0;e<t.length;e++){const n=t[e];n.querySelector(".checkbox")&&(n.innerHTML="")}}})(),o(),(()=>{const e=document.querySelectorAll("[data-spollers]");if(e.length>0){const t=Array.from(e).filter((function(e,t,n){return!e.dataset.spollers.split(",")[0]}));t.length>0&&o(t);const n=Array.from(e).filter((function(e,t,n){return e.dataset.spollers.split(",")[0]}));if(n.length>0){const e=[];n.forEach((t=>{const n={},o=t.dataset.spollers.split(",");n.value=o[0],n.type=o[1]?o[1].trim():"max",n.item=t,e.push(n)}));let t=e.map((function(e){return"("+e.type+"-width: "+e.value+"px),"+e.value+","+e.type}));t=t.filter((function(e,t,n){return n.indexOf(e)===t})),t.forEach((t=>{const n=t.split(","),i=n[1],l=n[2],s=window.matchMedia(n[0]),r=e.filter((function(e){if(e.value===i&&e.type===l)return!0}));s.addListener((function(){o(r,s)})),o(r,s)}))}function o(e,t=!1){e.forEach((e=>{e=t?e.item:e,t.matches||!t?(e.classList.add("_init"),i(e),e.addEventListener("click",l)):(e.classList.remove("_init"),i(e,!1),e.removeEventListener("click",l))}))}function i(e,t=!0){const n=e.querySelectorAll("[data-spoller]");n.length>0&&n.forEach((e=>{t?(e.removeAttribute("tabindex"),e.classList.contains("_active")||(e.nextElementSibling.hidden=!0)):(e.setAttribute("tabindex","-1"),e.nextElementSibling.hidden=!1)}))}function l(e){const t=e.target;if(t.hasAttribute("data-spoller")||t.closest("[data-spoller]")){const n=t.hasAttribute("data-spoller")?t:t.closest("[data-spoller]"),o=n.closest("[data-spollers]"),i=!!o.hasAttribute("data-one-spoller");o.querySelectorAll("._slide").length||(i&&!n.classList.contains("_active")&&s(o),n.classList.toggle("_active"),n.nextElementSibling.slideToggle(300)),e.preventDefault()}}function s(e){const t=e.querySelector("[data-spoller]._active");t&&(t.classList.remove("_active"),t.nextElementSibling.slideUp(300))}}})(),document.addEventListener("click",(e=>{if(e.target.hasAttribute("data-setting")){let t=e.target.dataset.setting;document.getElementById(t).classList.toggle("visible")}})),document.querySelector(".diary__product-slider")&&new Swiper(".diary__product-slider",{speed:800,slidesPerView:1,loop:!0,navigation:{nextEl:".diary__product-next",prevEl:".diary__product-prev"}}),document.querySelectorAll(".diary__setting").length>0&&document.querySelectorAll(".diary__setting").forEach((e=>{const t=e.querySelector(".diary__setting-prev"),n=e.querySelector(".diary__setting-next"),o=e.querySelector(".diary__setting-content");new Swiper(o,{speed:800,slidesPerView:5,direction:"vertical",navigation:{nextEl:n,prevEl:t}})}))}))})(); |