annotate WebContent/jscripts/tiny_mce/plugins/noneditable/editor_plugin_src.js @ 5:0be9d53a6967

editor for annotations
author dwinter
date Tue, 13 Dec 2011 17:43:46 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var Event = tinymce.dom.Event;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 tinymce.create('tinymce.plugins.NonEditablePlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 var t = this, editClass, nonEditClass, state;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 t.editor = ed;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 editClass = ed.getParam("noneditable_editable_class", "mceEditable");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 ed.onNodeChange.addToTop(function(ed, cm, n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 var sc, ec;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 // Block if start or end is inside a non editable element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 sc = ed.dom.getParent(ed.selection.getStart(), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 return ed.dom.hasClass(n, nonEditClass);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 ec = ed.dom.getParent(ed.selection.getEnd(), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 return ed.dom.hasClass(n, nonEditClass);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 // Block or unblock
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 if (sc || ec) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 state = 1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 t._setDisabled(1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38 return false;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 } else if (state == 1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 t._setDisabled(0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 state = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 longname : 'Non editable elements',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 _block : function(ed, e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 var k = e.keyCode;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 // Don't block arrow keys, pg up/down, and F1-F12
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 if ((k > 32 && k < 41) || (k > 111 && k < 124))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 return Event.cancel(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 _setDisabled : function(s) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 var t = this, ed = t.editor;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 tinymce.each(ed.controlManager.controls, function(c) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 c.setDisabled(s);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 if (s !== t.disabled) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 if (s) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 ed.onKeyDown.addToTop(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 ed.onKeyPress.addToTop(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 ed.onKeyUp.addToTop(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 ed.onPaste.addToTop(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 ed.onContextMenu.addToTop(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 ed.onKeyDown.remove(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 ed.onKeyPress.remove(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 ed.onKeyUp.remove(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 ed.onPaste.remove(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 ed.onContextMenu.remove(t._block);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 t.disabled = s;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 })();