[ Index ] |
|
Code source de Seagull 0.6.1 |
1 /** 2 * $RCSfile: editor_plugin_src.js,v $ 3 * $Revision: 1.7 $ 4 * $Date: 2006/02/06 20:02:38 $ 5 * 6 * @author Moxiecode 7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 8 */ 9 10 var TinyMCE_NonEditablePlugin = { 11 getInfo : function() { 12 return { 13 longname : 'Non editable elements', 14 author : 'Moxiecode Systems', 15 authorurl : 'http://tinymce.moxiecode.com', 16 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_noneditable.html', 17 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion 18 }; 19 }, 20 21 initInstance : function(inst) { 22 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/noneditable/css/noneditable.css"); 23 24 // Ugly hack 25 if (tinyMCE.isMSIE5_0) 26 tinyMCE.settings['plugins'] = tinyMCE.settings['plugins'].replace(/noneditable/gi, 'Noneditable'); 27 28 if (tinyMCE.isGecko) { 29 tinyMCE.addEvent(inst.getDoc(), "keyup", TinyMCE_NonEditablePlugin._fixKeyUp); 30 // tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_NonEditablePlugin._selectAll); 31 // tinyMCE.addEvent(inst.getDoc(), "mouseup", TinyMCE_NonEditablePlugin._selectAll); 32 } 33 }, 34 35 cleanup : function(type, content, inst) { 36 switch (type) { 37 case "insert_to_editor_dom": 38 var nodes = tinyMCE.getNodeTree(content, new Array(), 1); 39 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable"); 40 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable"); 41 42 for (var i=0; i<nodes.length; i++) { 43 var elm = nodes[i]; 44 45 // Convert contenteditable to classes 46 var editable = tinyMCE.getAttrib(elm, "contenteditable"); 47 if (new RegExp("true|false","gi").test(editable)) 48 TinyMCE_NonEditablePlugin._setEditable(elm, editable == "true"); 49 50 if (tinyMCE.isMSIE) { 51 var className = elm.className ? elm.className : ""; 52 53 if (className.indexOf(editClass) != -1) 54 elm.contentEditable = true; 55 56 if (className.indexOf(nonEditClass) != -1) 57 elm.contentEditable = false; 58 } 59 } 60 61 break; 62 63 case "insert_to_editor": 64 if (tinyMCE.isMSIE) { 65 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable"); 66 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable"); 67 68 content = content.replace(new RegExp("class=\"(.*)(" + editClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="true"'); 69 content = content.replace(new RegExp("class=\"(.*)(" + nonEditClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="false"'); 70 } 71 72 break; 73 74 case "get_from_editor_dom": 75 if (tinyMCE.getParam("noneditable_leave_contenteditable", false)) { 76 var nodes = tinyMCE.getNodeTree(content, new Array(), 1); 77 78 for (var i=0; i<nodes.length; i++) 79 nodes[i].removeAttribute("contenteditable"); 80 } 81 82 break; 83 } 84 85 return content; 86 }, 87 88 // Private internal plugin methods 89 90 _fixKeyUp : function(e) { 91 var inst = tinyMCE.selectedInstance; 92 var sel = inst.getSel(); 93 var rng = inst.getRng(); 94 var an = sel.anchorNode; 95 96 // Move cursor outside non editable fields 97 if ((e.keyCode == 38 || e.keyCode == 37 || e.keyCode == 40 || e.keyCode == 39) && (elm = TinyMCE_NonEditablePlugin._isNonEditable(an)) != null) { 98 rng = inst.getDoc().createRange(); 99 rng.selectNode(elm); 100 rng.collapse(true); 101 sel.removeAllRanges(); 102 sel.addRange(rng); 103 tinyMCE.cancelEvent(e); 104 } 105 }, 106 /* 107 _selectAll : function(e) { 108 var inst = tinyMCE.selectedInstance; 109 var sel = inst.getSel(); 110 var doc = inst.getDoc(); 111 112 if ((elm = TinyMCE_NonEditablePlugin._isNonEditable(sel.focusNode)) != null) { 113 inst.selection.selectNode(elm, false); 114 tinyMCE.cancelEvent(e); 115 return; 116 } 117 118 if ((elm = TinyMCE_NonEditablePlugin._isNonEditable(sel.anchorNode)) != null) { 119 inst.selection.selectNode(elm, false); 120 tinyMCE.cancelEvent(e); 121 return; 122 } 123 },*/ 124 125 _isNonEditable : function(elm) { 126 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable"); 127 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable"); 128 129 if (!elm) 130 return; 131 132 do { 133 var className = elm.className ? elm.className : ""; 134 135 if (className.indexOf(editClass) != -1) 136 return null; 137 138 if (className.indexOf(nonEditClass) != -1) 139 return elm; 140 } while (elm = elm.parentNode); 141 142 return null; 143 }, 144 145 _setEditable : function(elm, state) { 146 var editClass = tinyMCE.getParam("noneditable_editable_class", "mceEditable"); 147 var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceNonEditable"); 148 149 var className = elm.className ? elm.className : ""; 150 151 if (className.indexOf(editClass) != -1 || className.indexOf(nonEditClass) != -1) 152 return; 153 154 if ((className = tinyMCE.getAttrib(elm, "class")) != "") 155 className += " "; 156 157 className += state ? editClass : nonEditClass; 158 159 elm.setAttribute("class", className); 160 elm.className = className; 161 } 162 }; 163 164 tinyMCE.addPlugin("noneditable", TinyMCE_NonEditablePlugin);
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 01:27:52 2007 | par Balluche grâce à PHPXref 0.7 |