From 6b686dd3174371e1ae4baec30e4ab5043dbba20d Mon Sep 17 00:00:00 2001 From: Leonardo Date: Mon, 31 Jul 2017 18:03:03 -0500 Subject: [PATCH 1/2] CKEditor compatibility. --- jquery.are-you-sure.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jquery.are-you-sure.js b/jquery.are-you-sure.js index 3c41e2f..131184c 100644 --- a/jquery.are-you-sure.js +++ b/jquery.are-you-sure.js @@ -152,12 +152,23 @@ var reinitialize = function() { initForm($(this)); } + + function checkCKEditor(){ + 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 && checkCKEditor()) { return; } // Prevent multiple prompts - seen on Chrome and IE From e80e1ab7e8afcfb330e58251c55f8890e5606203 Mon Sep 17 00:00:00 2001 From: axia4 <1399905+axia4@users.noreply.github.com> Date: Tue, 6 Feb 2018 11:34:26 -0500 Subject: [PATCH 2/2] areYouSure_live & modalboxFix * added areYouSure_live, to detect new forms on the fly. * added modalboxFix, AreYouSure does not work properly with modalbox . --- jquery.are-you-sure.js | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/jquery.are-you-sure.js b/jquery.are-you-sure.js index 131184c..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( @@ -153,7 +180,7 @@ initForm($(this)); } - function checkCKEditor(){ + function ckeditorCheck(){ if (typeof(CKEDITOR) !== 'undefined'){ for(var x in CKEDITOR.instances){ if (CKEDITOR.instances[x].checkDirty()){ @@ -168,7 +195,7 @@ window.aysUnloadSet = true; $(window).bind('beforeunload', function() { $dirtyForms = $("form").filter('.' + settings.dirtyClass); - if ($dirtyForms.length == 0 && checkCKEditor()) { + if ($dirtyForms.length == 0 && ckeditorCheck()) { return; } // Prevent multiple prompts - seen on Chrome and IE @@ -192,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);