X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Fplugins%2Fpaste%2Feditor_plugin_src.js;h=1d9d3b42e7ca3070541f01a117d15141c86afcda;hb=b05f4eef4014db3885787ef15107cba93c932ac9;hp=da69cbb6df3e4481e7c017da4256f0ba8f3e6298;hpb=11d9e4ed8d4dfe0f5f4f35dc36fdd69008fa081e;p=citadel.git diff --git a/webcit/tiny_mce/plugins/paste/editor_plugin_src.js b/webcit/tiny_mce/plugins/paste/editor_plugin_src.js index da69cbb6d..1d9d3b42e 100644 --- a/webcit/tiny_mce/plugins/paste/editor_plugin_src.js +++ b/webcit/tiny_mce/plugins/paste/editor_plugin_src.js @@ -1,292 +1,861 @@ -/* Import plugin specific language pack */ -tinyMCE.importPluginLanguagePack('paste', 'en,sv,cs,zh_cn,fr_ca,da,he,no,de,hu'); - -function TinyMCE_paste_getInfo() { - return { - longname : 'Paste text/word', - author : 'Moxiecode Systems', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_paste.html', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; -}; - -function TinyMCE_paste_initInstance(inst) { - if (tinyMCE.isMSIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false)) - tinyMCE.addEvent(inst.getBody(), "paste", TinyMCE_paste_handleEvent); -} - -function TinyMCE_paste_handleEvent(e) { - switch (e.type) { - case "paste": - var html = TinyMCE_paste__clipboardHTML(); - - // Removes italic, strong etc - tinyMCE.execCommand('delete'); - - if (html && html.length > 0) - tinyMCE.execCommand('mcePasteWord', false, html); - - tinyMCE.cancelEvent(e); - return false; - } - - return true; -} - -function TinyMCE_paste_getControlHTML(control_name) { - switch (control_name) { - case "pastetext": - return ''; - - case "pasteword": - return ''; - - case "selectall": - return ''; - } - - return ''; -} - -function TinyMCE_paste_execCommand(editor_id, element, command, user_interface, value) { - switch (command) { - case "mcePasteText": - if (user_interface) { - if (tinyMCE.isMSIE && !tinyMCE.getParam('paste_use_dialog', false)) - TinyMCE_paste__insertText(clipboardData.getData("Text"), true); - else { - var template = new Array(); - template['file'] = '../../plugins/paste/pastetext.htm'; // Relative to theme - template['width'] = 450; - template['height'] = 400; - var plain_text = ""; - tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'}); - } - } else - TinyMCE_paste__insertText(value['html'], value['linebreaks']); - - return true; - - case "mcePasteWord": - if (user_interface) { - if (tinyMCE.isMSIE && !tinyMCE.getParam('paste_use_dialog', false)) { - var html = TinyMCE_paste__clipboardHTML(); - - if (html && html.length > 0) - TinyMCE_paste__insertWordContent(html); - } else { - var template = new Array(); - template['file'] = '../../plugins/paste/pasteword.htm'; // Relative to theme - template['width'] = 450; - template['height'] = 400; - var plain_text = ""; - tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'}); - } - } else - TinyMCE_paste__insertWordContent(value); - - return true; - - case "mceSelectAll": - tinyMCE.execInstanceCommand(editor_id, 'selectall'); - return true; - - } - - // Pass to next handler in chain - return false; -} - -function TinyMCE_paste__insertText(content, bLinebreaks) { - if (content && content.length > 0) { - if (bLinebreaks) { - // Special paragraph treatment - if (tinyMCE.getParam("plaintext_create_paragraphs", true)) { - content = tinyMCE.regexpReplace(content, "\r\n\r\n", "
", "gi"); - content = tinyMCE.regexpReplace(content, "\r\r", "
", "gi"); - content = tinyMCE.regexpReplace(content, "\n\n", "
", "gi"); - - // Has paragraphs - if ((pos = content.indexOf('
')) != -1) { - tinyMCE.execCommand("Delete"); - - var node = tinyMCE.selectedInstance.getFocusElement(); - - // Get list of elements to break - var breakElms = new Array(); - - do { - if (node.nodeType == 1) { - // Don't break tables and break at body - if (node.nodeName == "TD" || node.nodeName == "BODY") - break; - - breakElms[breakElms.length] = node; - } - } while(node = node.parentNode); - - var before = "", after = "
"; - before += content.substring(0, pos); - - for (var i=0; i";
- content = before + content.substring(pos+7) + after;
- }
- }
-
- content = tinyMCE.regexpReplace(content, "\r\n", "
", "gi");
- content = tinyMCE.regexpReplace(content, "\r", "
", "gi");
- content = tinyMCE.regexpReplace(content, "\n", "
", "gi");
- }
-
- tinyMCE.execCommand("mceInsertRawHTML", false, content);
- }
-}
-
-function TinyMCE_paste__insertWordContent(content) {
- if (content && content.length > 0) {
- // Cleanup Word content
- var bull = String.fromCharCode(8226);
- var middot = String.fromCharCode(183);
-
- if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) {
- content = content.replace(new RegExp('
(.*?)<\/p>', 'gi'), '
$1
'); - } - - content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--"); - content = content.replace(new RegExp(bull + "(.*?)" + middot + "$1
"); - content = content.replace(new RegExp('', 'gi'), "" + bull); // Covert to bull list - content = content.replace(/<\/p>/gi, ""); // Remove pagebreaks - content = content.replace(/-- page break --/gi, ""); // Remove pagebreaks - -// content = content.replace(/\/? */gi, ""); -// content = content.replace(/
<\/p>/gi, ''); - - if (!tinyMCE.settings['force_p_newlines']) { - content = content.replace('', '' ,'gi'); - content = content.replace('
', ''); - content = content.replace(/
'); - content = content.replace(/<\/h[1-6]>/gi, '
'); - content = content.replace(/ <\/b>/gi, ' '); - content = content.replace(/^( )*/gi, ''); - } - - content = content.replace(/--list--/gi, ""); // Remove --list-- - - // Insert cleaned content - tinyMCE.execCommand("mceInsertContent", false, content); - tinyMCE.execCommand("mceCleanup"); // Do normal cleanup - } -} - -function TinyMCE_paste_convertMiddots(div, search, class_name) { - var mdot = String.fromCharCode(183); - var bull = String.fromCharCode(8226); - - var nodes = div.getElementsByTagName("p"); - for (var i=0; i' + dom.encode(textContent).replace(/\r?\n\r?\n/g, '
').replace(/\r?\n/g, '
') + '
]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "
$1
"); + } + + if (getParam(ed, "paste_convert_middot_lists")) { + process([ + [//gi, '$&__MCE_ITEM__'], // Convert supportLists to a list item marker + [/(]+(?:mso-list:|:\s*symbol)[^>]+>)/gi, '$1__MCE_ITEM__'], // Convert mso-list and symbol spans to item markers + [/(]+(?:MsoListParagraph)[^>]+>)/gi, '$1__MCE_ITEM__'] // Convert mso-list and symbol paragraphs to item markers (FF)
+ ]);
+ }
+
+ process([
+ // Word comments like conditional comments etc
+ //gi,
+
+ // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags
+ /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
+
+ // Convert "],
+ [/<\/h[1-6][^>]*>/gi, " into for line-though
+ [/<(\/?)s>/gi, "<$1strike>"],
+
+ // Replace nsbp entites to char since it's easier to handle
+ [/ /gi, "\u00a0"]
+ ]);
+
+ // Remove bad attributes, with or without quotes, ensuring that attribute text is really inside a tag.
+ // If JavaScript had a RegExp look-behind, we could have integrated this with the last process() array and got rid of the loop. But alas, it does not, so we cannot.
+ do {
+ len = h.length;
+ h = h.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1");
+ } while (len != h.length);
+
+ // Remove all spans if no styles is to be retained
+ if (getParam(ed, "paste_retain_style_properties").replace(/^none$/i, "").length == 0) {
+ h = h.replace(/<\/?span[^>]*>/gi, "");
+ } else {
+ // We're keeping styles, so at least clean them up.
+ // CSS Reference: http://msdn.microsoft.com/en-us/library/aa155477.aspx
+
+ process([
+ // Convert ___ to string of alternating breaking/non-breaking spaces of same length
+ [/([\s\u00a0]*)<\/span>/gi,
+ function(str, spaces) {
+ return (spaces.length > 0)? spaces.replace(/./, " ").slice(Math.floor(spaces.length/2)).split("").join("\u00a0") : "";
+ }
+ ],
+
+ // Examine all styles: delete junk, transform some, and keep the rest
+ [/(<[a-z][^>]*)\sstyle="([^"]*)"/gi,
+ function(str, tag, style) {
+ var n = [],
+ i = 0,
+ s = explode(trim(style).replace(/"/gi, "'"), ";");
+
+ // Examine each style definition within the tag's style attribute
+ each(s, function(v) {
+ var name, value,
+ parts = explode(v, ":");
+
+ function ensureUnits(v) {
+ return v + ((v !== "0") && (/\d$/.test(v)))? "px" : "";
+ }
+
+ if (parts.length == 2) {
+ name = parts[0].toLowerCase();
+ value = parts[1].toLowerCase();
+
+ // Translate certain MS Office styles into their CSS equivalents
+ switch (name) {
+ case "mso-padding-alt":
+ case "mso-padding-top-alt":
+ case "mso-padding-right-alt":
+ case "mso-padding-bottom-alt":
+ case "mso-padding-left-alt":
+ case "mso-margin-alt":
+ case "mso-margin-top-alt":
+ case "mso-margin-right-alt":
+ case "mso-margin-bottom-alt":
+ case "mso-margin-left-alt":
+ case "mso-table-layout-alt":
+ case "mso-height":
+ case "mso-width":
+ case "mso-vertical-align-alt":
+ n[i++] = name.replace(/^mso-|-alt$/g, "") + ":" + ensureUnits(value);
+ return;
+
+ case "horiz-align":
+ n[i++] = "text-align:" + value;
+ return;
+
+ case "vert-align":
+ n[i++] = "vertical-align:" + value;
+ return;
+
+ case "font-color":
+ case "mso-foreground":
+ n[i++] = "color:" + value;
+ return;
+
+ case "mso-background":
+ case "mso-highlight":
+ n[i++] = "background:" + value;
+ return;
+
+ case "mso-default-height":
+ n[i++] = "min-height:" + ensureUnits(value);
+ return;
+
+ case "mso-default-width":
+ n[i++] = "min-width:" + ensureUnits(value);
+ return;
+
+ case "mso-padding-between-alt":
+ n[i++] = "border-collapse:separate;border-spacing:" + ensureUnits(value);
+ return;
+
+ case "text-line-through":
+ if ((value == "single") || (value == "double")) {
+ n[i++] = "text-decoration:line-through";
+ }
+ return;
+
+ case "mso-zero-height":
+ if (value == "yes") {
+ n[i++] = "display:none";
+ }
+ return;
+ }
+
+ // Eliminate all MS Office style definitions that have no CSS equivalent by examining the first characters in the name
+ if (/^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?!align|decor|indent|trans)|top-bar|version|vnd|word-break)/.test(name)) {
+ return;
+ }
+
+ // If it reached this point, it must be a valid CSS style
+ n[i++] = name + ":" + parts[1]; // Lower-case name, but keep value case
+ }
+ });
+
+ // If style attribute contained any valid styles the re-write it; otherwise delete style attribute.
+ if (i > 0) {
+ return tag + ' style="' + n.join(';') + '"';
+ } else {
+ return tag;
+ }
+ }
+ ]
+ ]);
+ }
+ }
+
+ // Replace headers with
+ if (getParam(ed, "paste_convert_headers_to_strong")) {
+ process([
+ [/
]*>|<\/tr>/gi, "\n"], // Single linebreak for
tags and table rows
+ [/<\/t[dh]>\s*
"]
+ ]);
+ } else {
+ process([
+ [/\n\n/g, "
"], + [/^(.*<\/p>)(
)$/, '
$1'],
+ [/\n/g, "
"]
+ ]);
+ }
+
+ ed.execCommand('mceInsertContent', false, content);
+ }
+ },
+
+ /**
+ * This method will open the old style paste dialogs. Some users might want the old behavior but still use the new cleanup engine.
+ */
+ _legacySupport : function() {
+ var t = this, ed = t.editor;
+
+ // Register command(s) for backwards compatibility
+ ed.addCommand("mcePasteWord", function() {
+ ed.windowManager.open({
+ file: t.url + "/pasteword.htm",
+ width: parseInt(getParam(ed, "paste_dialog_width")),
+ height: parseInt(getParam(ed, "paste_dialog_height")),
+ inline: 1
+ });
+ });
+
+ if (getParam(ed, "paste_text_use_dialog")) {
+ ed.addCommand("mcePasteText", function() {
+ ed.windowManager.open({
+ file : t.url + "/pastetext.htm",
+ width: parseInt(getParam(ed, "paste_dialog_width")),
+ height: parseInt(getParam(ed, "paste_dialog_height")),
+ inline : 1
+ });
+ });
+ }
+
+ // Register button for backwards compatibility
+ ed.addButton("pasteword", {title : "paste.paste_word_desc", cmd : "mcePasteWord"});
+ }
+ });
+
+ // Register plugin
+ tinymce.PluginManager.add("paste", tinymce.plugins.PastePlugin);
+})();