--- a/includes/clientside/tinymce/plugins/noneditable/editor_plugin_src.js Wed Dec 26 00:37:26 2007 -0500
+++ b/includes/clientside/tinymce/plugins/noneditable/editor_plugin_src.js Thu Dec 27 22:09:33 2007 -0500
@@ -1,153 +1,81 @@
/**
- * $Id: editor_plugin_src.js 205 2007-02-12 18:58:29Z spocke $
+ * $Id: editor_plugin_src.js 372 2007-11-11 18:38:50Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/
-var TinyMCE_NonEditablePlugin = {
- getInfo : function() {
- return {
- longname : 'Non editable elements',
- author : 'Moxiecode Systems AB',
- authorurl : 'http://tinymce.moxiecode.com',
- infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
- version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
- };
- },
+(function() {
+ var Event = tinymce.dom.Event;
+
+ tinymce.create('tinymce.plugins.NonEditablePlugin', {
+ init : function(ed, url) {
+ var t = this, editClass, nonEditClass;
- initInstance : function(inst) {
- tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/noneditable/css/noneditable.css");
+ t.editor = ed;
+ editClass = ed.getParam("noneditable_editable_class", "mceEditable");
+ nonEditClass = ed.getParam("noneditable_noneditable_class", "mceNonEditable");
+
+ ed.onNodeChange.addToTop(function(ed, cm, n) {
+ var sc, ec;
- // Ugly hack
- if (tinyMCE.isMSIE5_0)
- tinyMCE.settings['plugins'] = tinyMCE.settings['plugins'].replace(/noneditable/gi, 'Noneditable');
- },
+ // Block if start or end is inside a non editable element
+ sc = ed.dom.getParent(ed.selection.getStart(), function(n) {
+ return ed.dom.hasClass(n, nonEditClass);
+ });
- handleEvent : function(e) {
- return this._moveSelection(e, tinyMCE.selectedInstance);
- },
+ ec = ed.dom.getParent(ed.selection.getEnd(), function(n) {
+ return ed.dom.hasClass(n, nonEditClass);
+ });
- cleanup : function(type, content, inst) {
- switch (type) {
- case "insert_to_editor_dom":
- var nodes, i, editClass, nonEditClass, editable, elm;
-
- // Pass through Gecko
- if (tinyMCE.isGecko)
- return content;
-
- nodes = tinyMCE.getNodeTree(content, [], 1);
+ // Block or unblock
+ if (sc || ec) {
+ t._setDisabled(1);
+ return false;
+ } else
+ t._setDisabled(0);
+ });
+ },
- editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable");
- nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable");
-
- for (i=0; i<nodes.length; i++) {
- elm = nodes[i];
+ getInfo : function() {
+ return {
+ longname : 'Non editable elements',
+ author : 'Moxiecode Systems AB',
+ authorurl : 'http://tinymce.moxiecode.com',
+ infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/noneditable',
+ version : tinymce.majorVersion + "." + tinymce.minorVersion
+ };
+ },
- // Convert contenteditable to classes
- editable = tinyMCE.getAttrib(elm, "contenteditable");
- if (new RegExp("true|false","gi").test(editable))
- TinyMCE_NonEditablePlugin._setEditable(elm, editable == "true");
-
- if (tinyMCE.isIE) {
- if (tinyMCE.hasCSSClass(elm, editClass))
- elm.contentEditable = true;
+ _block : function(ed, e) {
+ return Event.cancel(e);
+ },
- if (tinyMCE.hasCSSClass(elm, nonEditClass))
- elm.contentEditable = false;
- }
- }
+ _setDisabled : function(s) {
+ var t = this, ed = t.editor;
- break;
-
- case "insert_to_editor":
- var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable");
- var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable");
+ tinymce.each(ed.controlManager.controls, function(c) {
+ c.setDisabled(s);
+ });
- // Replace mceItem to new school
- content = content.replace(/mceItemEditable/g, editClass);
- content = content.replace(/mceItemNonEditable/g, nonEditClass);
-
- if (tinyMCE.isIE && (content.indexOf(editClass) != -1 || content.indexOf(nonEditClass) != -1)) {
- content = content.replace(new RegExp("class=\"(.+)(" + editClass + ")\"", "gi"), 'class="$1$2" contenteditable="true"');
- content = content.replace(new RegExp("class=\"(.+)(" + nonEditClass + ")\"", "gi"), 'class="$1$2" contenteditable="false"');
- content = content.replace(new RegExp("class=\"(" + editClass + ")([^\"]*)\"", "gi"), 'class="$1$2" contenteditable="true"');
- content = content.replace(new RegExp("class=\"(" + nonEditClass + ")([^\"]*)\"", "gi"), 'class="$1$2" contenteditable="false"');
- content = content.replace(new RegExp("class=\"(.+)(" + editClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="true"');
- content = content.replace(new RegExp("class=\"(.+)(" + nonEditClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="false"');
+ if (s !== t.disabled) {
+ if (s) {
+ ed.onKeyDown.addToTop(t._block);
+ ed.onKeyPress.addToTop(t._block);
+ ed.onKeyUp.addToTop(t._block);
+ ed.onPaste.addToTop(t._block);
+ } else {
+ ed.onKeyDown.remove(t._block);
+ ed.onKeyPress.remove(t._block);
+ ed.onKeyUp.remove(t._block);
+ ed.onPaste.remove(t._block);
}
- break;
-
- case "get_from_editor_dom":
- // Pass through Gecko
- if (tinyMCE.isGecko)
- return content;
-
- if (tinyMCE.getParam("noneditable_leave_contenteditable", false)) {
- var nodes = tinyMCE.getNodeTree(content, new Array(), 1);
-
- for (var i=0; i<nodes.length; i++)
- nodes[i].removeAttribute("contenteditable");
- }
-
- break;
- }
-
- return content;
- },
-
- _moveSelection : function(e, inst) {
- var s, r, sc, ec, el, c = tinyMCE.getParam('noneditable_editable_class', 'mceNonEditable');
-
- if (!inst)
- return true;
-
- // Always select whole element
- if (tinyMCE.isGecko) {
- s = inst.selection.getSel();
- r = s.getRangeAt(0);
- sc = tinyMCE.getParentNode(r.startContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
- ec = tinyMCE.getParentNode(r.endContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
-
- sc && r.setStartBefore(sc);
- ec && r.setEndAfter(ec);
-
- if (sc || ec) {
- if (e.type == 'keypress' && e.keyCode == 39) {
- el = sc || ec;
-
- // Try!!
- }
-
- s.removeAllRanges();
- s.addRange(r);
-
- return tinyMCE.cancelEvent(e);
+ t.disabled = s;
}
}
-
- return true;
- },
-
- _setEditable : function(elm, state) {
- var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable");
- var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable");
-
- var className = elm.className ? elm.className : "";
+ });
- if (className.indexOf(editClass) != -1 || className.indexOf(nonEditClass) != -1)
- return;
-
- if ((className = tinyMCE.getAttrib(elm, "class")) != "")
- className += " ";
-
- className += state ? editClass : nonEditClass;
-
- elm.setAttribute("class", className);
- elm.className = className;
- }
-};
-
-tinyMCE.addPlugin("noneditable", TinyMCE_NonEditablePlugin);
+ // Register plugin
+ tinymce.PluginManager.add('noneditable', tinymce.plugins.NonEditablePlugin);
+})();
\ No newline at end of file