Line # Revision Author
1 8 ahitrov@rambler.ru /**
2 * $Id: editor_plugin_src.js 743 2008-03-23 17:47:33Z spocke $
3 *
4 * @author Moxiecode
5 * @copyright Copyright � 2004-2008, Moxiecode Systems AB, All rights reserved.
6 */
7
8 (function() {
9 var Event = tinymce.dom.Event;
10
11 tinymce.create('tinymce.plugins.NonEditablePlugin', {
12 init : function(ed, url) {
13 var t = this, editClass, nonEditClass;
14
15 t.editor = ed;
16 editClass = ed.getParam("noneditable_editable_class", "mceEditable");
17 nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable");
18
19 ed.onNodeChange.addToTop(function(ed, cm, n) {
20 var sc, ec;
21
22 // Block if start or end is inside a non editable element
23 sc = ed.dom.getParent(ed.selection.getStart(), function(n) {
24 return ed.dom.hasClass(n, nonEditClass);
25 });
26
27 ec = ed.dom.getParent(ed.selection.getEnd(), function(n) {
28 return ed.dom.hasClass(n, nonEditClass);
29 });
30
31 // Block or unblock
32 if (sc || ec) {
33 t._setDisabled(1);
34 return false;
35 } else
36 t._setDisabled(0);
37 });
38 },
39
40 getInfo : function() {
41 return {
42 longname : 'Non editable elements',
43 author : 'Moxiecode Systems AB',
44 authorurl : 'http://tinymce.moxiecode.com',
45 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
46 version : tinymce.majorVersion + "." + tinymce.minorVersion
47 };
48 },
49
50 _block : function(ed, e) {
51 var k = e.keyCode;
52
53 // Don't block arrow keys, pg up/down, and F1-F12
54 if ((k > 32 && k < 41) || (k > 111 && k < 124))
55 return;
56
57 return Event.cancel(e);
58 },
59
60 _setDisabled : function(s) {
61 var t = this, ed = t.editor;
62
63 tinymce.each(ed.controlManager.controls, function(c) {
64 c.setDisabled(s);
65 });
66
67 if (s !== t.disabled) {
68 if (s) {
69 ed.onKeyDown.addToTop(t._block);
70 ed.onKeyPress.addToTop(t._block);
71 ed.onKeyUp.addToTop(t._block);
72 ed.onPaste.addToTop(t._block);
73 } else {
74 ed.onKeyDown.remove(t._block);
75 ed.onKeyPress.remove(t._block);
76 ed.onKeyUp.remove(t._block);
77 ed.onPaste.remove(t._block);
78 }
79
80 t.disabled = s;
81 }
82 }
83 });
84
85 // Register plugin
86 tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin);
87 })();