-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.dirtyforms.helpers.ckeditor.js
67 lines (61 loc) · 2.37 KB
/
jquery.dirtyforms.helpers.ckeditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*!
CkEditor helper module (for jQuery Dirty Forms) | v2.0.0 | github.com/snikch/jquery.dirtyforms
(c) 2012-2015 Mal Curtis
License MIT
*/
(function($, window, document, undefined) {
// Can't use ECMAScript 5's strict mode because several apps
// including ASP.NET trace the stack via arguments.caller.callee
// and Firefox dies if you try to trace through "use strict" call chains.
// See jQuery issue (#13335)
// Support: Firefox 18+
//"use strict";
var ignoreSelector = '.cke_dialog_ui_button,.cke_tpl_list a';
var ckeditor = {
ignoreSelector: ignoreSelector,
isDirty: function ($form) {
var $editors = ckeditors($form),
isDirty = false;
if ($editors.length > 0) {
$.DirtyForms.dirtylog('Checking ' + $editors.length + ' ckeditors for dirtyness.');
$editors.each(function (editorIndex) {
if (this.checkDirty()) {
isDirty = true;
$.DirtyForms.dirtylog('CKEditor with index ' + editorIndex + ' was dirty, exiting...');
// Return false to break out of the .each() function
return false;
}
});
}
return isDirty;
},
setClean: function ($form) {
ckeditors($form).each(function () { this.resetDirty(); });
},
// Support for Dirty Forms < 2.0
ignoreAnchorSelector: ignoreSelector
};
var ckeditors = function (form) {
var $form = form.jquery ? form : $(form);
var editors = [];
if (!window.CKEDITOR || !window.CKEDITOR.instances) {
return $(editors);
}
try {
for (var key in window.CKEDITOR.instances) {
if (window.CKEDITOR.instances.hasOwnProperty(key)) {
var editor = window.CKEDITOR.instances[key];
if ($(editor.element.$).parents().index($form) != -1) {
$.DirtyForms.dirtylog('Adding CKEditor with key ' + key);
editors.push(editor);
}
}
}
}
catch (e) {
// Ignore, means there was no CKEDITOR variable
}
return $(editors);
};
$.DirtyForms.helpers.push(ckeditor);
})(jQuery, window, document);