-
Notifications
You must be signed in to change notification settings - Fork 1
/
form-mutator.min.js
2 lines (2 loc) · 1.62 KB
/
form-mutator.min.js
1
2
/*! form-mutator v4.0.7 | (c) <> | */
(e=>{exports="undefined"==typeof exports?e.formMutator={}:exports;const t={bubbles:!0,cancelable:!0},n=e=>{let n=!1;try{e.dispatchEvent(new MouseEvent("click",t)),n=!0}catch(e){}return n},c=(e,n,c)=>{let s=!1,r=Array.isArray(n)?n:[n];try{e.dispatchEvent(new Event("focus",t));let n=Array.from(e.options||[]),a=n.filter((e=>r.includes(e.text)));for(let e=0,t=a.length;e<t;e+=1)a[e].selected=c;e.dispatchEvent(new Event("change",t)),e.dispatchEvent(new Event("blur",t)),n=null,a=null,s=!0}catch(e){}return r=null,s},s=(e,t)=>c(e,t,!0),r=(e,n)=>{let c=!1;try{e.dispatchEvent(new Event("focus",t)),e.checked=n,e.dispatchEvent(new Event("change",t)),e.dispatchEvent(new Event("blur",t)),c=!0}catch(e){}return c},a=(e,n)=>{let c=!1;try{e.dispatchEvent(new Event("focus",t)),e.dispatchEvent(new Event("reset",t)),e.value=n,e.dispatchEvent(new Event("keydown",t)),e.dispatchEvent(new Event("keypress",t)),e.dispatchEvent(new Event("keyup",t)),e.dispatchEvent(new Event("input",t)),e.dispatchEvent(new Event("change",t)),e.dispatchEvent(new Event("blur",t)),c=!0}catch(e){}return c},l=(t,c)=>{let l=e.document?e.document.querySelector(t):null,o=!1;if(l)switch(l.type){case"checkbox":case"radio":o=r(l,c);break;case"select-one":case"select-multiple":o=s(l,c);break;case"submit":o=n(l);break;case"password":case"text":o=a(l,c);break;default:o=!0}else o=!0;return l=null,o};exports.click=n,exports.deselectByText=(e,t)=>c(e,t,!1),exports.fillOut=(e={})=>Object.keys(e).every((t=>l(t,e[t]))),exports.selectByText=s,exports.setValue=l,exports.toggleCheckbox=r,exports.typeValue=a})("undefined"==typeof window?global||this:window);