[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 // Tiny MCE Paste Plugin 2 // Updated by speednet 25 May 2005 - IE converts and pastes without opening popup window 3 4 /* Import plugin specific language pack */ 5 tinyMCE.importPluginLanguagePack('paste', 'en,sv'); 6 7 function TinyMCE_paste_getControlHTML(control_name) { 8 switch (control_name) { 9 case "pastetext": 10 return '<img id="{$editor_id}pastetext" src="{$pluginurl}/images/pastetext.gif" title="{$lang_paste_text_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcePasteText\');" />'; 11 12 case "pasteword": 13 return '<img id="{$editor_id}pasteword" src="{$pluginurl}/images/pasteword.gif" title="{$lang_paste_word_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcePasteWord\');" />'; 14 15 case "selectall": 16 return '<img id="{$editor_id}selectall" src="{$pluginurl}/images/selectall.gif" title="{$lang_selectall_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSelectAll\');" />'; 17 } 18 19 return ''; 20 } 21 22 function TinyMCE_paste_execCommand(editor_id, element, command, user_interface, value) { 23 switch (command) { 24 case "mcePasteText": 25 if (tinyMCE.isMSIE && tinyMCE.getParam('paste_use_dialog', false)) 26 TinyMCE_paste__insertText(clipboardData.getData("Text"), true); 27 else { 28 var template = new Array(); 29 template['file'] = '../../plugins/paste/pastetext.htm'; // Relative to theme 30 template['width'] = 450; 31 template['height'] = 400; 32 var plain_text = ""; 33 tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", mceDo : 'insert'}); 34 } 35 36 return true; 37 38 case "mcePasteWord": 39 if (tinyMCE.isMSIE && tinyMCE.getParam('paste_use_dialog', false)) { 40 var html = TinyMCE_paste__clipboardHTML(); 41 42 if (html && html.length > 0) 43 TinyMCE_paste__insertWordContent(html); 44 } else { 45 var template = new Array(); 46 template['file'] = '../../plugins/paste/pasteword.htm'; // Relative to theme 47 template['width'] = 450; 48 template['height'] = 400; 49 var plain_text = ""; 50 tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", mceDo : 'insert'}); 51 } 52 53 return true; 54 55 case "mceSelectAll": 56 tinyMCE.execInstanceCommand(editor_id, 'selectall'); 57 return true; 58 59 } 60 61 // Pass to next handler in chain 62 return false; 63 } 64 65 function TinyMCE_paste__insertText(content, bLinebreaks) { 66 67 if (content && content.length > 0) { 68 if (bLinebreaks) { 69 // Special paragraph treatment 70 if (tinyMCE.getParam("plaintext_create_paragraphs", true)) { 71 content = tinyMCE.regexpReplace(content, "\r\n\r\n", "</p><p>", "gi"); 72 content = tinyMCE.regexpReplace(content, "\r\r", "</p><p>", "gi"); 73 content = tinyMCE.regexpReplace(content, "\n\n", "</p><p>", "gi"); 74 75 // Has paragraphs 76 if ((pos = content.indexOf('</p><p>')) != -1) { 77 tinyMCE.execCommand("Delete"); 78 79 var node = tinyMCE.selectedInstance.getFocusElement(); 80 81 // Get list of elements to break 82 var breakElms = new Array(); 83 84 do { 85 if (node.nodeType == 1) { 86 // Don't break tables and break at body 87 if (node.nodeName == "TD" || node.nodeName == "BODY") 88 break; 89 90 breakElms[breakElms.length] = node; 91 } 92 } while(node = node.parentNode); 93 94 var before = "", after = "</p>"; 95 before += content.substring(0, pos); 96 97 for (var i=0; i<breakElms.length; i++) { 98 before += "</" + breakElms[i].nodeName + ">"; 99 after += "<" + breakElms[(breakElms.length-1)-i].nodeName + ">"; 100 } 101 102 before += "<p>"; 103 content = before + content.substring(pos+7) + after; 104 } 105 } 106 107 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi"); 108 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi"); 109 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi"); 110 } 111 112 tinyMCE.execCommand("mceInsertRawHTML", false, content); 113 } 114 } 115 116 function TinyMCE_paste__insertWordContent(content) { 117 118 if (content && content.length > 0) { 119 // Cleanup Word content 120 content = content.replace(new RegExp('<(!--)([^>]*)(--)>', 'g'), ""); // Word comments 121 content = content.replace(/<\/?span[^>]*>/gi, ""); 122 content = content.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3"); 123 content = content.replace(/<\/?font[^>]*>/gi, ""); 124 content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3"); 125 content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3"); 126 content = content.replace(/<\\?\?xml[^>]*>/gi, ""); 127 content = content.replace(/<\/?\w+:[^>]*>/gi, ""); 128 content = content.replace(/\/? */gi, ""); 129 content = content.replace('<p> </p>', '' ,'g'); 130 131 if (!tinyMCE.settings['force_p_newlines']) { 132 content = content.replace('', '' ,'gi'); 133 content = content.replace('</p>', '<br /><br />' ,'gi'); 134 } 135 136 if (!tinyMCE.isMSIE && !tinyMCE.settings['force_p_newlines']) { 137 content = content.replace(/<\/?p[^>]*>/gi, ""); 138 } 139 140 content = content.replace(/<\/?div[^>]*>/gi, ""); 141 142 // Insert cleaned content 143 tinyMCE.execCommand("mceAddUndoLevel"); 144 tinyMCE.execCommand("mceInsertContent", false, content); 145 } 146 } 147 148 function TinyMCE_paste__clipboardHTML() { 149 var div = document.getElementById('_TinyMCE_clipboardHTML'); 150 151 if (!div) { 152 var div = document.createElement('DIV'); 153 div.id = '_TinyMCE_clipboardHTML'; 154 155 with (div.style) { 156 visibility = 'hidden'; 157 overflow = 'hidden'; 158 position = 'absolute'; 159 width = 1; 160 height = 1; 161 } 162 163 document.body.appendChild(div); 164 } 165 166 div.innerHTML = ''; 167 var rng = document.body.createTextRange(); 168 rng.moveToElementText(div); 169 rng.execCommand('Paste'); 170 var html = div.innerHTML; 171 div.innerHTML = ''; 172 return html; 173 } 174
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |