Blame view
local/templates/main/js/requisites.js
4.88 KB
80576aee7 Интеграция верстк... |
1 |
(()=>{"use strict";const t={scroll(){document.body.style.overflow=""},unscroll(){document.body.style.overflow="hidden"}};class e{constructor(t){this._popup=t,this.openPopup=this.openPopup.bind(this),this.closePopup=this.closePopup.bind(this),this._setEscHandler=this._setEscHandler.bind(this),this.setEventListeners=this.setEventListeners.bind(this)}openPopup(e){e&&(this._subject=e),this._popup.classList.add("popup-form_visible"),document.body.style.overflow="hidden",t.unscroll(),document.addEventListener("keydown",this._setEscHandler)}closePopup(){this._popup.classList.remove("popup-form_visible"),t.scroll(),document.removeEventListener("keydown",this._setEscHandler)}_setEscHandler(t){"Escape"===t.key&&this.closePopup()}setEventListeners(){this._popup.addEventListener("mousedown",(t=>{(t.target.classList.contains("popup-form_visible")||t.target.closest(".popup-form__close"))&&this.closePopup()}))}}class o extends e{constructor(t,e){super(t),this._form=t.querySelector(".form"),this._onSubmit=e,this._inputList=this._form.querySelectorAll(".form__item"),this._popupButton=this._form.querySelector(".form__btn"),this._inputValues={},this._hiddenInput=this._form.querySelector(".form__fields_input-hidden")}openPopup(t){super.openPopup(t),this._hiddenInput.value=this._subject,console.log(this._hiddenInput.value)}closePopup(){this._form.reset(),super.closePopup()}_getInputValues(){return this._inputList.forEach((t=>{this._inputValues[t.name]=t.value})),this._inputValues}setEventListeners(){super.setEventListeners(),this._form.addEventListener("submit",(t=>{t.preventDefault()}))}}const s={WRAPPER:document.querySelector(".wrapper"),CANVAS:document.querySelector(".canvas")},c=.003,n=20,i=0,l=0,r=n,a={MIN:-180,MAX:180},u={MIN:-90,MAX:90},d="#202020",h="#FBFBFB",p="#A42E2C",m="#670E0E",f="#511112",y="#340D0F",_={rotation:0,time:0,ctx:void 0,dots:[],background:h,KKK:0,WIDTH:0,HEIGHT:0,colorFill:p,colorStroke:m};try{k(),requestAnimationFrame(k),function(){for(let t=0;t<500;t++)_.dots.push(g())}(),function(){const t=s.CANVAS.getContext("2d");t.fillRect(0,0,s.CANVAS.width,s.CANVAS.height),_.ctx=t}(),S(),S()}catch(t){}function v(t){t?(_.background=h,_.colorFill=f,_.colorStroke=y):(_.background=d,_.colorFill=p,_.colorStroke=m)}function E(t){const e=n/t.z,o=_.WIDTH/2,s=_.HEIGHT/2,c=_.KKK*e*t.x+o,i=-_.KKK*e*t.y+s;t.xDisplay=c,t.yDisplay=i,_.ctx.beginPath(),_.ctx.ellipse(c,i,2,2,0,0,2*Math.PI),_.ctx.fill()}function b(t){t.links.forEach((e=>{_.ctx.beginPath(),_.ctx.moveTo(t.xDisplay,t.yDisplay),_.ctx.lineTo(e.xDisplay,e.yDisplay),_.ctx.stroke()}))}function S(){k(),_.time++,_.dots.forEach((t=>{t.a=t.a+t.da,t.b=t.b+t.db,function(t){t.x=i+1*Math.sin(-_.rotation-_.time/1e3+t.a)*Math.cos(t.b),t.y=l+1*Math.sin(t.b),t.z=r-1*Math.cos(t.b)*Math.cos(-_.rotation-_.time/1e3+t.a)}(t)})),_.dots.sort(((t,e)=>e.z-t.z)),_.dots.forEach((t=>{t.links=[],_.dots.forEach((e=>{var o,s;o=t,s=e,Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2)+Math.pow(o.z-s.z,2))<.15&&t.links.push(e)}))})),_.ctx.fillStyle=_.background,_.ctx.fillRect(0,0,_.WIDTH,_.HEIGHT),_.ctx.fillStyle=_.colorFill,_.ctx.strokeStyle=_.colorStroke,_.dots.forEach(b),_.dots.forEach(E),requestAnimationFrame(S)}function g(...t){return t.length>0?{a:t[0],b:t[1],da:0,db:0,xDisplay:0,yDisplay:0,links:[]}:{a:(a.MAX-a.MIN)*Math.random()+a.MIN,b:(u.MAX-u.MIN)*Math.random()+u.MIN,da:c*Math.random()-.0015,db:c*Math.random()-.0015,links:[]}}function k(){const t=s.CANVAS.clientWidth,e=s.CANVAS.clientHeight,o=Math.min(t,e);_.KKK=o/3,_.WIDTH=t,_.HEIGHT=e,s.CANVAS.width=t,s.CANVAS.height=e}const L=document.querySelectorAll(".js_toggle_input");function A(){document.body.classList.add("light-mode"),v(!0),console.log("светлая тема")}function M(){document.body.classList.remove("light-mode"),v(!1),console.log("тёмная тема")}"dark"===localStorage.getItem("theme")?(L.forEach((t=>{t.checked=!1})),M()):(L.forEach((t=>{t.checked=!0})),A()),L.forEach((t=>{t.addEventListener("change",(()=>{t.checked?(L.forEach((t=>{t.checked=!0})),localStorage.setItem("theme","light"),A()):(L.forEach((t=>{t.checked=!1})),localStorage.setItem("theme","dark"),M())}))})),function(){try{const e=document.querySelector(".js_header_btn"),o=document.querySelector(".js_menu"),s=document.querySelector(".js_menu_overlay"),c=document.querySelector(".js_menu_exit");o.style.display="",e.addEventListener("click",(()=>{s.classList.add("active"),o.classList.add("active-half"),c.classList.add("active"),t.unscroll()})),c.addEventListener("click",(()=>{n()})),s.addEventListener("click",(()=>{n()}));const n=()=>{s.classList.remove("active"),o.classList.remove("active-half","active-full"),c.classList.remove("active"),t.scroll()}}catch(t){}}(),function(){try{const t=document.querySelector("#popupform"),e=new o(t,(()=>{e.closePopup()}));e.setEventListeners(),document.querySelectorAll(".popup-form-open").forEach((t=>{t.addEventListener("click",(t=>{const o=t.target.dataset.subject;e.openPopup(o)}))}))}catch(t){console.log(t)}}()})(); |