-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
1 lines (1 loc) · 1.53 KB
/
base.js
1
var formAntiClear={};const event=document.createEvent("Event");function isAntiClearNone(e){return e.className.split(" ").indexOf("form-anticlear-none")>=0||e.parentElement&&isAntiClearNone(e.parentElement,"form-anticlear-none")}event.initEvent("anticleared",!0,!0),formAntiClear.clear=function(e=".form-anticlear"){document.querySelectorAll(e).forEach(function(e){e.reset()})},window.onbeforeunload=function(){document.querySelectorAll(".form-anticlear input:not([type='radio']), .form-anticlear select, .form-anticlear textarea").forEach(function(e,t){isAntiClearNone(e)||null===e.value||""===e.value||("checkbox"==e.type?localStorage.setItem("frf_"+e.name+"_"+t,e.checked):localStorage.setItem("frf_"+e.name+"_"+t,e.value))}),document.querySelectorAll('.form-anticlear input[type="radio"]:checked').forEach(function(e,t){isAntiClearNone(e)||localStorage.setItem("frf_"+e.name+"_"+t,e.value)})},window.onload=function(){var e=[];document.querySelectorAll(".form-anticlear input:not([type='radio']), .form-anticlear select, .form-anticlear textarea").forEach(function(e,t){var n="frf_"+e.name+"_"+t;null!==localStorage.getItem(n)&&("checkbox"==e.type?e.checked="true"==localStorage.getItem(n):e.value=localStorage.getItem(n))}),document.querySelectorAll('.form-anticlear input[type="radio"]').forEach(function(t){var n="frf_"+t.name+"_"+i;e.indexOf(n)<0&&null!==localStorage.getItem(n)&&(e.push(n),document.querySelector("input[type='radio'][name='"+t.name+"'][value='"+localStorage.getItem(n)+"']").checked=!0)}),localStorage.clear(),document.dispatchEvent(event)};