[1] | 1 | /** |
---|
| 2 | * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z 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 | return Event.cancel(e); |
---|
| 52 | }, |
---|
| 53 | |
---|
| 54 | _setDisabled : function(s) { |
---|
| 55 | var t = this, ed = t.editor; |
---|
| 56 | |
---|
| 57 | tinymce.each(ed.controlManager.controls, function(c) { |
---|
| 58 | c.setDisabled(s); |
---|
| 59 | }); |
---|
| 60 | |
---|
| 61 | if (s !== t.disabled) { |
---|
| 62 | if (s) { |
---|
| 63 | ed.onKeyDown.addToTop(t._block); |
---|
| 64 | ed.onKeyPress.addToTop(t._block); |
---|
| 65 | ed.onKeyUp.addToTop(t._block); |
---|
| 66 | ed.onPaste.addToTop(t._block); |
---|
| 67 | } else { |
---|
| 68 | ed.onKeyDown.remove(t._block); |
---|
| 69 | ed.onKeyPress.remove(t._block); |
---|
| 70 | ed.onKeyUp.remove(t._block); |
---|
| 71 | ed.onPaste.remove(t._block); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | t.disabled = s; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | }); |
---|
| 78 | |
---|
| 79 | // Register plugin |
---|
| 80 | tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin); |
---|
| 81 | })(); |
---|