2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
\r
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
\r
8 var TinyMCE_NonEditablePlugin = {
\r
9 getInfo : function() {
\r
11 longname : 'Non editable elements',
\r
12 author : 'Moxiecode Systems AB',
\r
13 authorurl : 'http://tinymce.moxiecode.com',
\r
14 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_noneditable.html',
\r
15 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
\r
19 initInstance : function(inst) {
\r
20 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/noneditable/css/noneditable.css");
\r
23 if (tinyMCE.isMSIE5_0)
\r
24 tinyMCE.settings['plugins'] = tinyMCE.settings['plugins'].replace(/noneditable/gi, 'Noneditable');
\r
27 handleEvent : function(e) {
\r
28 return this._moveSelection(e, tinyMCE.selectedInstance);
\r
31 cleanup : function(type, content, inst) {
\r
32 // Pass through Gecko
\r
33 if (tinyMCE.isGecko)
\r
37 case "insert_to_editor_dom":
\r
38 var nodes = tinyMCE.getNodeTree(content, new Array(), 1);
\r
39 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
\r
40 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
\r
42 for (var i=0; i<nodes.length; i++) {
\r
45 // Convert contenteditable to classes
\r
46 var editable = tinyMCE.getAttrib(elm, "contenteditable");
\r
47 if (new RegExp("true|false","gi").test(editable))
\r
48 TinyMCE_NonEditablePlugin._setEditable(elm, editable == "true");
\r
50 if (tinyMCE.isMSIE) {
\r
51 var className = elm.className ? elm.className : "";
\r
53 if (className.indexOf(editClass) != -1)
\r
54 elm.contentEditable = true;
\r
56 if (className.indexOf(nonEditClass) != -1)
\r
57 elm.contentEditable = false;
\r
63 case "insert_to_editor":
\r
64 if (tinyMCE.isMSIE) {
\r
65 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
\r
66 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
\r
68 content = content.replace(new RegExp("class=\"(.*)(" + editClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="true"');
\r
69 content = content.replace(new RegExp("class=\"(.*)(" + nonEditClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="false"');
\r
74 case "get_from_editor_dom":
\r
75 if (tinyMCE.getParam("noneditable_leave_contenteditable", false)) {
\r
76 var nodes = tinyMCE.getNodeTree(content, new Array(), 1);
\r
78 for (var i=0; i<nodes.length; i++)
\r
79 nodes[i].removeAttribute("contenteditable");
\r
88 _moveSelection : function(e, inst) {
\r
89 var s, r, sc, ec, el, c = tinyMCE.getParam('noneditable_editable_class', 'mceItemNonEditable');
\r
94 // Always select whole element
\r
95 if (tinyMCE.isGecko) {
\r
96 s = inst.selection.getSel();
\r
97 r = s.getRangeAt(0);
\r
98 sc = tinyMCE.getParentNode(r.startContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
\r
99 ec = tinyMCE.getParentNode(r.endContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
\r
101 sc && r.setStartBefore(sc);
\r
102 ec && r.setEndAfter(ec);
\r
105 if (e.type == 'keypress' && e.keyCode == 39) {
\r
111 s.removeAllRanges();
\r
114 return tinyMCE.cancelEvent(e);
\r
121 _setEditable : function(elm, state) {
\r
122 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
\r
123 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
\r
125 var className = elm.className ? elm.className : "";
\r
127 if (className.indexOf(editClass) != -1 || className.indexOf(nonEditClass) != -1)
\r
130 if ((className = tinyMCE.getAttrib(elm, "class")) != "")
\r
133 className += state ? editClass : nonEditClass;
\r
135 elm.setAttribute("class", className);
\r
136 elm.className = className;
\r
140 tinyMCE.addPlugin("noneditable", TinyMCE_NonEditablePlugin);
\r