{"version":3,"file":"global.dirtyForm.min.js","names":["formsToCheckForDirty","fieldIdsToIgnoreIsDirty","isDirtyOverridden","browserDirtyMessage","initDirtyForm","$","window","bind","isFormDirty","x","length","form","i","elements","element","inArray","id","type","checked","defaultChecked","console","log","currentValue","value","defaultValue","replace","fieldIdsToRemoveMask","hasClass","getUnmaskedNumber","inputmask","j","options","selected","defaultSelected","subscribeFormForDirtyDetection","formId","push","ignoreIsDirtyById","arguments","each","e","indexOf","checkIsDirtyById","index","splice","click","href","this","attr","SmartMessageBox","title","content","buttons","buttonPressed","location","preventDefault"],"sources":["global/global.dirtyForm.js"],"sourcesContent":["//#region Dirty global variables\n\nvar formsToCheckForDirty = [];\nvar fieldIdsToIgnoreIsDirty = [];\n\n// Setting this to true will disable any kind dirty form message that would stop the user from leaving the page. This is mainly needed for successful form submits and to override the window unload event when we detect a link clicked\nvar isDirtyOverridden = false;\n\n// This is the message that will display if a user has made changes then navigates away from the page using the address bar of the browser\nvar browserDirtyMessage = 'Are you sure you want to leave this page?';\n\n//#endregion\n\n//#region initDirtyForm. Attaches to the window beforeunload event to check dirty if the user tries to navigate away with the browser\n\nfunction initDirtyForm() {\n $(window).bind('beforeunload', function () {\n var isDirty = isFormDirty();\n if (isDirty) {\n return browserDirtyMessage;\n }\n });\n}\n\n//#endregion\n\n//#region Link Click Handler. This will trigger a dirty check and notify the user if they click a link within the site\n\n$('a').click(function (e) {\n var href = $(this).attr('href');\n if (href && href != '#' && href != 'javascript:void(0)') {\n var isDirty = isFormDirty();\n if (isDirty) {\n $.SmartMessageBox({\n title: ' Are you sure you want to leave this page?',\n content: \"You haven't saved your changes yet. Do you want to leave without saving?\",\n buttons: '[Yes, leave this page][No, stay on this page]'\n }, function (buttonPressed) {\n if (buttonPressed == 'Yes, leave this page') {\n isDirtyOverridden = true;\n window.location = href;\n }\n });\n e.preventDefault();\n }\n }\n return true;\n});\n\n//#endregion\n\n//#region isFormDirty. Function to check if the form is dirty\n\nfunction isFormDirty() {\n if (isDirtyOverridden) {\n return false;\n }\n\n for (var x = 0; x < formsToCheckForDirty.length; x++) {\n var form = formsToCheckForDirty[x];\n\n for (var i = 0; i < form.elements.length; i++) {\n var element = form.elements[i];\n\n if ($.inArray(element.id, fieldIdsToIgnoreIsDirty) > -1) {\n return false;\n }\n\n var type = element.type;\n if (type == \"checkbox\" || type == \"radio\") {\n if (element.checked != element.defaultChecked) {\n console.log('Element ' + element.id + ' caused the form to be dirty. Checked is: ' + element.checked + '. Default checked is: ' + element.defaultChecked);\n return true;\n }\n }\n else if (type == \"hidden\" || type == \"password\" ||\n type == \"text\" || type == \"textarea\") {\n var currentValue = element.value;\n var defaultValue = element.defaultValue;\n\n if (currentValue) {\n currentValue = currentValue.replace(/\\r\\n/g, '\\n'); //replace crlf to solve buggy scenario where defaultValue has crlf and value just has lf\n }\n if (defaultValue) {\n defaultValue = defaultValue.replace(/\\r\\n/g, '\\n'); //replace crlf to solve buggy scenario where defaultValue has crlf and value just has lf\n }\n\n if ($.inArray(element.id, fieldIdsToRemoveMask) > -1) {\n if ($(element).hasClass('percentMask')) {\n currentValue = getUnmaskedNumber(element.value);\n }\n else {\n currentValue = $(element).inputmask('unmaskedvalue') || \"\";\n }\n }\n if (currentValue != defaultValue) {\n console.log('Element ' + element.id + ' caused the form to be dirty. Current value is: ' + currentValue + '. Default value is: ' + defaultValue);\n return true;\n }\n }\n else if (type == \"select-one\" || type == \"select-multiple\") {\n for (var j = 0; j < element.options.length; j++) {\n if (element.options[j].selected !=\n element.options[j].defaultSelected) {\n console.log('Element ' + element.id + ' caused the form to be dirty. Option with value ' + element.options[j].value + 'was selected but not was not the default selected option ');\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\n//#endregion\n\n//#region subscribeFormForDirtyDetection. Sets up the forms that preform dirty detection\n\nfunction subscribeFormForDirtyDetection(formId) {\n var form = $('#' + formId)[0];\n formsToCheckForDirty.push(form);\n}\n\n//#endregion\n\n//#region IsDirtyById. Call this to setup elements to ignore/un-ignore isDirty check.\n\nfunction ignoreIsDirtyById() {\n $(arguments).each(function (i, e) {\n var index = fieldIdsToIgnoreIsDirty.indexOf(e);\n if (index < 0) {\n fieldIdsToIgnoreIsDirty.push(e);\n }\n });\n}\n\nfunction checkIsDirtyById() {\n $(arguments).each(function (i, e) {\n var index = fieldIdsToIgnoreIsDirty.indexOf(e);\n if (index >= 0) {\n fieldIdsToIgnoreIsDirty.splice(index, 1);\n }\n });\n}\n\n//#endregion IsDirtyById\n"],"mappings":"AAEA,IAAIA,qBAAuB,GACvBC,wBAA0B,GAG1BC,mBAAoB,EAGpBC,oBAAsB,4CAM1B,SAASC,gBACPC,EAAEC,QAAQC,KAAK,gBAAgB,WAE7B,GADcC,cAEZ,OAAOL,uBAkCb,SAASK,cACP,GAAIN,kBACF,OAAO,EAGT,IAAK,IAAIO,EAAI,EAAGA,EAAIT,qBAAqBU,OAAQD,IAG/C,IAFA,IAAIE,EAAOX,qBAAqBS,GAEvBG,EAAI,EAAGA,EAAID,EAAKE,SAASH,OAAQE,IAAK,CAC7C,IAAIE,EAAUH,EAAKE,SAASD,GAE5B,GAAIP,EAAEU,QAAQD,EAAQE,GAAIf,0BAA4B,EACpD,OAAO,EAGT,IAAIgB,EAAOH,EAAQG,KACnB,GAAY,YAARA,GAA8B,SAARA,GACxB,GAAIH,EAAQI,SAAWJ,EAAQK,eAE7B,OADAC,QAAQC,IAAI,WAAaP,EAAQE,GAAK,8CAAgDF,EAAQI,QAAU,yBAA2BJ,EAAQK,iBACpI,OAGN,GAAY,UAARF,GAA4B,YAARA,GACZ,QAARA,GAA0B,YAARA,EAAoB,CAC7C,IAAIK,EAAeR,EAAQS,MACvBC,EAAeV,EAAQU,aAiB3B,GAfIF,IACFA,EAAeA,EAAaG,QAAQ,QAAS,OAE3CD,IACFA,EAAeA,EAAaC,QAAQ,QAAS,OAG3CpB,EAAEU,QAAQD,EAAQE,GAAIU,uBAAyB,IAE/CJ,EADEjB,EAAES,GAASa,SAAS,eACPC,kBAAkBd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