-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.min.js
1 lines (1 loc) · 1.42 KB
/
popup.min.js
1
var link=document.querySelector(".feedback-link");var popup=document.querySelector(".modal-feedback");var close=document.querySelector(".close");var overlayClose=document.querySelector(".overlay");var userName=popup.querySelector("[name=user-name]");var userEmail=popup.querySelector("[name=email]");var userMessage=popup.querySelector("[name=message]");var form=popup.querySelector(".feedback_form");var isStorageSupport=true;var storage="";try{storage=localStorage.getItem("userName")}catch(err){isStorageSupport=false}link.addEventListener("click",function(a){a.preventDefault();popup.classList.add("modal-show");if(storage){userName.value=storage;userEmail.focus()}else{userName.focus()}});close.addEventListener("click",function(a){a.preventDefault();popup.classList.remove("modal-show")});overlayClose.addEventListener("click",function(a){a.preventDefault();popup.classList.remove("modal-show");popup.classList.remove("modal-error")});form.addEventListener("submit",function(a){if(!userName.value||!userEmail.value||!userMessage.value){a.preventDefault();popup.classList.remove("modal-error");popup.offsetWidth=popup.offsetWidth;popup.classList.add("modal-error")}else{if(isStorageSupport){localStorage.setItem("userName",userName.value)}}});window.addEventListener("keydown",function(a){if(a.keyCode===27){if(popup.classList.contains("modal-show")){a.preventDefault();popup.classList.remove("modal-show");popup.classList.remove("modal-error")}}});