Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions jquery.are-you-sure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down