diff --git a/jquery.are-you-sure.js b/jquery.are-you-sure.js index 3c41e2f..4107c89 100644 --- a/jquery.are-you-sure.js +++ b/jquery.are-you-sure.js @@ -9,9 +9,36 @@ * Author: chris.dance@papercut.com * Version: 1.9.0 * Date: 13th August 2014 + * */ + + (function($) { - + $.fn.areYouSure_live = function (toWatch){ + var formIds_aYs = []; + addFormTo_aYs(this); + + jQuery(toWatch).bind('DOMNodeInserted', function(event) { + addFormTo_aYs(jQuery(event.target)); + }); + + function addFormTo_aYs(selector){ + jQuery(selector).find('form').each(function(key, obj){ + if(formIds_aYs.includes(obj.id)){ + modalboxFix(obj); + }else{ + formIds_aYs.push(obj.id); + jQuery(obj).areYouSure(); + } + }); + } + + function modalboxFix(obj){ + if(jQuery('#MB_'+obj.id).length > 0 || jQuery(obj).parents('#MB_content').length > 0 ){ + jQuery(obj).areYouSure(); + } + } + }; $.fn.areYouSure = function(options) { var settings = $.extend( @@ -152,12 +179,23 @@ var reinitialize = function() { initForm($(this)); } + + function ckeditorCheck(){ + if (typeof(CKEDITOR) !== 'undefined'){ + for(var x in CKEDITOR.instances){ + if (CKEDITOR.instances[x].checkDirty()){ + return false; + } + } + } + return true; + } if (!settings.silent && !window.aysUnloadSet) { window.aysUnloadSet = true; $(window).bind('beforeunload', function() { $dirtyForms = $("form").filter('.' + settings.dirtyClass); - if ($dirtyForms.length == 0) { + if ($dirtyForms.length == 0 && ckeditorCheck()) { return; } // Prevent multiple prompts - seen on Chrome and IE @@ -181,6 +219,17 @@ $form.submit(function() { $form.removeClass(settings.dirtyClass); }); + + jQuery($form).bind('submit', function(){ + $form.removeClass(settings.dirtyClass); + }); + + $form.find('input[type=submit]').each(function(){ + jQuery(this).bind('click', function(){ + $form.removeClass(settings.dirtyClass); + }); + }); + $form.bind('reset', function() { setDirtyStatus($form, false); }); // Add a custom events $form.bind('rescan.areYouSure', rescan);