[ Index ] |
|
Code source de Seagull 0.6.1 |
1 /** 2 * $RCSfile: editor_plugin_src.js,v $ 3 * $Revision: 1.37 $ 4 * $Date: 2006/03/27 10:07:08 $ 5 * 6 * @author Moxiecode 7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 8 */ 9 10 /* Import plugin specific language pack */ 11 tinyMCE.importPluginLanguagePack('paste', 'en,tr,sv,cs,zh_cn,fr_ca,da,he,nb,de,hu,ru,ru_KOI8-R,ru_UTF-8,nn,fi,es,cy,is,pl,nl,fr,pt_br'); 12 13 var TinyMCE_PastePlugin = { 14 getInfo : function() { 15 return { 16 longname : 'Paste text/word', 17 author : 'Moxiecode Systems', 18 authorurl : 'http://tinymce.moxiecode.com', 19 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_paste.html', 20 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion 21 }; 22 }, 23 24 initInstance : function(inst) { 25 if (tinyMCE.isMSIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false)) 26 tinyMCE.addEvent(inst.getBody(), "paste", TinyMCE_PastePlugin._handlePasteEvent); 27 }, 28 29 getControlHTML : function(cn) { 30 switch (cn) { 31 case "pastetext": 32 return tinyMCE.getButtonHTML(cn, 'lang_paste_text_desc', '{$pluginurl}/images/pastetext.gif', 'mcePasteText', true); 33 34 case "pasteword": 35 return tinyMCE.getButtonHTML(cn, 'lang_paste_word_desc', '{$pluginurl}/images/pasteword.gif', 'mcePasteWord', true); 36 37 case "selectall": 38 return tinyMCE.getButtonHTML(cn, 'lang_selectall_desc', '{$pluginurl}/images/selectall.gif', 'mceSelectAll', true); 39 } 40 41 return ''; 42 }, 43 44 execCommand : function(editor_id, element, command, user_interface, value) { 45 switch (command) { 46 case "mcePasteText": 47 if (user_interface) { 48 if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false)) 49 TinyMCE_PastePlugin._insertText(clipboardData.getData("Text"), true); 50 else { 51 var template = new Array(); 52 template['file'] = '../../plugins/paste/pastetext.htm'; // Relative to theme 53 template['width'] = 450; 54 template['height'] = 400; 55 var plain_text = ""; 56 tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'}); 57 } 58 } else 59 TinyMCE_PastePlugin._insertText(value['html'], value['linebreaks']); 60 61 return true; 62 63 case "mcePasteWord": 64 if (user_interface) { 65 if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false)) { 66 var html = TinyMCE_PastePlugin._clipboardHTML(); 67 68 if (html && html.length > 0) 69 TinyMCE_PastePlugin._insertWordContent(html); 70 } else { 71 var template = new Array(); 72 template['file'] = '../../plugins/paste/pasteword.htm'; // Relative to theme 73 template['width'] = 450; 74 template['height'] = 400; 75 var plain_text = ""; 76 tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'}); 77 } 78 } else 79 TinyMCE_PastePlugin._insertWordContent(value); 80 81 return true; 82 83 case "mceSelectAll": 84 tinyMCE.execInstanceCommand(editor_id, 'selectall'); 85 return true; 86 87 } 88 89 // Pass to next handler in chain 90 return false; 91 }, 92 93 // Private plugin internal methods 94 95 _handlePasteEvent : function(e) { 96 switch (e.type) { 97 case "paste": 98 var html = TinyMCE_PastePlugin._clipboardHTML(); 99 var r, inst = tinyMCE.selectedInstance; 100 101 // Removes italic, strong etc, the if was needed due to bug #1437114 102 if (inst && (r = inst.getRng()) && r.text.length > 0) 103 tinyMCE.execCommand('delete'); 104 105 if (html && html.length > 0) 106 tinyMCE.execCommand('mcePasteWord', false, html); 107 108 tinyMCE.cancelEvent(e); 109 return false; 110 } 111 112 return true; 113 }, 114 115 _insertText : function(content, bLinebreaks) { 116 if (content && content.length > 0) { 117 if (bLinebreaks) { 118 // Special paragraph treatment 119 if (tinyMCE.getParam("paste_create_paragraphs", true)) { 120 var rl = tinyMCE.getParam("paste_replace_list", '\u2122,<sup>TM</sup>,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); 121 for (var i=0; i<rl.length; i+=2) 122 content = content.replace(new RegExp(rl[i], 'gi'), rl[i+1]); 123 124 content = tinyMCE.regexpReplace(content, "\r\n\r\n", "</p><p>", "gi"); 125 content = tinyMCE.regexpReplace(content, "\r\r", "</p><p>", "gi"); 126 content = tinyMCE.regexpReplace(content, "\n\n", "</p><p>", "gi"); 127 128 // Has paragraphs 129 if ((pos = content.indexOf('</p><p>')) != -1) { 130 tinyMCE.execCommand("Delete"); 131 132 var node = tinyMCE.selectedInstance.getFocusElement(); 133 134 // Get list of elements to break 135 var breakElms = new Array(); 136 137 do { 138 if (node.nodeType == 1) { 139 // Don't break tables and break at body 140 if (node.nodeName == "TD" || node.nodeName == "BODY") 141 break; 142 143 breakElms[breakElms.length] = node; 144 } 145 } while(node = node.parentNode); 146 147 var before = "", after = "</p>"; 148 before += content.substring(0, pos); 149 150 for (var i=0; i<breakElms.length; i++) { 151 before += "</" + breakElms[i].nodeName + ">"; 152 after += "<" + breakElms[(breakElms.length-1)-i].nodeName + ">"; 153 } 154 155 before += "<p>"; 156 content = before + content.substring(pos+7) + after; 157 } 158 } 159 160 if (tinyMCE.getParam("paste_create_linebreaks", true)) { 161 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi"); 162 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi"); 163 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi"); 164 } 165 } 166 167 tinyMCE.execCommand("mceInsertRawHTML", false, content); 168 } 169 }, 170 171 _insertWordContent : function(content) { 172 if (content && content.length > 0) { 173 // Cleanup Word content 174 var bull = String.fromCharCode(8226); 175 var middot = String.fromCharCode(183); 176 var cb; 177 178 if ((cb = tinyMCE.getParam("paste_insert_word_content_callback", "")) != "") 179 content = eval(cb + "('before', content)"); 180 181 var rl = tinyMCE.getParam("paste_replace_list", '\u2122,<sup>TM</sup>,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); 182 for (var i=0; i<rl.length; i+=2) 183 content = content.replace(new RegExp(rl[i], 'gi'), rl[i+1]); 184 185 if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) { 186 content = content.replace(new RegExp('<p class=MsoHeading.*?>(.*?)<\/p>', 'gi'), '<p><b>$1</b></p>'); 187 } 188 189 content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--"); 190 content = content.replace(new RegExp(bull + "(.*?)<BR>", "gi"), "<p>" + middot + "$1</p>"); 191 content = content.replace(new RegExp('<SPAN style="mso-list: Ignore">', 'gi'), "<span>" + bull); // Covert to bull list 192 content = content.replace(/<o:p><\/o:p>/gi, ""); 193 content = content.replace(new RegExp('<br style="page-break-before: always;.*>', 'gi'), '-- page break --'); // Replace pagebreaks 194 content = content.replace(new RegExp('<(!--)([^>]*)(--)>', 'g'), ""); // Word comments 195 196 if (tinyMCE.getParam("paste_remove_spans", true)) 197 content = content.replace(/<\/?span[^>]*>/gi, ""); 198 199 if (tinyMCE.getParam("paste_remove_styles", true)) 200 content = content.replace(new RegExp('<(\\w[^>]*) style="([^"]*)"([^>]*)', 'gi'), "<$1$3"); 201 202 content = content.replace(/<\/?font[^>]*>/gi, ""); 203 204 // Strips class attributes. 205 switch (tinyMCE.getParam("paste_strip_class_attributes", "all")) { 206 case "all": 207 content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3"); 208 break; 209 210 case "mso": 211 content = content.replace(new RegExp('<(\\w[^>]*) class="?mso([^ |>]*)([^>]*)', 'gi'), "<$1$3"); 212 break; 213 } 214 215 content = content.replace(new RegExp('href="?' + TinyMCE_PastePlugin._reEscape("" + document.location) + '', 'gi'), 'href="' + tinyMCE.settings['document_base_url']); 216 content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3"); 217 content = content.replace(/<\\?\?xml[^>]*>/gi, ""); 218 content = content.replace(/<\/?\w+:[^>]*>/gi, ""); 219 content = content.replace(/-- page break --\s*<p> <\/p>/gi, ""); // Remove pagebreaks 220 content = content.replace(/-- page break --/gi, ""); // Remove pagebreaks 221 222 // content = content.replace(/\/? */gi, ""); 223 // content = content.replace(/<p> <\/p>/gi, ''); 224 225 if (!tinyMCE.settings['force_p_newlines']) { 226 content = content.replace('', '' ,'gi'); 227 content = content.replace('</p>', '<br /><br />' ,'gi'); 228 } 229 230 if (!tinyMCE.isMSIE && !tinyMCE.settings['force_p_newlines']) { 231 content = content.replace(/<\/?p[^>]*>/gi, ""); 232 } 233 234 content = content.replace(/<\/?div[^>]*>/gi, ""); 235 236 // Convert all middlot lists to UL lists 237 if (tinyMCE.getParam("paste_convert_middot_lists", true)) { 238 var div = document.createElement("div"); 239 div.innerHTML = content; 240 241 // Convert all middot paragraphs to li elements 242 var className = tinyMCE.getParam("paste_unindented_list_class", "unIndentedList"); 243 244 while (TinyMCE_PastePlugin._convertMiddots(div, "--list--")) ; // bull 245 while (TinyMCE_PastePlugin._convertMiddots(div, middot, className)) ; // Middot 246 while (TinyMCE_PastePlugin._convertMiddots(div, bull)) ; // bull 247 248 content = div.innerHTML; 249 } 250 251 // Replace all headers with strong and fix some other issues 252 if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) { 253 content = content.replace(/<h[1-6]> <\/h[1-6]>/gi, '<p> </p>'); 254 content = content.replace(/<h[1-6]>/gi, '<p><b>'); 255 content = content.replace(/<\/h[1-6]>/gi, '</b></p>'); 256 content = content.replace(/<b> <\/b>/gi, '<b> </b>'); 257 content = content.replace(/^( )*/gi, ''); 258 } 259 260 content = content.replace(/--list--/gi, ""); // Remove --list-- 261 262 if ((cb = tinyMCE.getParam("paste_insert_word_content_callback", "")) != "") 263 content = eval(cb + "('after', content)"); 264 265 // Insert cleaned content 266 tinyMCE.execCommand("mceInsertContent", false, content); 267 window.setTimeout('tinyMCE.execCommand("mceCleanup");', 1); // Do normal cleanup detached from this thread 268 } 269 }, 270 271 _reEscape : function(s) { 272 var l = "?.\\*[](){}+^$:"; 273 var o = ""; 274 275 for (var i=0; i<s.length; i++) { 276 var c = s.charAt(i); 277 278 if (l.indexOf(c) != -1) 279 o += '\\' + c; 280 else 281 o += c; 282 } 283 284 return o; 285 }, 286 287 _convertMiddots : function(div, search, class_name) { 288 var mdot = String.fromCharCode(183); 289 var bull = String.fromCharCode(8226); 290 291 var nodes = div.getElementsByTagName("p"); 292 var prevul; 293 for (var i=0; i<nodes.length; i++) { 294 var p = nodes[i]; 295 296 // Is middot 297 if (p.innerHTML.indexOf(search) == 0) { 298 var ul = document.createElement("ul"); 299 300 if (class_name) 301 ul.className = class_name; 302 303 // Add the first one 304 var li = document.createElement("li"); 305 li.innerHTML = p.innerHTML.replace(new RegExp('' + mdot + '|' + bull + '|--list--| ', "gi"), ''); 306 ul.appendChild(li); 307 308 // Add the rest 309 var np = p.nextSibling; 310 while (np) { 311 // If the node is whitespace, then 312 // ignore it and continue on. 313 if (np.nodeType == 3 && new RegExp('^\\s$', 'm').test(np.nodeValue)) { 314 np = np.nextSibling; 315 continue; 316 } 317 318 if (search == mdot) { 319 if (np.nodeType == 1 && new RegExp('^o(\\s+| )').test(np.innerHTML)) { 320 // Second level of nesting 321 if (!prevul) { 322 prevul = ul; 323 ul = document.createElement("ul"); 324 prevul.appendChild(ul); 325 } 326 np.innerHTML = np.innerHTML.replace(/^o/, ''); 327 } else { 328 // Pop the stack if we're going back up to the first level 329 if (prevul) { 330 ul = prevul; 331 prevul = null; 332 } 333 // Not element or middot paragraph 334 if (np.nodeType != 1 || np.innerHTML.indexOf(search) != 0) 335 break; 336 } 337 } else { 338 // Not element or middot paragraph 339 if (np.nodeType != 1 || np.innerHTML.indexOf(search) != 0) 340 break; 341 } 342 343 var cp = np.nextSibling; 344 var li = document.createElement("li"); 345 li.innerHTML = np.innerHTML.replace(new RegExp('' + mdot + '|' + bull + '|--list--| ', "gi"), ''); 346 np.parentNode.removeChild(np); 347 ul.appendChild(li); 348 np = cp; 349 } 350 351 p.parentNode.replaceChild(ul, p); 352 353 return true; 354 } 355 } 356 357 return false; 358 }, 359 360 _clipboardHTML : function() { 361 var div = document.getElementById('_TinyMCE_clipboardHTML'); 362 363 if (!div) { 364 var div = document.createElement('DIV'); 365 div.id = '_TinyMCE_clipboardHTML'; 366 367 with (div.style) { 368 visibility = 'hidden'; 369 overflow = 'hidden'; 370 position = 'absolute'; 371 width = 1; 372 height = 1; 373 } 374 375 document.body.appendChild(div); 376 } 377 378 div.innerHTML = ''; 379 var rng = document.body.createTextRange(); 380 rng.moveToElementText(div); 381 rng.execCommand('Paste'); 382 var html = div.innerHTML; 383 div.innerHTML = ''; 384 return html; 385 } 386 }; 387 388 tinyMCE.addPlugin("paste", TinyMCE_PastePlugin);
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 |