PageSourceSearch

https://expert.ru/js/EmailChangeController.js

js expert.ru collected 2026-10-01 07:55:07 UTC 3,077 bytes, 7 lines download raw bytes

1var u=Object.defineProperty;var d=(s,t,e)=>t in s?u(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var n=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);import{I as m}from"./InputController.js";import"./index.js";const r="[data-js-email-change-modal]";class h{constructor(t){n(this,"rootElement");n(this,"elementInput");n(this,"elementButton");n(this,"emailInput");n(this,"isLoading",!1);n(this,"selectors",{root:r,input:"[data-js-email-change-input]",button:"[data-js-email-change-button]"});n(this,"stateClasses",{isHidden:"js-hidden"});n(this,"updateButtonState",()=>{const e=this.emailInput.getValue().trim().length>0&&this.emailInput.isValid();this.elementButton.disabled=!e||this.isLoading});n(this,"onSubmit",t=>{t.preventDefault(),!this.elementButton.disabled&&this.sendRequest()});n(this,"sendRequest",async()=>{var a;const t=this.rootElement.getAttribute("data-js-api-url")||"",e=this.emailInput.getValue().trim(),i=this.getSessionToken();this.isLoading=!0,this.elementButton.disabled=!0,this.elementButton.innerHTML=`
2			<div class="loader">
3				<div></div>
4				<div></div>
5				<div></div>
6			</div>
7		`,this.emailInput.hideError();try{const l=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({email:e,_token:i})}),o=await l.json();if(!l.ok||o.success===!1){o.message&&this.emailInput.showError(o.message),(a=o.errors)!=null&&a.login&&this.emailInput.showError(o.errors.login[0]);return}this.openNextModal()}catch{this.emailInput.showError("Ошибка соединения")}finally{this.isLoading=!1,this.elementButton.textContent="Сохранить",this.updateButtonState()}});this.rootElement=t,this.elementInput=this.rootElement.querySelector(this.selectors.input),this.elementButton=this.rootElement.querySelector(this.selectors.button),this.emailInput=m(this.elementInput),this.init()}init(){this.bindEvents()}bindEvents(){this.elementInput.addEventListener("input",this.updateButtonState),this.elementButton.addEventListener("click",this.onSubmit)}getSessionToken(){const t=this.rootElement.querySelector('input[name="_token"]');if(t!=null&&t.value)return t.value;const e=document.querySelector('input[name="_token"]');if(e!=null&&e.value)return e.value;const i=document.querySelector('meta[name="csrf-token"]');return(i==null?void 0:i.content)??""}show(){this.rootElement.classList.remove(this.stateClasses.isHidden)}hide(){this.rootElement.classList.add(this.stateClasses.isHidden)}openNextModal(){const t="email-confirmation",e=document.querySelector(`[data-js-${t}-modal]`);e&&(e.setAttribute("data-flow","change"),e.setAttribute("data-current-email",this.emailInput.getValue()));const i=document.querySelector(`[data-js-modal-open="${t}"]`);i==null||i.click()}}class E{constructor(){n(this,"modal");this.init()}init(){const t=document.querySelector(r);if(t instanceof HTMLElement)this.modal=new h(t);else throw new Error(`EmailChangeModal element is not an HTMLElement: ${t}`)}open(){this.modal.show()}close(){this.modal.hide()}}export{E as EmailChangeController};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.