Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener('DOMContentLoaded', () => {
- if ('undefined' === typeof window.GLSR) return;
- const storeKey = (el) => 'checkbox' === el.type ? (el.name + el.value) : el.name;
- const event = (ev) => sessionStorage.setItem(storeKey(ev.target), ev.target.value);
- // const forget = (el) => el.removeEventListener('change', event);
- const listen = (el) => el.addEventListener('change', event);
- const restore = (el) => {
- const value = sessionStorage.getItem(storeKey(el));
- if (null === value) return;
- if (['checkbox','radio'].includes(el.type)) {
- el.checked = (el.value === value);
- } else {
- el.value = value;
- }
- el.dispatchEvent(new Event('change'))
- };
- GLSR.Event.on('site-reviews/loaded', () => {
- GLSR.forms.forEach(o => [...o.form.elements].forEach(el => {
- if (el.disabled || el.readonly || ['file','hidden','password','submit'].includes(el.type)) return;
- if (['input','select','textarea'].includes(el.localName)) {
- restore(el)
- listen(el)
- }
- }))
- })
- GLSR.Event.on('site-reviews/form/handle', (response) => {
- if (true === response.success) {
- sessionStorage.clear()
- }
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement