diff -r c72b545f1304 -r 67bd3121a12e includes/clientside/tinymce/plugins/paste/editor_plugin_src.js --- a/includes/clientside/tinymce/plugins/paste/editor_plugin_src.js Wed Dec 26 00:37:26 2007 -0500 +++ b/includes/clientside/tinymce/plugins/paste/editor_plugin_src.js Thu Dec 27 22:09:33 2007 -0500 @@ -1,395 +1,382 @@ /** - * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ + * $Id: editor_plugin_src.js 432 2007-11-23 16:07:16Z spocke $ * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. */ -/* Import plugin specific language pack */ -tinyMCE.importPluginLanguagePack('paste'); - -var TinyMCE_PastePlugin = { - getInfo : function() { - return { - longname : 'Paste text/word', - author : 'Moxiecode Systems AB', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; - }, - - initInstance : function(inst) { - if (tinyMCE.isMSIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false)) - tinyMCE.addEvent(inst.getBody(), "paste", TinyMCE_PastePlugin._handlePasteEvent); - }, +(function() { + var Event = tinymce.dom.Event; - handleEvent : function(e) { - // Force paste dialog if non IE browser - if (!tinyMCE.isRealIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false) && e.ctrlKey && e.keyCode == 86 && e.type == "keydown") { - window.setTimeout('tinyMCE.selectedInstance.execCommand("mcePasteText",true)', 1); - return tinyMCE.cancelEvent(e); - } - - return true; - }, + tinymce.create('tinymce.plugins.PastePlugin', { + init : function(ed, url) { + var t = this; - getControlHTML : function(cn) { - switch (cn) { - case "pastetext": - return tinyMCE.getButtonHTML(cn, 'lang_paste_text_desc', '{$pluginurl}/images/pastetext.gif', 'mcePasteText', true); - - case "pasteword": - return tinyMCE.getButtonHTML(cn, 'lang_paste_word_desc', '{$pluginurl}/images/pasteword.gif', 'mcePasteWord', true); - - case "selectall": - return tinyMCE.getButtonHTML(cn, 'lang_selectall_desc', '{$pluginurl}/images/selectall.gif', 'mceSelectAll', true); - } - - return ''; - }, + t.editor = ed; - execCommand : function(editor_id, element, command, user_interface, value) { - switch (command) { - case "mcePasteText": - if (user_interface) { - if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false)) - TinyMCE_PastePlugin._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'}); - } + // Register commands + ed.addCommand('mcePasteText', function(ui, v) { + if (ui) { + ed.windowManager.open({ + file : url + '/pastetext.htm', + width : 450, + height : 400, + inline : 1 + }, { + plugin_url : url + }); } else - TinyMCE_PastePlugin._insertText(value['html'], value['linebreaks']); - - return true; - - case "mcePasteWord": - if (user_interface) { - if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false)) { - TinyMCE_PastePlugin._insertWordContent(TinyMCE_PastePlugin._clipboardHTML()); - } 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_PastePlugin._insertWordContent(value); - - return true; - - case "mceSelectAll": - tinyMCE.execInstanceCommand(editor_id, 'selectall'); - return true; - - } - - // Pass to next handler in chain - return false; - }, - - // Private plugin internal methods + t._insertText(v.html, v.linebreaks); + }); - _handlePasteEvent : function(e) { - switch (e.type) { - case "paste": - var html = TinyMCE_PastePlugin._clipboardHTML(); - var r, inst = tinyMCE.selectedInstance; - - // Removes italic, strong etc, the if was needed due to bug #1437114 - if (inst && (r = inst.getRng()) && r.text.length > 0) - tinyMCE.execCommand('delete'); - - if (html && html.length > 0) - tinyMCE.execCommand('mcePasteWord', false, html); - - tinyMCE.cancelEvent(e); - return false; - } - - return true; - }, - - _insertText : function(content, bLinebreaks) { - if (content && content.length > 0) { - if (bLinebreaks) { - // Special paragraph treatment - if (tinyMCE.getParam("paste_create_paragraphs", true)) { - var rl = tinyMCE.getParam("paste_replace_list", '\u2122,TM,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); - for (var i=0; i

", "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(); + ed.addCommand('mcePasteWord', function(ui, v) { + if (ui) { + ed.windowManager.open({ + file : url + '/pasteword.htm', + width : 450, + height : 400, + inline : 1 + }, { + plugin_url : url + }); + } else + t._insertWordContent(v); + }); - 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"; - after += "<" + breakElms[(breakElms.length-1)-i].nodeName + ">"; - } - - before += "

"; - content = before + content.substring(pos+7) + after; - } - } + ed.addCommand('mceSelectAll', function() { + ed.execCommand('selectall'); + }); - if (tinyMCE.getParam("paste_create_linebreaks", true)) { - content = tinyMCE.regexpReplace(content, "\r\n", "
", "gi"); - content = tinyMCE.regexpReplace(content, "\r", "
", "gi"); - content = tinyMCE.regexpReplace(content, "\n", "
", "gi"); - } - } - - tinyMCE.execCommand("mceInsertRawHTML", false, content); - } - }, + // Register buttons + ed.addButton('pastetext', {title : 'paste.paste_text_desc', cmd : 'mcePasteText', ui : true}); + ed.addButton('pasteword', {title : 'paste.paste_word_desc', cmd : 'mcePasteWord', ui : true}); + ed.addButton('selectall', {title : 'paste.selectall_desc', cmd : 'mceSelectAll'}); - _insertWordContent : function(content) { - if (content && content.length > 0) { - // Cleanup Word content - var bull = String.fromCharCode(8226); - var middot = String.fromCharCode(183); - var cb; - - if ((cb = tinyMCE.getParam("paste_insert_word_content_callback", "")) != "") - content = eval(cb + "('before', content)"); - - var rl = tinyMCE.getParam("paste_replace_list", '\u2122,TM,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); - for (var i=0; i(.*?)<\/p>', 'gi'), '

$1

'); + if (ed.getParam("paste_auto_cleanup_on_paste", false)) { + ed.onPaste.add(function(ed, e) { + return t._handlePasteEvent(e) + }); } - content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--"); - content = content.replace(new RegExp(bull + "(.*?)
", "gi"), "

" + middot + "$1

"); - content = content.replace(new RegExp('', 'gi'), "" + bull); // Covert to bull list - content = content.replace(/<\/o:p>/gi, ""); - content = content.replace(new RegExp('
]*>/gi, ""); + _handlePasteEvent : function(e) { + var html = this._clipboardHTML(), ed = this.editor, sel = ed.selection, r; + + // Removes italic, strong etc, the if was needed due to bug #1437114 + if (ed && (r = sel.getRng()) && r.text.length > 0) + ed.execCommand('delete'); + + if (html && html.length > 0) + ed.execCommand('mcePasteWord', false, html); + + return Event.cancel(e); + }, - if (tinyMCE.getParam("paste_remove_styles", true)) - content = content.replace(new RegExp('<(\\w[^>]*) style="([^"]*)"([^>]*)', 'gi'), "<$1$3"); + _insertText : function(content, bLinebreaks) { + if (content && content.length > 0) { + if (bLinebreaks) { + // Special paragraph treatment + if (this.editor.getParam("paste_create_paragraphs", true)) { + var rl = this.editor.getParam("paste_replace_list", '\u2122,TM,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); + for (var i=0; i]*>/gi, ""); + content = content.replace(/\r\n\r\n/g, '

'); + content = content.replace(/\r\r/g, '

'); + content = content.replace(/\n\n/g, '

'); - // Strips class attributes. - switch (tinyMCE.getParam("paste_strip_class_attributes", "all")) { - case "all": - content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3"); - break; + // Has paragraphs + if ((pos = content.indexOf('

')) != -1) { + this.editor.execCommand("Delete"); + + var node = this.editor.selection.getNode(); + + // Get list of elements to break + var breakElms = []; + + 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); - case "mso": - content = content.replace(new RegExp('<(\\w[^>]*) class="?mso([^ |>]*)([^>]*)', 'gi'), "<$1$3"); - break; - } + for (var i=0; i"; + after += "<" + breakElms[(breakElms.length-1)-i].nodeName + ">"; + } + + before += "

"; + content = before + content.substring(pos+7) + after; + } + } - content = content.replace(new RegExp('href="?' + TinyMCE_PastePlugin._reEscape("" + document.location) + '', 'gi'), 'href="' + tinyMCE.settings['document_base_url']); - content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3"); - content = content.replace(/<\\?\?xml[^>]*>/gi, ""); - content = content.replace(/<\/?\w+:[^>]*>/gi, ""); - content = content.replace(/-- page break --\s*

 <\/p>/gi, ""); // Remove pagebreaks - content = content.replace(/-- page break --/gi, ""); // Remove pagebreaks + if (this.editor.getParam("paste_create_linebreaks", true)) { + content = content.replace(/\r\n/g, '
'); + content = content.replace(/\r/g, '
'); + content = content.replace(/\n/g, '
'); + } + } + + this.editor.execCommand("mceInsertRawHTML", false, content); + } + }, + + _insertWordContent : function(content) { + if (content && content.length > 0) { + // Cleanup Word content + var bull = String.fromCharCode(8226); + var middot = String.fromCharCode(183); + var cb; + + if ((cb = this.editor.getParam("paste_insert_word_content_callback", "")) != "") + content = eval(cb + "('before', content)"); - // content = content.replace(/\/? */gi, "");   - // content = content.replace(/

 <\/p>/gi, ''); + var rl = this.editor.getParam("paste_replace_list", '\u2122,TM,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(','); + for (var i=0; i(.*?)<\/p>', 'gi'), '

$1

'); + } + + content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--"); + content = content.replace(new RegExp(bull + "(.*?)
", "gi"), "

" + middot + "$1

"); + content = content.replace(new RegExp('', 'gi'), "" + bull); // Covert to bull list + content = content.replace(/<\/o:p>/gi, ""); + content = content.replace(new RegExp('
]*>/gi, ""); + + if (this.editor.getParam("paste_remove_styles", true)) + content = content.replace(new RegExp('<(\\w[^>]*) style="([^"]*)"([^>]*)', 'gi'), "<$1$3"); + + content = content.replace(/<\/?font[^>]*>/gi, ""); - if (!tinyMCE.settings['force_p_newlines']) { - content = content.replace('', '' ,'gi'); - content = content.replace('

', '

' ,'gi'); - } + // Strips class attributes. + switch (this.editor.getParam("paste_strip_class_attributes", "all")) { + case "all": + content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3"); + break; + + case "mso": + content = content.replace(new RegExp('<(\\w[^>]*) class="?mso([^ |>]*)([^>]*)', 'gi'), "<$1$3"); + break; + } - if (!tinyMCE.isMSIE && !tinyMCE.settings['force_p_newlines']) { - content = content.replace(/<\/?p[^>]*>/gi, ""); - } + content = content.replace(new RegExp('href="?' + this._reEscape("" + document.location) + '', 'gi'), 'href="' + this.editor.documentBaseURI.getURI()); + content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3"); + content = content.replace(/<\\?\?xml[^>]*>/gi, ""); + content = content.replace(/<\/?\w+:[^>]*>/gi, ""); + content = content.replace(/-- page break --\s*

 <\/p>/gi, ""); // Remove pagebreaks + content = content.replace(/-- page break --/gi, ""); // Remove pagebreaks - content = content.replace(/<\/?div[^>]*>/gi, ""); + // content = content.replace(/\/? */gi, "");   + // content = content.replace(/

 <\/p>/gi, ''); + + if (!this.editor.getParam('force_p_newlines')) { + content = content.replace('', '' ,'gi'); + content = content.replace('

', '

' ,'gi'); + } + + if (!tinymce.isIE && !this.editor.getParam('force_p_newlines')) { + content = content.replace(/<\/?p[^>]*>/gi, ""); + } - // Convert all middlot lists to UL lists - if (tinyMCE.getParam("paste_convert_middot_lists", true)) { - var div = document.createElement("div"); - div.innerHTML = content; + content = content.replace(/<\/?div[^>]*>/gi, ""); + + // Convert all middlot lists to UL lists + if (this.editor.getParam("paste_convert_middot_lists", true)) { + var div = document.createElement("div"); + div.innerHTML = content; + + // Convert all middot paragraphs to li elements + var className = this.editor.getParam("paste_unindented_list_class", "unIndentedList"); + + while (this._convertMiddots(div, "--list--")) ; // bull + while (this._convertMiddots(div, middot, className)) ; // Middot + while (this._convertMiddots(div, bull)) ; // bull - // Convert all middot paragraphs to li elements - var className = tinyMCE.getParam("paste_unindented_list_class", "unIndentedList"); + content = div.innerHTML; + } + + // Replace all headers with strong and fix some other issues + if (this.editor.getParam("paste_convert_headers_to_strong", false)) { + content = content.replace(/ <\/h[1-6]>/gi, '

  

'); + content = content.replace(//gi, '

'); + content = content.replace(/<\/h[1-6]>/gi, '

'); + content = content.replace(/ <\/b>/gi, '  '); + content = content.replace(/^( )*/gi, ''); + } + + content = content.replace(/--list--/gi, ""); // Remove --list-- - while (TinyMCE_PastePlugin._convertMiddots(div, "--list--")) ; // bull - while (TinyMCE_PastePlugin._convertMiddots(div, middot, className)) ; // Middot - while (TinyMCE_PastePlugin._convertMiddots(div, bull)) ; // bull + if ((cb = this.editor.getParam("paste_insert_word_content_callback", "")) != "") + content = eval(cb + "('after', content)"); - content = div.innerHTML; - } + // Insert cleaned content + this.editor.execCommand("mceInsertContent", false, content); + + if (this.editor.getParam('paste_force_cleanup_wordpaste', true)) { + var ed = this.editor; - // Replace all headers with strong and fix some other issues - if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) { - content = content.replace(/ <\/h[1-6]>/gi, '

  

'); - content = content.replace(//gi, '

'); - content = content.replace(/<\/h[1-6]>/gi, '

'); - content = content.replace(/ <\/b>/gi, '  '); - content = content.replace(/^( )*/gi, ''); + window.setTimeout(function() { + ed.execCommand("mceCleanup"); + }, 1); // Do normal cleanup detached from this thread + } + } + }, + + _reEscape : function(s) { + var l = "?.\\*[](){}+^$:"; + var o = ""; + + for (var i=0; i