'use strict';const confirmClose=function(){if(arguments.length>0){for(let i=0;i<arguments.length;i++){this.forms_id.push(arguments[i]);}}};confirmClose.prototype={prompt:'You have unsaved changes.',forms_id:[],forms:[],form_submit:false,getCurrentForms(){const eltRef=(e)=>(e.id!=undefined&&e.id!=''?e.id:e.name);const formsInPage=this.getForms();this.forms=[];for(const f of formsInPage){let tmpForm=[];for(let j=0;j<f.elements.length;j++){const e=this.getFormElementValue(f[j]);if(e!==undefined){tmpForm[eltRef(f[j])]=e;}}
const j=f.getElementsByTagName('iframe');if(j!==undefined){for(let k=0;k<j.length;k++){if(j[k].contentDocument.body.id!==undefined&&j[k].contentDocument.body.id!==''){tmpForm[j[k].contentDocument.body.id]=j[k].contentDocument.body.innerHTML;}}}
this.forms.push(tmpForm);f.addEventListener('submit',()=>(this.form_submit=true));}},compareForms(){if(this.forms.length==0){return true;}
const formMatch=(current,source)=>Object.keys(current).every((key)=>!source.hasOwnProperty(key)||(source.hasOwnProperty(key)&&source[key]===current[key]));const eltRef=(e)=>(e.id!=undefined&&e.id!=''?e.id:e.name);const formFirstDiff=(current,source)=>{let diff='<none>';Object.keys(current).every((key)=>{if(source.hasOwnProperty(key)&&current[key]!==source[key]){diff=`Key = [${key}] - Original = [${source[key]}] - Current = [${current[key]}]`;return false;}
return true;});return diff;};const formsInPage=this.getForms();for(let i=0;i<formsInPage.length;i++){const f=formsInPage[i];let tmpForm=[];for(let j=0;j<f.elements.length;j++){const e=this.getFormElementValue(f[j]);if(e!==undefined){tmpForm[eltRef(f[j])]=e;}}
const j=f.getElementsByTagName('iframe');if(j!==undefined){for(let k=0;k<j.length;k++){if(j[k].contentDocument.body.id!==undefined&&j[k].contentDocument.body.id!==''){tmpForm[j[k].contentDocument.body.id]=j[k].contentDocument.body.innerHTML;}}}
if(!formMatch(tmpForm,this.forms[i])){if(dotclear.debug){console.log('Input data modified:');console.log('Current form',tmpForm);console.log('Saved form',this.forms[i]);console.log('First difference:',formFirstDiff(tmpForm,this.forms[i]));}
return false;}}
return true;},getForms(){if(!document.getElementsByTagName||!document.getElementById){return[];}
if(this.forms_id.length>0){let res=[];for(let i=0;i<this.forms_id.length;i++){const f=document.getElementById(this.forms_id[i]);if(f!=undefined){res.push(f);}}
return res;}else{return document.getElementsByTagName('form');}
return[];},getFormElementValue(e){if(e===undefined||((e.id===undefined||e.id==='')&&(e.name===undefined||e.name===''))||(e.type!==undefined&&e.type==='button')||(e.type!==undefined&&e.type==='submit')||e.hasAttribute('readonly')||e.classList.contains('meta-helper')||e.classList.contains('checkbox-helper')){return undefined;}
if(e.type!==undefined&&(e.type==='radio'||e.type==='checkbox')){return e.checked?e.value:null;}else if(e.type!==undefined&&e.type==='password'){return null;}else if(e.value!==undefined){return e.value;}else{return null;}},};window.addEventListener('load',()=>{const confirm_close=dotclear.getData('confirm_close');confirmClose.prototype.prompt=confirm_close.prompt;dotclear.confirmClosePage=new confirmClose(...confirm_close.forms);dotclear.confirmClosePage.getCurrentForms();});window.addEventListener('beforeunload',(event)=>{if(event==undefined&&window.event){event=window.event;}
if(dotclear.confirmClosePage!==undefined&&!dotclear.confirmClosePage.form_submit&&!dotclear.confirmClosePage.compareForms()){if(dotclear.debug){console.log('Confirmation before exiting is required.');}
event.preventDefault();event.returnValue='';}});