annotate media/js/tiny_mce/plugins/noneditable/editor_plugin_src.js @ 273:2dbb657a2305

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