forked from theatlantic/django-admin-locking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocking.ckeditor.js
More file actions
56 lines (51 loc) · 1.87 KB
/
locking.ckeditor.js
File metadata and controls
56 lines (51 loc) · 1.87 KB
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
;(function(plugins) {
'use strict';
var CKEPlugin = (function () {
function isDescendant(parent, child) {
var node = child.parentNode;
while (node !== null) {
if (node == parent) {
return true;
}
node = node.parentNode;
}
return false;
}
var toggleCKEditorReadonly = function(form, isReadOnly) {
var toggleEditor = function(editor) {
if (!isDescendant(form, editor.element.$)) {
return;
}
if (editor.status == 'ready' || editor.status == 'basic_ready') {
editor.setReadOnly(isReadOnly);
} else {
editor.on('contentDom', function(e) {
e.editor.setReadOnly(isReadOnly);
});
}
};
if (window.CKEDITOR !== undefined) {
switch (CKEDITOR.status) {
case 'basic_ready':
case 'ready':
case 'loaded':
case 'basic_loaded':
for (var instanceId in CKEDITOR.instances) {
toggleEditor(CKEDITOR.instances[instanceId]);
}
break;
default:
CKEDITOR.on("instanceReady", function(e) {
toggleEditor(e.editor);
});
break;
}
}
};
return {
'enable': function(form) { return toggleCKEditorReadonly(form, false); },
'disable': function(form) { return toggleCKEditorReadonly(form, true); }
};
})();
plugins.register(CKEPlugin);
})(window.locking.LockingFormPlugins);