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