-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
1 lines (1 loc) · 10.8 KB
/
script.js
1
!function(){"use strict";var e=()=>{document.querySelector(".pulse").classList.add("animated","pulse"),document.querySelector(".popup-wrap").classList.add("animated","pulse");let e=!1;function t(t,n,o){let l=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const s=document.querySelectorAll(t),a=document.querySelector(n),i=document.querySelector(o),c=document.querySelectorAll("[data-modal]"),r=function(){let e=document.createElement("div");e.style.width="50px",e.style.height="50px",e.style.overflow="scroll",e.style.visibility="hidden",document.body.appendChild(e);let t=e.offsetWidth-e.clientWidth;return e.remove(),t}(),d=document.querySelector(".fixed-gift");s.forEach((t=>{t.addEventListener("click",(n=>{n.target&&n.preventDefault(),e=!0,l&&t.remove(),c.forEach((e=>{e.style.display="none",e.classList.add("animated","fadeIn")})),a.style.display="block",document.body.style.overflow="hidden",d.style.marginRight="17px",document.body.style.marginRight=`${r}px`}))})),i.addEventListener("click",(()=>{c.forEach((e=>{e.style.display="none"})),a.style.display="none",document.body.style.overflow="",d.style.marginRight="0px",document.body.style.marginRight="0px"})),a.addEventListener("click",(e=>{e.target===a&&(c.forEach((e=>{e.style.display="none"})),a.style.display="none",document.body.style.overflow="",d.style.marginRight="0",document.body.style.marginRight="0px")}))}t(".button-design",".popup-design",".popup-design .popup-close"),t(".button-consultation",".popup-consultation",".popup-consultation .popup-close"),t(".fixed-gift",".popup-gift",".popup-gift .popup-close",!0),window.addEventListener("scroll",(()=>{let t=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);!e&&window.scrollY+document.documentElement.clientHeight>=t&&document.querySelector(".fixed-gift").click()}))},t=(e,t,n,o)=>{let l=1,s=!1;const a=document.querySelectorAll(e);function i(e){e>a.length&&(l=1),e<1&&(l=a.length),a.forEach((e=>{e.classList.add("animated"),e.style.display="none"})),a[l-1].style.display="block"}function c(e){i(l+=e)}i(l);try{const e=document.querySelector(n),t=document.querySelector(o);e.addEventListener("click",(()=>{c(-1),a[l-1].classList.remove("slideInRight"),a[l-1].classList.add("slideInLeft")})),t.addEventListener("click",(()=>{c(1),a[l-1].classList.remove("slideInLeft"),a[l-1].classList.add("slideInRight")}))}catch(e){}function r(){s="vertical"===t?setInterval((function(){c(1),a[l-1].classList.add("slideInDown"),document.body.style.overflowX="hidden"}),3e3):setInterval((function(){c(1),a[l-1].classList.remove("slideInLeft"),a[l-1].classList.add("slideInRight"),document.body.style.overflowX="hidden"}),3e3)}r(),a[0].parentNode.addEventListener("mouseenter",(()=>{clearInterval(s)})),a[0].parentNode.addEventListener("mouseleave",(()=>{r()}))},n=e=>{function t(e){let t="+7 (___) ___ __ __",n=0,o=t.replace(/\D/g,""),l=this.value.replace(/\D/g,"");o.length>=l.length&&(l=o),this.value=t.replace(/./g,(function(e){return/[_\d]/.test(e)&&n<l.length?l.charAt(n++):n>=l.length?"":e})),"blur"===e.type?2==this.value.length&&(this.value=""):((e,t)=>{if(t.focus(),t.setSelectionRange)t.setSelectionRange(e,e);else if(t.createTextRange){let n=t.createTextRange();n.collapse(!0),n.moveEnd("character",e),n.moveStart("character",e),n.select()}})(this.value.length,this)}document.querySelectorAll(e).forEach((e=>{e.addEventListener("input",t),e.addEventListener("focus",t),e.addEventListener("blur",t)}))},o=e=>{document.querySelectorAll(e).forEach((e=>{e.addEventListener("keypress",(function(e){e.key.match(/[^а-яё 0-9]/gi)&&e.preventDefault()}))}))},l=(e,t)=>{document.querySelector(e).addEventListener("click",(function(){(async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Could not fetch ${e}, status: ${t.status}`);return await t.json()})("assets/db.json").then((e=>{e.styles.forEach((e=>{let{src:n,title:o,link:l}=e,s=document.createElement("div");s.classList.add("animated","fadeInUp","col-sm-3","col-sm-offset-0","col-xs-10","col-xs-offset-1"),s.innerHTML=`\n\t\t\t\t<div class="styles-block">\n\t\t\t\t\t<img src=${n} alt="style">\n\t\t\t\t\t<h4>${o}</h4>\n\t\t\t\t\t<a href=${l}>Подробнее</a>\n\t\t\t\t</div>\n\t\t\t`,document.querySelector(t).appendChild(s)}))})).catch((e=>console.log(e))),this.remove()}))},s=e=>{const t=document.querySelectorAll(e);t.forEach((e=>{e.addEventListener("click",(function(){this.classList.contains("active-style")||t.forEach((e=>{e.classList.remove("active-style"),e.nextElementSibling.classList.remove("active-content"),e.nextElementSibling.style.maxHeight="0px"})),this.classList.toggle("active-style"),this.nextElementSibling.classList.toggle("active-content"),this.classList.contains("active-style")?this.nextElementSibling.style.maxHeight=this.nextElementSibling.scrollHeight+80+"px":this.nextElementSibling.style.maxHeight="0px"}))}))},a=e=>{const t=document.querySelector(e);window.addEventListener("scroll",(()=>{document.documentElement.scrollTop>1650?(t.classList.add("animated","fadeIn"),t.classList.remove("fadeOut")):(t.classList.add("fadeOut"),t.classList.remove("fadeIn"))})),document.querySelectorAll('[href^="#"]').forEach((e=>{e.addEventListener("click",(function(e){e.preventDefault();let t=document.documentElement.scrollTop,n=this.hash,o=document.querySelector(n).getBoundingClientRect().top,l=null;requestAnimationFrame((function e(s){null===l&&(l=s);let a=s-l,i=o<0?Math.max(t-a/.4,t+o):Math.min(t+a/.4,t+o);document.documentElement.scrollTo(0,i),i!=t+o?requestAnimationFrame(e):location.hash=n}))}))}))};window.addEventListener("DOMContentLoaded",(function(){var i;e(),t(".feedback-slider-item","horizontal",".main-prev-btn",".main-next-btn"),t(".main-slider-item","vertical"),(()=>{const e=document.querySelectorAll("form"),t=document.querySelectorAll("input"),n=document.querySelectorAll('[name="message"]'),o=document.querySelectorAll('[name="upload"]');o.forEach((e=>{e.addEventListener("input",(()=>{let t;console.log(e.files[0]);const n=e.files[0].name.split(".");t=n[0].length>6?"...":".";const o=n[0].substring(0,6)+t+n[1];e.previousElementSibling.textContent=o}))})),e.forEach((e=>{e.addEventListener("submit",(l=>{l.preventDefault();let s=document.createElement("div");s.classList.add("status"),e.parentNode.appendChild(s),e.classList.add("animated","fadeOutUp"),setTimeout((()=>{e.style.display="none"}),400);let a=document.createElement("img");a.setAttribute("src","assets/img/spinner.gif"),a.classList.add("animated","fadeInUp"),s.appendChild(a);let i=document.createElement("div");i.textContent="Загрузка...",s.appendChild(i);const c=new FormData(e);let r;r=e.closest(".popup-design")||e.classList.contains("calc_form")?"assets/server.php":"assets/question.php",console.log(r),(async(e,t)=>{let n=await fetch(e,{method:"POST",body:t});return await n.text()})(r,c).then((e=>{console.log(e),a.setAttribute("src","assets/img/ok.png"),i.textContent="Спасибо,Мы скоро с вами свяжемся!"})).catch((()=>{a.setAttribute("src","assets/img/fail.png"),i.textContent="Что-то пошло не так..."})).finally((()=>{t.forEach((e=>{e.value=""})),n.forEach((e=>{e.value=""})),o.forEach((e=>{e.previousElementSibling.textContent="Файл не выбран"})),setTimeout((()=>{s.remove(),e.style.display="block",e.classList.remove("fadeOutUp"),e.classList.add("fadeInUp")}),5e3)}))}))}))})(),n('[name="phone"]'),o('[name="name"]'),o('[name="message"]'),l(".button-styles","#styles .row"),((e,t,n,o,l)=>{const s=document.querySelector(e),a=document.querySelector(t),i=document.querySelector(n),c=document.querySelector(o),r=document.querySelector(l);let d=0;const u=()=>{d=Math.round(+s.value*+a.value+ +i.value),""==s.value||""==a.value?r.textContent="Пожалуйста, выберите размер и материал картины":"IWANTPOPART"===c.value?r.textContent=Math.round(.7*d):r.textContent=d};s.addEventListener("change",u),a.addEventListener("change",u),i.addEventListener("change",u),c.addEventListener("input",u)})("#size","#material","#options",".promocode",".calc-price"),(()=>{const e=document.querySelector(".portfolio-menu"),t=document.querySelectorAll("li"),n=document.querySelector(".portfolio-wrapper"),o=n.querySelectorAll(".all"),l=document.querySelector(".portfolio-no");e.addEventListener("click",(e=>{let o=e.target;o&&"LI"==o.tagName&&(t.forEach((e=>e.classList.remove("active"))),o.classList.add("active")),n.style.justifyContent="center"}));const s=(e,t)=>{const n=document.querySelector(e);n&&n.addEventListener("click",(()=>{var e;e=document.querySelectorAll(t),o.forEach((e=>{e.style.display="none",e.classList.remove("animated","fadeIn")})),l.style.display="none",l.classList.remove("animated","fadeIn"),e?e.forEach((e=>{e.style.display="block",e.classList.add("animated","fadeIn")})):(l.style.display="block",l.classList.add("animated","fadeIn"))}))};s(".portfolio-menu .all",".all"),s(".portfolio-menu .chef",".chef"),s(".portfolio-menu .girl",".girl"),s(".portfolio-menu .guy",".guy"),s(".portfolio-menu .grandmother",".portfolio-no"),s(".portfolio-menu .granddad",".portfolio-no"),s(".portfolio-menu .lovers",".lovers")})(),i=".sizes-block",document.querySelectorAll(i).forEach((e=>{e.addEventListener("mouseover",(()=>{!function(e){const t=e.querySelector("img");t.src=t.src.slice(0,-4)+"-1.png",e.querySelectorAll("p:not(.sizes-hit)").forEach((e=>{e.style.display="none"}))}(e),e.classList.add("animated","fadeIn")})),e.addEventListener("mouseout",(()=>{!function(e){const t=e.querySelector("img");t.src=t.src.slice(0,-6)+".png",e.querySelectorAll("p:not(.sizes-hit)").forEach((e=>{e.style.display="block"}))}(e),e.classList.remove("animated","fadeIn")}))})),s(".accordion-heading"),((e,t)=>{const n=document.querySelector(e),o=document.querySelector(t);n.style.display="none",o.addEventListener("click",(()=>{"none"==n.style.display&&window.screen.availWidth<993?n.style.display="block":n.style.display="none"})),window.addEventListener("resize",(()=>{window.screen.availWidth>992&&(n.style.display="none")}))})(".burger-menu",".burger"),a(".pageup"),(()=>{const e=document.querySelectorAll('[name="upload"]');function t(e){e.preventDefault(),e.stopPropagation()}["dragenter","dragleave","dragover","drop"].forEach((n=>{e.forEach((e=>{e.addEventListener(n,t,!1)}))})),["dragenter","dragover"].forEach((t=>{e.forEach((e=>{e.addEventListener(t,(()=>{return(t=e).closest(".file_upload").style.border="2px solid yellow",void(t.closest(".file_upload").style.backgroundColor="rgba(0,0,0, .1)");var t}),!1)}))})),["dragleave","drop"].forEach((t=>{e.forEach((e=>{e.addEventListener(t,(()=>{return(t=e).closest(".file_upload").style.border="none",void(t.closest(".calc_form")?t.closest(".file_upload").style.backgroundColor="#fff":t.closest(".file_upload").style.backgroundColor="#ededed");var t}),!1)}))})),e.forEach((e=>{e.addEventListener("drop",(t=>{let n;e.files=t.dataTransfer.files;const o=e.files[0].name.split(".");n=o[0].length>6?"...":".";const l=o[0].substring(0,6)+n+o[1];e.previousElementSibling.textContent=l}))}))})()}))}();