!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery)}(function(e){if("function"!=typeof e(document).on){if("function"!=typeof e(document).delegate)throw"jQuery 1.4.2 or higher is required by jquery.dirtyforms";e.fn.on=function(t,i,n,r){e(this).delegate(i,t,n,r)}}e.extend({DirtyForms:{debug:!1,message:"You've made changes on this page which aren't saved. If you leave you will lose these changes.",title:"Are you sure you want to do that?",dirtyClass:"dirty",listeningClass:"dirtylisten",ignoreClass:"ignoredirty",choiceContinue:!1,helpers:[],dialog:{refire:function(t,i){e.facebox(t)},fire:function(t,i){var n="
"+t+'
ContinueStop';e.facebox(n)},bind:function(){var t=function(t){return function(i){i.preventDefault(),e(document).trigger("close.facebox"),t(i)}};e("#facebox .cancel, #facebox .close, #facebox_overlay").click(t(y)),e("#facebox .continue").click(t(p))},stash:function(){var t=e("#facebox");return""===e.trim(t.html())||"block"!=t.css("display")?!1:e("#facebox .content").clone(!0)},selector:"#facebox .content"},isDirty:function(){return e(":dirtylistening").dirtyForms("isDirty")},disable:function(){i.disabled=!0},ignoreParentDocs:function(){i.watchParentDocs=!1},choiceCommit:function(e){h(e)},isDeciding:function(){return i.deciding},decidingContinue:function(e){p(e)},decidingCancel:function(e){y(e)},dirtylog:function(e){a(e)}}}),e.extend(e.expr[":"],{dirtylistening:function(t){return e(t).hasClass(e.DirtyForms.listeningClass)},dirty:function(t){return e(t).hasClass(e.DirtyForms.dirtyClass)}});var t={init:function(){var t=e.DirtyForms;return a("Adding forms to watch"),d(),this.each(function(s){if(e(this).is("form")){a("Adding form "+e(this).attr("id")+" to forms to watch"),e(this).addClass(t.listeningClass);var d="textarea,input:not([type='checkbox'],[type='radio'],[type='button'],[type='image'],[type='submit'],[type='reset'],[type='file'],[type='search'])",c="input[type='checkbox'],input[type='radio'],select",l="input[type='reset']";e(this).on("focus change",d,o),e(this).on("change",c,r),e(this).on("click",l,n);var u=e(this).find(d).filter(":focus");u&&(i.focused.element=u,i.focused.value=u.val())}})},isDirty:function(){var t=!1,n=this;return i.disabled?!1:s()?(t=!0,!0):(this.each(function(i){return e(this).hasClass(e.DirtyForms.dirtyClass)?(t=!0,!0):void 0}),e.each(e.DirtyForms.helpers,function(e,i){return"isDirty"in i&&i.isDirty(n)?(t=!0,!0):"isNodeDirty"in i&&i.isNodeDirty(n)?(t=!0,!0):void 0}),a("isDirty returned "+t),t)},setDirty:function(){return a("setDirty called"),this.each(function(t){e(this).addClass(e.DirtyForms.dirtyClass).parents("form").addClass(e.DirtyForms.dirtyClass)})},setClean:function(){return a("setClean called"),i.focused={element:!1,value:!1},this.each(function(t){var i=this;if(e(i).removeClass(e.DirtyForms.dirtyClass),e(i).is("form"))e(i).find(":dirty").removeClass(e.DirtyForms.dirtyClass);else{var n=e(i).parents("form");0===n.find(":dirty").length&&n.removeClass(e.DirtyForms.dirtyClass)}e.each(e.DirtyForms.helpers,function(e,t){"setClean"in t&&t.setClean(i)})})}};e.fn.dirtyForms=function(i){return t[i]?t[i].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof i&&i?void e.error("Method "+i+" does not exist on jQuery.dirtyForms"):t.init.apply(this,arguments)},e.fn.setDirty=function(){return this.dirtyForms("setDirty")},e.fn.isDirty=function(){return this.dirtyForms("isDirty")},e.fn.cleanDirty=function(){return this.dirtyForms("setClean")};var i=e.DirtyForms=e.extend({watchParentDocs:!0,disabled:!1,exitBound:!1,formStash:!1,dialogStash:!1,deciding:!1,decidingEvent:!1,currentForm:!1,hasFirebug:"console"in window&&"firebug"in window.console,hasConsoleLog:"console"in window&&"log"in window.console,focused:{element:!1,value:!1}},e.DirtyForms),n=function(){e(this).parents("form").dirtyForms("setClean"),i.onFormCheck&&i.onFormCheck()},r=function(){e(this).hasClass(e.DirtyForms.ignoreClass)||(e(this).dirtyForms("setDirty"),i.onFormCheck&&i.onFormCheck())},o=function(){var t=e(this);s()&&!t.hasClass(e.DirtyForms.ignoreClass)&&(i.focused.element.dirtyForms("setDirty"),i.onFormCheck&&i.onFormCheck()),i.focused.element=t,i.focused.value=t.val()},s=function(){return i.focused.element&&i.focused.element.val()!==i.focused.value},a=function(t){e.DirtyForms.debug&&(t="[DirtyForms] "+t,i.hasFirebug?console.log(t):i.hasConsoleLog?window.console.log(t):alert(t))},d=function(){if(!i.exitBound){var t=top!==self;e(document).on("click","a[href]",l),e(document).on("submit","form",u),i.watchParentDocs&&t&&(e(top.document).on("click","a[href]",l),e(top.document).on("submit","form",u)),e(window).bind("beforeunload",f),i.watchParentDocs&&t&&e(top.window).bind("beforeunload",f),i.exitBound=!0}},c=function(){var t="";return e.each(e.DirtyForms.helpers,function(e,i){"ignoreAnchorSelector"in i&&(t.length>0&&(t+=","),t+=i.ignoreAnchorSelector)}),t},l=function(t){var i=e(this);i.is(c())||"undefined"==typeof i.attr("href")||g(t)},u=function(e){i.currentForm=this,g(e)},f=function(e){var t=g(e);return t&&i.doubleunloadfix!==!0&&(a("Before unload will be called, resetting"),i.deciding=!1),i.doubleunloadfix=!0,setTimeout(function(){i.doubleunloadfix=!1},200),"string"==typeof t?(e=e||window.event,e&&(e.returnValue=t),t):void 0},g=function(t){return a("Entering: Leaving Event fired, type: "+t.type+", element: "+t.target+", class: "+e(t.target).attr("class")+" and id: "+t.target.id),"beforeunload"==t.type&&i.doubleunloadfix?(a("Skip this unload, Firefox bug triggers the unload event multiple times"),i.doubleunloadfix=!1,!1):e(t.target).hasClass(i.ignoreClass)||m(t)?(a("Leaving: Element has ignore class or has target='_blank'"),t.isDefaultPrevented()||v(),!1):i.deciding?(a("Leaving: Already in the deciding process"),!1):t.isDefaultPrevented()?(a("Leaving: Event has been stopped elsewhere"),!1):i.isDirty()?"submit"==t.type&&e(t.target).dirtyForms("isDirty")?(a("Leaving: Form submitted is a dirty form"),t.isDefaultPrevented()||v(),!0):(i.dialog&&(i.deciding=!0,i.decidingEvent=t,a("Setting deciding active"),a("Saving dialog content"),i.dialogStash=i.dialog.stash(),a(i.dialogStash)),e(document).trigger("defer.dirtyforms"),"beforeunload"==t.type?(a("Returning to beforeunload browser handler with: "+i.message),i.message):void(i.dialog&&(t.preventDefault(),t.stopImmediatePropagation(),e(t.target).is("form")&&e(t.target).parents(i.dialog.selector).length>0?(a("Stashing form"),i.formStash=e(t.target).clone(!0).hide()):i.formStash=!1,a("Deferring to the dialog"),i.dialog.fire(e.DirtyForms.message,e.DirtyForms.title),i.dialog.bind()))):(a("Leaving: Not dirty"),t.isDefaultPrevented()||v(),!1)},m=function(t){var i=e(t.target).attr("target");return"string"==typeof i&&(i=i.toLowerCase()),"_blank"===i},h=function(t){i.deciding&&(e(document).trigger("choicecommit.dirtyforms"),e.DirtyForms.choiceContinue?p(t):y(t),e(document).trigger("choicecommitAfter.dirtyforms"))},y=function(t){t.preventDefault(),e(document).trigger("decidingcancelled.dirtyforms"),i.dialog!==!1&&i.dialogStash!==!1&&(a("Refiring the dialog with stashed content"),i.dialog.refire(i.dialogStash.html(),t)),e(document).trigger("decidingcancelledAfter.dirtyforms"),i.dialogStash=!1,i.deciding=i.currentForm=i.decidingEvent=!1},p=function(t){v(),t.preventDefault(),i.dialogStash=!1,e(document).trigger("decidingcontinued.dirtyforms"),b(i.decidingEvent),i.deciding=i.currentForm=i.decidingEvent=!1},v=function(){a("Clearing the beforeunload event"),e(window).unbind("beforeunload",f),window.onbeforeunload=null,e(document).trigger("beforeunload.dirtyforms")},b=function(t){switch(e(document).trigger("beforeRefire.dirtyforms"),e(document).trigger("beforeunload.dirtyforms"),t.type){case"click":a("Refiring click event");var n=new jQuery.Event("click");if(e(t.target).trigger(n),!n.isDefaultPrevented()){var r=e(t.target).closest("[href]");return a("Sending location to "+r.attr("href")),void(void 0!==r.attr("href")&&(location.href=r.attr("href")))}break;default:a("Refiring "+t.type+" event on "+t.target);var o;i.formStash?(a("Appending stashed form to body"),o=i.formStash,e("body").append(o)):(o=e(t.target),o.is("form")||(o=o.closest("form"))),o.trigger(t.type)}}}); //# sourceMappingURL=jquery.dirtyforms.min.js.map