bgneal@312: /** bgneal@312: * editor_plugin_src.js bgneal@312: * bgneal@312: * Copyright 2009, Moxiecode Systems AB bgneal@312: * Released under LGPL License. bgneal@312: * bgneal@312: * License: http://tinymce.moxiecode.com/license bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@312: */ bgneal@312: bgneal@312: (function() { bgneal@312: var Event = tinymce.dom.Event; bgneal@312: bgneal@312: tinymce.create('tinymce.plugins.NonEditablePlugin', { bgneal@312: init : function(ed, url) { bgneal@312: var t = this, editClass, nonEditClass; bgneal@312: bgneal@312: t.editor = ed; bgneal@312: editClass = ed.getParam("noneditable_editable_class", "mceEditable"); bgneal@312: nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable"); bgneal@312: bgneal@312: ed.onNodeChange.addToTop(function(ed, cm, n) { bgneal@312: var sc, ec; bgneal@312: bgneal@312: // Block if start or end is inside a non editable element bgneal@312: sc = ed.dom.getParent(ed.selection.getStart(), function(n) { bgneal@312: return ed.dom.hasClass(n, nonEditClass); bgneal@312: }); bgneal@312: bgneal@312: ec = ed.dom.getParent(ed.selection.getEnd(), function(n) { bgneal@312: return ed.dom.hasClass(n, nonEditClass); bgneal@312: }); bgneal@312: bgneal@312: // Block or unblock bgneal@312: if (sc || ec) { bgneal@312: t._setDisabled(1); bgneal@312: return false; bgneal@312: } else bgneal@312: t._setDisabled(0); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getInfo : function() { bgneal@312: return { bgneal@312: longname : 'Non editable elements', bgneal@312: author : 'Moxiecode Systems AB', bgneal@312: authorurl : 'http://tinymce.moxiecode.com', bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable', bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: _block : function(ed, e) { bgneal@312: var k = e.keyCode; bgneal@312: bgneal@312: // Don't block arrow keys, pg up/down, and F1-F12 bgneal@312: if ((k > 32 && k < 41) || (k > 111 && k < 124)) bgneal@312: return; bgneal@312: bgneal@312: return Event.cancel(e); bgneal@312: }, bgneal@312: bgneal@312: _setDisabled : function(s) { bgneal@312: var t = this, ed = t.editor; bgneal@312: bgneal@312: tinymce.each(ed.controlManager.controls, function(c) { bgneal@312: c.setDisabled(s); bgneal@312: }); bgneal@312: bgneal@312: if (s !== t.disabled) { bgneal@312: if (s) { bgneal@312: ed.onKeyDown.addToTop(t._block); bgneal@312: ed.onKeyPress.addToTop(t._block); bgneal@312: ed.onKeyUp.addToTop(t._block); bgneal@312: ed.onPaste.addToTop(t._block); bgneal@442: ed.onContextMenu.addToTop(t._block); bgneal@312: } else { bgneal@312: ed.onKeyDown.remove(t._block); bgneal@312: ed.onKeyPress.remove(t._block); bgneal@312: ed.onKeyUp.remove(t._block); bgneal@312: ed.onPaste.remove(t._block); bgneal@442: ed.onContextMenu.remove(t._block); bgneal@312: } bgneal@312: bgneal@312: t.disabled = s; bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Register plugin bgneal@312: tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin); bgneal@312: })();