Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / paste / editor_plugin_src.js
index a4e5d7013bc605fc2734e87fd9a2e1e184a615c6..1d9d3b42e7ca3070541f01a117d15141c86afcda 100644 (file)
-/* Import plugin specific language pack */ \r
-tinyMCE.importPluginLanguagePack('paste', 'en,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');\r
-\r
-function TinyMCE_paste_getInfo() {\r
-       return {\r
-               longname : 'Paste text/word',\r
-               author : 'Moxiecode Systems',\r
-               authorurl : 'http://tinymce.moxiecode.com',\r
-               infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_paste.html',\r
-               version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
-       };\r
-};\r
-\r
-function TinyMCE_paste_initInstance(inst) {\r
-       if (tinyMCE.isMSIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false))\r
-               tinyMCE.addEvent(inst.getBody(), "paste", TinyMCE_paste_handleEvent);\r
-}\r
-\r
-function TinyMCE_paste_handleEvent(e) {\r
-       switch (e.type) {\r
-               case "paste":\r
-                       var html = TinyMCE_paste__clipboardHTML();\r
-\r
-                       // Removes italic, strong etc\r
-                       tinyMCE.execCommand('delete');\r
-\r
-                       if (html && html.length > 0)\r
-                               tinyMCE.execCommand('mcePasteWord', false, html);\r
-\r
-                       tinyMCE.cancelEvent(e);\r
-                       return false;\r
+/**\r
+ * editor_plugin_src.js\r
+ *\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
+ *\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
+ */\r
+\r
+(function() {\r
+       var each = tinymce.each,\r
+               defs = {\r
+                       paste_auto_cleanup_on_paste : true,\r
+                       paste_enable_default_filters : true,\r
+                       paste_block_drop : false,\r
+                       paste_retain_style_properties : "none",\r
+                       paste_strip_class_attributes : "mso",\r
+                       paste_remove_spans : false,\r
+                       paste_remove_styles : false,\r
+                       paste_remove_styles_if_webkit : true,\r
+                       paste_convert_middot_lists : true,\r
+                       paste_convert_headers_to_strong : false,\r
+                       paste_dialog_width : "450",\r
+                       paste_dialog_height : "400",\r
+                       paste_text_use_dialog : false,\r
+                       paste_text_sticky : false,\r
+                       paste_text_sticky_default : false,\r
+                       paste_text_notifyalways : false,\r
+                       paste_text_linebreaktype : "p",\r
+                       paste_text_replacements : [\r
+                               [/\u2026/g, "..."],\r
+                               [/[\x93\x94\u201c\u201d]/g, '"'],\r
+                               [/[\x60\x91\x92\u2018\u2019]/g, "'"]\r
+                       ]\r
+               };\r
+\r
+       function getParam(ed, name) {\r
+               return ed.getParam(name, defs[name]);\r
        }\r
 \r
-       return true;\r
-}\r
-\r
-function TinyMCE_paste_getControlHTML(control_name) { \r
-       switch (control_name) { \r
-               case "pastetext":\r
-                       var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcePasteText\', true);return false;';\r
-                       return '<a href="javascript:' + cmd + '" onclick="' + cmd + '" target="_self" onmousedown="return false;"><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.restoreClass(this);" /></a>'; \r
-\r
-               case "pasteword":\r
-                       var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcePasteWord\', true);return false;';\r
-                       return '<a href="javascript:' + cmd + '" onclick="' + cmd + '" target="_self" onmousedown="return false;"><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.restoreClass(this);" /></a>'; \r
-\r
-               case "selectall":\r
-                       var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSelectAll\');return false;';\r
-                       return '<a href="javascript:' + cmd + '" onclick="' + cmd + '" target="_self" onmousedown="return false;"><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.restoreClass(this);" /></a>'; \r
-       } \r
-\r
-       return ''; \r
-} \r
-\r
-function TinyMCE_paste_execCommand(editor_id, element, command, user_interface, value) { \r
-       switch (command) { \r
-               case "mcePasteText": \r
-                       if (user_interface) {\r
-                               if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false))\r
-                                       TinyMCE_paste__insertText(clipboardData.getData("Text"), true); \r
-                               else { \r
-                                       var template = new Array(); \r
-                                       template['file']        = '../../plugins/paste/pastetext.htm'; // Relative to theme \r
-                                       template['width']  = 450; \r
-                                       template['height'] = 400; \r
-                                       var plain_text = ""; \r
-                                       tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'}); \r
+       tinymce.create('tinymce.plugins.PastePlugin', {\r
+               init : function(ed, url) {\r
+                       var t = this;\r
+\r
+                       t.editor = ed;\r
+                       t.url = url;\r
+\r
+                       // Setup plugin events\r
+                       t.onPreProcess = new tinymce.util.Dispatcher(t);\r
+                       t.onPostProcess = new tinymce.util.Dispatcher(t);\r
+\r
+                       // Register default handlers\r
+                       t.onPreProcess.add(t._preProcess);\r
+                       t.onPostProcess.add(t._postProcess);\r
+\r
+                       // Register optional preprocess handler\r
+                       t.onPreProcess.add(function(pl, o) {\r
+                               ed.execCallback('paste_preprocess', pl, o);\r
+                       });\r
+\r
+                       // Register optional postprocess\r
+                       t.onPostProcess.add(function(pl, o) {\r
+                               ed.execCallback('paste_postprocess', pl, o);\r
+                       });\r
+\r
+                       ed.onKeyDown.addToTop(function(ed, e) {\r
+                               // Block ctrl+v from adding an undo level since the default logic in tinymce.Editor will add that\r
+                               if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))\r
+                                       return false; // Stop other listeners\r
+                       });\r
+\r
+                       // Initialize plain text flag\r
+                       ed.pasteAsPlainText = getParam(ed, 'paste_text_sticky_default');\r
+\r
+                       // This function executes the process handlers and inserts the contents\r
+                       // force_rich overrides plain text mode set by user, important for pasting with execCommand\r
+                       function process(o, force_rich) {\r
+                               var dom = ed.dom, rng;\r
+\r
+                               // Execute pre process handlers\r
+                               t.onPreProcess.dispatch(t, o);\r
+\r
+                               // Create DOM structure\r
+                               o.node = dom.create('div', 0, o.content);\r
+\r
+                               // If pasting inside the same element and the contents is only one block\r
+                               // remove the block and keep the text since Firefox will copy parts of pre and h1-h6 as a pre element\r
+                               if (tinymce.isGecko) {\r
+                                       rng = ed.selection.getRng(true);\r
+                                       if (rng.startContainer == rng.endContainer && rng.startContainer.nodeType == 3) {\r
+                                               // Is only one block node and it doesn't contain word stuff\r
+                                               if (o.node.childNodes.length === 1 && /^(p|h[1-6]|pre)$/i.test(o.node.firstChild.nodeName) && o.content.indexOf('__MCE_ITEM__') === -1)\r
+                                                       dom.remove(o.node.firstChild, true);\r
+                                       }\r
                                }\r
-                       } else\r
-                               TinyMCE_paste__insertText(value['html'], value['linebreaks']);\r
-\r
-                       return true;\r
-\r
-               case "mcePasteWord": \r
-                       if (user_interface) {\r
-                               if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && !tinyMCE.getParam('paste_use_dialog', false)) {\r
-                                       var html = TinyMCE_paste__clipboardHTML();\r
-\r
-                                       if (html && html.length > 0)\r
-                                               TinyMCE_paste__insertWordContent(html);\r
-                               } else { \r
-                                       var template = new Array(); \r
-                                       template['file']        = '../../plugins/paste/pasteword.htm'; // Relative to theme \r
-                                       template['width']  = 450; \r
-                                       template['height'] = 400; \r
-                                       var plain_text = ""; \r
-                                       tinyMCE.openWindow(template, {editor_id : editor_id, plain_text: plain_text, resizable : "yes", scrollbars : "no", inline : "yes", mceDo : 'insert'});\r
+\r
+                               // Execute post process handlers\r
+                               t.onPostProcess.dispatch(t, o);\r
+\r
+                               // Serialize content\r
+                               o.content = ed.serializer.serialize(o.node, {getInner : 1, forced_root_block : ''});\r
+\r
+                               // Plain text option active?\r
+                               if ((!force_rich) && (ed.pasteAsPlainText)) {\r
+                                       t._insertPlainText(o.content);\r
+\r
+                                       if (!getParam(ed, "paste_text_sticky")) {\r
+                                               ed.pasteAsPlainText = false;\r
+                                               ed.controlManager.setActive("pastetext", false);\r
+                                       }\r
+                               } else {\r
+                                       t._insert(o.content);\r
                                }\r
-                       } else\r
-                               TinyMCE_paste__insertWordContent(value);\r
-\r
-                       return true;\r
-\r
-               case "mceSelectAll":\r
-                       tinyMCE.execInstanceCommand(editor_id, 'selectall'); \r
-                       return true; \r
-\r
-       } \r
-\r
-       // Pass to next handler in chain \r
-       return false; \r
-} \r
-\r
-function TinyMCE_paste__insertText(content, bLinebreaks) { \r
-       if (content && content.length > 0) {\r
-               if (bLinebreaks) { \r
-                       // Special paragraph treatment \r
-                       if (tinyMCE.getParam("paste_create_paragraphs", true)) {\r
-                               var rl = tinyMCE.getParam("paste_replace_list", '\u2122,<sup>TM</sup>,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(',');\r
-                               for (var i=0; i<rl.length; i+=2)\r
-                                       content = content.replace(new RegExp(rl[i], 'gi'), rl[i+1]);\r
-\r
-                               content = tinyMCE.regexpReplace(content, "\r\n\r\n", "</p><p>", "gi"); \r
-                               content = tinyMCE.regexpReplace(content, "\r\r", "</p><p>", "gi"); \r
-                               content = tinyMCE.regexpReplace(content, "\n\n", "</p><p>", "gi"); \r
-\r
-                               // Has paragraphs \r
-                               if ((pos = content.indexOf('</p><p>')) != -1) { \r
-                                       tinyMCE.execCommand("Delete"); \r
-\r
-                                       var node = tinyMCE.selectedInstance.getFocusElement(); \r
-\r
-                                       // Get list of elements to break \r
-                                       var breakElms = new Array(); \r
-\r
-                                       do { \r
-                                               if (node.nodeType == 1) { \r
-                                                       // Don't break tables and break at body \r
-                                                       if (node.nodeName == "TD" || node.nodeName == "BODY") \r
-                                                               break; \r
-       \r
-                                                       breakElms[breakElms.length] = node; \r
-                                               } \r
-                                       } while(node = node.parentNode); \r
-\r
-                                       var before = "", after = "</p>"; \r
-                                       before += content.substring(0, pos); \r
-\r
-                                       for (var i=0; i<breakElms.length; i++) { \r
-                                               before += "</" + breakElms[i].nodeName + ">"; \r
-                                               after += "<" + breakElms[(breakElms.length-1)-i].nodeName + ">"; \r
-                                       } \r
-\r
-                                       before += "<p>"; \r
-                                       content = before + content.substring(pos+7) + after; \r
-                               } \r
-                       } \r
-\r
-                       if (tinyMCE.getParam("paste_create_linebreaks", true)) {\r
-                               content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi"); \r
-                               content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi"); \r
-                               content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi"); \r
                        }\r
-               } \r
-       \r
-               tinyMCE.execCommand("mceInsertRawHTML", false, content); \r
-       }\r
-}\r
 \r
-function TinyMCE_paste__insertWordContent(content) { \r
-       if (content && content.length > 0) {\r
-               // Cleanup Word content\r
-               var bull = String.fromCharCode(8226);\r
-               var middot = String.fromCharCode(183);\r
+                       // Add command for external usage\r
+                       ed.addCommand('mceInsertClipboardContent', function(u, o) {\r
+                               process(o, true);\r
+                       });\r
+\r
+                       if (!getParam(ed, "paste_text_use_dialog")) {\r
+                               ed.addCommand('mcePasteText', function(u, v) {\r
+                                       var cookie = tinymce.util.Cookie;\r
+\r
+                                       ed.pasteAsPlainText = !ed.pasteAsPlainText;\r
+                                       ed.controlManager.setActive('pastetext', ed.pasteAsPlainText);\r
+\r
+                                       if ((ed.pasteAsPlainText) && (!cookie.get("tinymcePasteText"))) {\r
+                                               if (getParam(ed, "paste_text_sticky")) {\r
+                                                       ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky'));\r
+                                               } else {\r
+                                                       ed.windowManager.alert(ed.translate('paste.plaintext_mode'));\r
+                                               }\r
+\r
+                                               if (!getParam(ed, "paste_text_notifyalways")) {\r
+                                                       cookie.set("tinymcePasteText", "1", new Date(new Date().getFullYear() + 1, 12, 31))\r
+                                               }\r
+                                       }\r
+                               });\r
+                       }\r
 \r
-               var rl = tinyMCE.getParam("paste_replace_list", '\u2122,<sup>TM</sup>,\u2026,...,\u201c|\u201d,",\u2019,\',\u2013|\u2014|\u2015|\u2212,-').split(',');\r
-               for (var i=0; i<rl.length; i+=2)\r
-                       content = content.replace(new RegExp(rl[i], 'gi'), rl[i+1]);\r
+                       ed.addButton('pastetext', {title: 'paste.paste_text_desc', cmd: 'mcePasteText'});\r
+                       ed.addButton('selectall', {title: 'paste.selectall_desc', cmd: 'selectall'});\r
 \r
-               if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) {\r
-                       content = content.replace(new RegExp('<p class=MsoHeading.*?>(.*?)<\/p>', 'gi'), '<p><b>$1</b></p>');\r
-               }\r
+                       // This function grabs the contents from the clipboard by adding a\r
+                       // hidden div and placing the caret inside it and after the browser paste\r
+                       // is done it grabs that contents and processes that\r
+                       function grabContent(e) {\r
+                               var n, or, rng, oldRng, sel = ed.selection, dom = ed.dom, body = ed.getBody(), posY, textContent;\r
 \r
-               content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--");\r
-               content = content.replace(new RegExp(bull + "(.*?)<BR>", "gi"), "<p>" + middot + "$1</p>");\r
-               content = content.replace(new RegExp('<SPAN style="mso-list: Ignore">', 'gi'), "<span>" + bull); // Covert to bull list\r
-               content = content.replace(/<o:p><\/o:p>/gi, "");\r
-               content = content.replace(new RegExp('<br style="page-break-before: always;.*>', 'gi'), '-- page break --'); // Replace pagebreaks\r
-               content = content.replace(new RegExp('<(!--)([^>]*)(--)>', 'g'), "");  // Word comments\r
-               content = content.replace(/<\/?span[^>]*>/gi, "");\r
-               content = content.replace(new RegExp('<(\\w[^>]*) style="([^"]*)"([^>]*)', 'gi'), "<$1$3");\r
-               content = content.replace(/<\/?font[^>]*>/gi, "");\r
-\r
-               // Strips class attributes.\r
-               switch (tinyMCE.getParam("paste_strip_class_attributes", "all")) {\r
-                       case "all":\r
-                               content = content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");\r
-                               break;\r
-\r
-                       case "mso":\r
-                               content = content.replace(new RegExp('<(\\w[^>]*) class="?mso([^ |>]*)([^>]*)', 'gi'), "<$1$3");\r
-                               break;\r
-               }\r
+                               // Check if browser supports direct plaintext access\r
+                               if (e.clipboardData || dom.doc.dataTransfer) {\r
+                                       textContent = (e.clipboardData || dom.doc.dataTransfer).getData('Text');\r
 \r
-               content = content.replace(new RegExp('href="?' + TinyMCE_paste__reEscape("" + document.location) + '', 'gi'), 'href="' + tinyMCE.settings['document_base_url']);\r
-               content = content.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");\r
-               content = content.replace(/<\\?\?xml[^>]*>/gi, "");\r
-               content = content.replace(/<\/?\w+:[^>]*>/gi, "");\r
-               content = content.replace(/-- page break --\s*<p>&nbsp;<\/p>/gi, ""); // Remove pagebreaks\r
-               content = content.replace(/-- page break --/gi, ""); // Remove pagebreaks\r
+                                       if (ed.pasteAsPlainText) {\r
+                                               e.preventDefault();\r
+                                               process({content : dom.encode(textContent).replace(/\r?\n/g, '<br />')});\r
+                                               return;\r
+                                       }\r
+                               }\r
 \r
-//             content = content.replace(/\/?&nbsp;*/gi, ""); &nbsp;\r
-//             content = content.replace(/<p>&nbsp;<\/p>/gi, '');\r
+                               if (dom.get('_mcePaste'))\r
+                                       return;\r
+\r
+                               // Create container to paste into\r
+                               n = dom.add(body, 'div', {id : '_mcePaste', 'class' : 'mcePaste', 'data-mce-bogus' : '1'}, '\uFEFF\uFEFF');\r
+\r
+                               // If contentEditable mode we need to find out the position of the closest element\r
+                               if (body != ed.getDoc().body)\r
+                                       posY = dom.getPos(ed.selection.getStart(), body).y;\r
+                               else\r
+                                       posY = body.scrollTop + dom.getViewPort(ed.getWin()).y;\r
+\r
+                               // Styles needs to be applied after the element is added to the document since WebKit will otherwise remove all styles\r
+                               // If also needs to be in view on IE or the paste would fail\r
+                               dom.setStyles(n, {\r
+                                       position : 'absolute',\r
+                                       left : tinymce.isGecko ? -40 : 0, // Need to move it out of site on Gecko since it will othewise display a ghost resize rect for the div\r
+                                       top : posY - 25,\r
+                                       width : 1,\r
+                                       height : 1,\r
+                                       overflow : 'hidden'\r
+                               });\r
+\r
+                               if (tinymce.isIE) {\r
+                                       // Store away the old range\r
+                                       oldRng = sel.getRng();\r
+\r
+                                       // Select the container\r
+                                       rng = dom.doc.body.createTextRange();\r
+                                       rng.moveToElementText(n);\r
+                                       rng.execCommand('Paste');\r
+\r
+                                       // Remove container\r
+                                       dom.remove(n);\r
+\r
+                                       // Check if the contents was changed, if it wasn't then clipboard extraction failed probably due\r
+                                       // to IE security settings so we pass the junk though better than nothing right\r
+                                       if (n.innerHTML === '\uFEFF\uFEFF') {\r
+                                               ed.execCommand('mcePasteWord');\r
+                                               e.preventDefault();\r
+                                               return;\r
+                                       }\r
+\r
+                                       // Restore the old range and clear the contents before pasting\r
+                                       sel.setRng(oldRng);\r
+                                       sel.setContent('');\r
+\r
+                                       // For some odd reason we need to detach the the mceInsertContent call from the paste event\r
+                                       // It's like IE has a reference to the parent element that you paste in and the selection gets messed up\r
+                                       // when it tries to restore the selection\r
+                                       setTimeout(function() {\r
+                                               // Process contents\r
+                                               process({content : n.innerHTML});\r
+                                       }, 0);\r
+\r
+                                       // Block the real paste event\r
+                                       return tinymce.dom.Event.cancel(e);\r
+                               } else {\r
+                                       function block(e) {\r
+                                               e.preventDefault();\r
+                                       };\r
+\r
+                                       // Block mousedown and click to prevent selection change\r
+                                       dom.bind(ed.getDoc(), 'mousedown', block);\r
+                                       dom.bind(ed.getDoc(), 'keydown', block);\r
+\r
+                                       or = ed.selection.getRng();\r
+\r
+                                       // Move select contents inside DIV\r
+                                       n = n.firstChild;\r
+                                       rng = ed.getDoc().createRange();\r
+                                       rng.setStart(n, 0);\r
+                                       rng.setEnd(n, 2);\r
+                                       sel.setRng(rng);\r
+\r
+                                       // Wait a while and grab the pasted contents\r
+                                       window.setTimeout(function() {\r
+                                               var h = '', nl;\r
+\r
+                                               // Paste divs duplicated in paste divs seems to happen when you paste plain text so lets first look for that broken behavior in WebKit\r
+                                               if (!dom.select('div.mcePaste > div.mcePaste').length) {\r
+                                                       nl = dom.select('div.mcePaste');\r
+\r
+                                                       // WebKit will split the div into multiple ones so this will loop through then all and join them to get the whole HTML string\r
+                                                       each(nl, function(n) {\r
+                                                               var child = n.firstChild;\r
+\r
+                                                               // WebKit inserts a DIV container with lots of odd styles\r
+                                                               if (child && child.nodeName == 'DIV' && child.style.marginTop && child.style.backgroundColor) {\r
+                                                                       dom.remove(child, 1);\r
+                                                               }\r
+\r
+                                                               // Remove apply style spans\r
+                                                               each(dom.select('span.Apple-style-span', n), function(n) {\r
+                                                                       dom.remove(n, 1);\r
+                                                               });\r
+\r
+                                                               // Remove bogus br elements\r
+                                                               each(dom.select('br[data-mce-bogus]', n), function(n) {\r
+                                                                       dom.remove(n);\r
+                                                               });\r
+\r
+                                                               // WebKit will make a copy of the DIV for each line of plain text pasted and insert them into the DIV\r
+                                                               if (n.parentNode.className != 'mcePaste')\r
+                                                                       h += n.innerHTML;\r
+                                                       });\r
+                                               } else {\r
+                                                       // Found WebKit weirdness so force the content into paragraphs this seems to happen when you paste plain text from Nodepad etc\r
+                                                       // So this logic will replace double enter with paragraphs and single enter with br so it kind of looks the same\r
+                                                       h = '<p>' + dom.encode(textContent).replace(/\r?\n\r?\n/g, '</p><p>').replace(/\r?\n/g, '<br />') + '</p>';\r
+                                               }\r
+\r
+                                               // Remove the nodes\r
+                                               each(dom.select('div.mcePaste'), function(n) {\r
+                                                       dom.remove(n);\r
+                                               });\r
+\r
+                                               // Restore the old selection\r
+                                               if (or)\r
+                                                       sel.setRng(or);\r
+\r
+                                               process({content : h});\r
+\r
+                                               // Unblock events ones we got the contents\r
+                                               dom.unbind(ed.getDoc(), 'mousedown', block);\r
+                                               dom.unbind(ed.getDoc(), 'keydown', block);\r
+                                       }, 0);\r
+                               }\r
+                       }\r
 \r
-               if (!tinyMCE.settings['force_p_newlines']) {\r
-                       content = content.replace('', '' ,'gi');\r
-                       content = content.replace('</p>', '<br /><br />' ,'gi');\r
-               }\r
+                       // Check if we should use the new auto process method                   \r
+                       if (getParam(ed, "paste_auto_cleanup_on_paste")) {\r
+                               // Is it's Opera or older FF use key handler\r
+                               if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) {\r
+                                       ed.onKeyDown.addToTop(function(ed, e) {\r
+                                               if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))\r
+                                                       grabContent(e);\r
+                                       });\r
+                               } else {\r
+                                       // Grab contents on paste event on Gecko and WebKit\r
+                                       ed.onPaste.addToTop(function(ed, e) {\r
+                                               return grabContent(e);\r
+                                       });\r
+                               }\r
+                       }\r
 \r
-               if (!tinyMCE.isMSIE && !tinyMCE.settings['force_p_newlines']) {\r
-                       content = content.replace(/<\/?p[^>]*>/gi, "");\r
-               }\r
+                       ed.onInit.add(function() {\r
+                               ed.controlManager.setActive("pastetext", ed.pasteAsPlainText);\r
 \r
-               content = content.replace(/<\/?div[^>]*>/gi, "");\r
+                               // Block all drag/drop events\r
+                               if (getParam(ed, "paste_block_drop")) {\r
+                                       ed.dom.bind(ed.getBody(), ['dragend', 'dragover', 'draggesture', 'dragdrop', 'drop', 'drag'], function(e) {\r
+                                               e.preventDefault();\r
+                                               e.stopPropagation();\r
 \r
-               // Convert all middlot lists to UL lists\r
-               if (tinyMCE.getParam("paste_convert_middot_lists", true)) {\r
-                       var div = document.createElement("div");\r
-                       div.innerHTML = content;\r
+                                               return false;\r
+                                       });\r
+                               }\r
+                       });\r
+\r
+                       // Add legacy support\r
+                       t._legacySupport();\r
+               },\r
+\r
+               getInfo : function() {\r
+                       return {\r
+                               longname : 'Paste text/word',\r
+                               author : 'Moxiecode Systems AB',\r
+                               authorurl : 'http://tinymce.moxiecode.com',\r
+                               infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste',\r
+                               version : tinymce.majorVersion + "." + tinymce.minorVersion\r
+                       };\r
+               },\r
+\r
+               _preProcess : function(pl, o) {\r
+                       var ed = this.editor,\r
+                               h = o.content,\r
+                               grep = tinymce.grep,\r
+                               explode = tinymce.explode,\r
+                               trim = tinymce.trim,\r
+                               len, stripClass;\r
+\r
+                       //console.log('Before preprocess:' + o.content);\r
+\r
+                       function process(items) {\r
+                               each(items, function(v) {\r
+                                       // Remove or replace\r
+                                       if (v.constructor == RegExp)\r
+                                               h = h.replace(v, '');\r
+                                       else\r
+                                               h = h.replace(v[0], v[1]);\r
+                               });\r
+                       }\r
+                       \r
+                       if (ed.settings.paste_enable_default_filters == false) {\r
+                               return;\r
+                       }\r
 \r
-                       // Convert all middot paragraphs to li elements\r
-                       var className = tinyMCE.getParam("paste_unindented_list_class", "unIndentedList");\r
+                       // IE9 adds BRs before/after block elements when contents is pasted from word or for example another browser\r
+                       if (tinymce.isIE && document.documentMode >= 9) {\r
+                               // IE9 adds BRs before/after block elements when contents is pasted from word or for example another browser\r
+                               process([[/(?:<br>&nbsp;[\s\r\n]+|<br>)*(<\/?(h[1-6r]|p|div|address|pre|form|table|tbody|thead|tfoot|th|tr|td|li|ol|ul|caption|blockquote|center|dl|dt|dd|dir|fieldset)[^>]*>)(?:<br>&nbsp;[\s\r\n]+|<br>)*/g, '$1']]);\r
+\r
+                               // IE9 also adds an extra BR element for each soft-linefeed and it also adds a BR for each word wrap break\r
+                               process([\r
+                                       [/<br><br>/g, '<BR><BR>'], // Replace multiple BR elements with uppercase BR to keep them intact\r
+                                       [/<br>/g, ' '], // Replace single br elements with space since they are word wrap BR:s\r
+                                       [/<BR><BR>/g, '<br>'] // Replace back the double brs but into a single BR\r
+                               ]);\r
+                       }\r
 \r
-                       while (TinyMCE_paste_convertMiddots(div, "--list--")) ; // bull\r
-                       while (TinyMCE_paste_convertMiddots(div, middot, className)) ; // Middot\r
-                       while (TinyMCE_paste_convertMiddots(div, bull)) ; // bull\r
+                       // Detect Word content and process it more aggressive\r
+                       if (/class="?Mso|style="[^"]*\bmso-|w:WordDocument/i.test(h) || o.wordContent) {\r
+                               o.wordContent = true;                   // Mark the pasted contents as word specific content\r
+                               //console.log('Word contents detected.');\r
 \r
-                       content = div.innerHTML;\r
-               }\r
+                               // Process away some basic content\r
+                               process([\r
+                                       /^\s*(&nbsp;)+/gi,                              // &nbsp; entities at the start of contents\r
+                                       /(&nbsp;|<br[^>]*>)+\s*$/gi             // &nbsp; entities at the end of contents\r
+                               ]);\r
 \r
-               // Replace all headers with strong and fix some other issues\r
-               if (tinyMCE.getParam("paste_convert_headers_to_strong", false)) {\r
-                       content = content.replace(/<h[1-6]>&nbsp;<\/h[1-6]>/gi, '<p>&nbsp;&nbsp;</p>');\r
-                       content = content.replace(/<h[1-6]>/gi, '<p><b>');\r
-                       content = content.replace(/<\/h[1-6]>/gi, '</b></p>');\r
-                       content = content.replace(/<b>&nbsp;<\/b>/gi, '<b>&nbsp;&nbsp;</b>');\r
-                       content = content.replace(/^(&nbsp;)*/gi, '');\r
-               }\r
+                               if (getParam(ed, "paste_convert_headers_to_strong")) {\r
+                                       h = h.replace(/<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>");\r
+                               }\r
 \r
-               content = content.replace(/--list--/gi, ""); // Remove --list--\r
+                               if (getParam(ed, "paste_convert_middot_lists")) {\r
+                                       process([\r
+                                               [/<!--\[if !supportLists\]-->/gi, '$&__MCE_ITEM__'],                                    // Convert supportLists to a list item marker\r
+                                               [/(<span[^>]+(?:mso-list:|:\s*symbol)[^>]+>)/gi, '$1__MCE_ITEM__'],             // Convert mso-list and symbol spans to item markers\r
+                                               [/(<p[^>]+(?:MsoListParagraph)[^>]+>)/gi, '$1__MCE_ITEM__']                             // Convert mso-list and symbol paragraphs to item markers (FF)\r
+                                       ]);\r
+                               }\r
 \r
-               // Insert cleaned content\r
-               tinyMCE.execCommand("mceInsertContent", false, content);\r
-               tinyMCE.execCommand("mceCleanup"); // Do normal cleanup\r
-       }\r
-}\r
+                               process([\r
+                                       // Word comments like conditional comments etc\r
+                                       /<!--[\s\S]+?-->/gi,\r
+\r
+                                       // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags\r
+                                       /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,\r
+\r
+                                       // Convert <s> into <strike> for line-though\r
+                                       [/<(\/?)s>/gi, "<$1strike>"],\r
+\r
+                                       // Replace nsbp entites to char since it's easier to handle\r
+                                       [/&nbsp;/gi, "\u00a0"]\r
+                               ]);\r
+\r
+                               // Remove bad attributes, with or without quotes, ensuring that attribute text is really inside a tag.\r
+                               // 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.\r
+                               do {\r
+                                       len = h.length;\r
+                                       h = h.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1");\r
+                               } while (len != h.length);\r
+\r
+                               // Remove all spans if no styles is to be retained\r
+                               if (getParam(ed, "paste_retain_style_properties").replace(/^none$/i, "").length == 0) {\r
+                                       h = h.replace(/<\/?span[^>]*>/gi, "");\r
+                               } else {\r
+                                       // We're keeping styles, so at least clean them up.\r
+                                       // CSS Reference: http://msdn.microsoft.com/en-us/library/aa155477.aspx\r
+\r
+                                       process([\r
+                                               // Convert <span style="mso-spacerun:yes">___</span> to string of alternating breaking/non-breaking spaces of same length\r
+                                               [/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,\r
+                                                       function(str, spaces) {\r
+                                                               return (spaces.length > 0)? spaces.replace(/./, " ").slice(Math.floor(spaces.length/2)).split("").join("\u00a0") : "";\r
+                                                       }\r
+                                               ],\r
+\r
+                                               // Examine all styles: delete junk, transform some, and keep the rest\r
+                                               [/(<[a-z][^>]*)\sstyle="([^"]*)"/gi,\r
+                                                       function(str, tag, style) {\r
+                                                               var n = [],\r
+                                                                       i = 0,\r
+                                                                       s = explode(trim(style).replace(/&quot;/gi, "'"), ";");\r
+\r
+                                                               // Examine each style definition within the tag's style attribute\r
+                                                               each(s, function(v) {\r
+                                                                       var name, value,\r
+                                                                               parts = explode(v, ":");\r
+\r
+                                                                       function ensureUnits(v) {\r
+                                                                               return v + ((v !== "0") && (/\d$/.test(v)))? "px" : "";\r
+                                                                       }\r
+\r
+                                                                       if (parts.length == 2) {\r
+                                                                               name = parts[0].toLowerCase();\r
+                                                                               value = parts[1].toLowerCase();\r
+\r
+                                                                               // Translate certain MS Office styles into their CSS equivalents\r
+                                                                               switch (name) {\r
+                                                                                       case "mso-padding-alt":\r
+                                                                                       case "mso-padding-top-alt":\r
+                                                                                       case "mso-padding-right-alt":\r
+                                                                                       case "mso-padding-bottom-alt":\r
+                                                                                       case "mso-padding-left-alt":\r
+                                                                                       case "mso-margin-alt":\r
+                                                                                       case "mso-margin-top-alt":\r
+                                                                                       case "mso-margin-right-alt":\r
+                                                                                       case "mso-margin-bottom-alt":\r
+                                                                                       case "mso-margin-left-alt":\r
+                                                                                       case "mso-table-layout-alt":\r
+                                                                                       case "mso-height":\r
+                                                                                       case "mso-width":\r
+                                                                                       case "mso-vertical-align-alt":\r
+                                                                                               n[i++] = name.replace(/^mso-|-alt$/g, "") + ":" + ensureUnits(value);\r
+                                                                                               return;\r
+\r
+                                                                                       case "horiz-align":\r
+                                                                                               n[i++] = "text-align:" + value;\r
+                                                                                               return;\r
+\r
+                                                                                       case "vert-align":\r
+                                                                                               n[i++] = "vertical-align:" + value;\r
+                                                                                               return;\r
+\r
+                                                                                       case "font-color":\r
+                                                                                       case "mso-foreground":\r
+                                                                                               n[i++] = "color:" + value;\r
+                                                                                               return;\r
+\r
+                                                                                       case "mso-background":\r
+                                                                                       case "mso-highlight":\r
+                                                                                               n[i++] = "background:" + value;\r
+                                                                                               return;\r
+\r
+                                                                                       case "mso-default-height":\r
+                                                                                               n[i++] = "min-height:" + ensureUnits(value);\r
+                                                                                               return;\r
+\r
+                                                                                       case "mso-default-width":\r
+                                                                                               n[i++] = "min-width:" + ensureUnits(value);\r
+                                                                                               return;\r
+\r
+                                                                                       case "mso-padding-between-alt":\r
+                                                                                               n[i++] = "border-collapse:separate;border-spacing:" + ensureUnits(value);\r
+                                                                                               return;\r
+\r
+                                                                                       case "text-line-through":\r
+                                                                                               if ((value == "single") || (value == "double")) {\r
+                                                                                                       n[i++] = "text-decoration:line-through";\r
+                                                                                               }\r
+                                                                                               return;\r
+\r
+                                                                                       case "mso-zero-height":\r
+                                                                                               if (value == "yes") {\r
+                                                                                                       n[i++] = "display:none";\r
+                                                                                               }\r
+                                                                                               return;\r
+                                                                               }\r
+\r
+                                                                               // Eliminate all MS Office style definitions that have no CSS equivalent by examining the first characters in the name\r
+                                                                               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)) {\r
+                                                                                       return;\r
+                                                                               }\r
+\r
+                                                                               // If it reached this point, it must be a valid CSS style\r
+                                                                               n[i++] = name + ":" + parts[1];         // Lower-case name, but keep value case\r
+                                                                       }\r
+                                                               });\r
+\r
+                                                               // If style attribute contained any valid styles the re-write it; otherwise delete style attribute.\r
+                                                               if (i > 0) {\r
+                                                                       return tag + ' style="' + n.join(';') + '"';\r
+                                                               } else {\r
+                                                                       return tag;\r
+                                                               }\r
+                                                       }\r
+                                               ]\r
+                                       ]);\r
+                               }\r
+                       }\r
 \r
-function TinyMCE_paste__reEscape(s) {\r
-       var l = "?.\\*[](){}+^$:";\r
-       var o = "";\r
+                       // Replace headers with <strong>\r
+                       if (getParam(ed, "paste_convert_headers_to_strong")) {\r
+                               process([\r
+                                       [/<h[1-6][^>]*>/gi, "<p><strong>"],\r
+                                       [/<\/h[1-6][^>]*>/gi, "</strong></p>"]\r
+                               ]);\r
+                       }\r
 \r
-       for (var i=0; i<s.length; i++) {\r
-               var c = s.charAt(i);\r
+                       process([\r
+                               // Copy paste from Java like Open Office will produce this junk on FF\r
+                               [/Version:[\d.]+\nStartHTML:\d+\nEndHTML:\d+\nStartFragment:\d+\nEndFragment:\d+/gi, '']\r
+                       ]);\r
 \r
-               if (l.indexOf(c) != -1)\r
-                       o += '\\' + c;\r
-               else\r
-                       o += c;\r
-       }\r
+                       // Class attribute options are: leave all as-is ("none"), remove all ("all"), or remove only those starting with mso ("mso").\r
+                       // Note:-  paste_strip_class_attributes: "none", verify_css_classes: true is also a good variation.\r
+                       stripClass = getParam(ed, "paste_strip_class_attributes");\r
+\r
+                       if (stripClass !== "none") {\r
+                               function removeClasses(match, g1) {\r
+                                               if (stripClass === "all")\r
+                                                       return '';\r
+\r
+                                               var cls = grep(explode(g1.replace(/^(["'])(.*)\1$/, "$2"), " "),\r
+                                                       function(v) {\r
+                                                               return (/^(?!mso)/i.test(v));\r
+                                                       }\r
+                                               );\r
 \r
-       return o;\r
-}\r
-\r
-function TinyMCE_paste_convertMiddots(div, search, class_name) {\r
-       var mdot = String.fromCharCode(183);\r
-       var bull = String.fromCharCode(8226);\r
-\r
-       var nodes = div.getElementsByTagName("p");\r
-       for (var i=0; i<nodes.length; i++) {\r
-               var p = nodes[i];\r
-\r
-               // Is middot\r
-               if (p.innerHTML.indexOf(search) != -1) {\r
-                       var ul = document.createElement("ul");\r
-\r
-                       if (class_name)\r
-                               ul.className = class_name;\r
-\r
-                       // Add the first one\r
-                       var li = document.createElement("li");\r
-                       li.innerHTML = p.innerHTML.replace(new RegExp('' + mdot + '|' + bull + '|--list--|&nbsp;', "gi"), '');\r
-                       ul.appendChild(li);\r
-\r
-                       // Add the rest\r
-                       var np = p.nextSibling;\r
-                       while (np) {\r
-                               // Not element or middot paragraph\r
-                               if (np.nodeType != 1 || np.innerHTML.indexOf(search) == -1)\r
-                                       break;\r
-\r
-                               var cp = np.nextSibling;\r
-                               var li = document.createElement("li");\r
-                               li.innerHTML = np.innerHTML.replace(new RegExp('' + mdot + '|' + bull + '|--list--|&nbsp;', "gi"), '');\r
-                               np.parentNode.removeChild(np);\r
-                               ul.appendChild(li);\r
-                               np = cp;\r
+                                               return cls.length ? ' class="' + cls.join(" ") + '"' : '';\r
+                               };\r
+\r
+                               h = h.replace(/ class="([^"]+)"/gi, removeClasses);\r
+                               h = h.replace(/ class=([\-\w]+)/gi, removeClasses);\r
                        }\r
 \r
-                       p.parentNode.replaceChild(ul, p);\r
+                       // Remove spans option\r
+                       if (getParam(ed, "paste_remove_spans")) {\r
+                               h = h.replace(/<\/?span[^>]*>/gi, "");\r
+                       }\r
 \r
-                       return true;\r
-               }\r
-       }\r
+                       //console.log('After preprocess:' + h);\r
 \r
-       return false;\r
-}\r
+                       o.content = h;\r
+               },\r
 \r
-function TinyMCE_paste__clipboardHTML() {\r
-       var div = document.getElementById('_TinyMCE_clipboardHTML');\r
+               /**\r
+                * Various post process items.\r
+                */\r
+               _postProcess : function(pl, o) {\r
+                       var t = this, ed = t.editor, dom = ed.dom, styleProps;\r
 \r
-       if (!div) {\r
-               var div = document.createElement('DIV');\r
-               div.id = '_TinyMCE_clipboardHTML';\r
+                       if (ed.settings.paste_enable_default_filters == false) {\r
+                               return;\r
+                       }\r
+                       \r
+                       if (o.wordContent) {\r
+                               // Remove named anchors or TOC links\r
+                               each(dom.select('a', o.node), function(a) {\r
+                                       if (!a.href || a.href.indexOf('#_Toc') != -1)\r
+                                               dom.remove(a, 1);\r
+                               });\r
+\r
+                               if (getParam(ed, "paste_convert_middot_lists")) {\r
+                                       t._convertLists(pl, o);\r
+                               }\r
 \r
-               with (div.style) {\r
-                       visibility = 'hidden';\r
-                       overflow = 'hidden';\r
-                       position = 'absolute';\r
-                       width = 1;\r
-                       height = 1;\r
-               }\r
+                               // Process styles\r
+                               styleProps = getParam(ed, "paste_retain_style_properties"); // retained properties\r
+\r
+                               // Process only if a string was specified and not equal to "all" or "*"\r
+                               if ((tinymce.is(styleProps, "string")) && (styleProps !== "all") && (styleProps !== "*")) {\r
+                                       styleProps = tinymce.explode(styleProps.replace(/^none$/i, ""));\r
+\r
+                                       // Retains some style properties\r
+                                       each(dom.select('*', o.node), function(el) {\r
+                                               var newStyle = {}, npc = 0, i, sp, sv;\r
+\r
+                                               // Store a subset of the existing styles\r
+                                               if (styleProps) {\r
+                                                       for (i = 0; i < styleProps.length; i++) {\r
+                                                               sp = styleProps[i];\r
+                                                               sv = dom.getStyle(el, sp);\r
+\r
+                                                               if (sv) {\r
+                                                                       newStyle[sp] = sv;\r
+                                                                       npc++;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+\r
+                                               // Remove all of the existing styles\r
+                                               dom.setAttrib(el, 'style', '');\r
+\r
+                                               if (styleProps && npc > 0)\r
+                                                       dom.setStyles(el, newStyle); // Add back the stored subset of styles\r
+                                               else // Remove empty span tags that do not have class attributes\r
+                                                       if (el.nodeName == 'SPAN' && !el.className)\r
+                                                               dom.remove(el, true);\r
+                                       });\r
+                               }\r
+                       }\r
 \r
-               document.body.appendChild(div);\r
-       }\r
+                       // Remove all style information or only specifically on WebKit to avoid the style bug on that browser\r
+                       if (getParam(ed, "paste_remove_styles") || (getParam(ed, "paste_remove_styles_if_webkit") && tinymce.isWebKit)) {\r
+                               each(dom.select('*[style]', o.node), function(el) {\r
+                                       el.removeAttribute('style');\r
+                                       el.removeAttribute('data-mce-style');\r
+                               });\r
+                       } else {\r
+                               if (tinymce.isWebKit) {\r
+                                       // We need to compress the styles on WebKit since if you paste <img border="0" /> it will become <img border="0" style="... lots of junk ..." />\r
+                                       // Removing the mce_style that contains the real value will force the Serializer engine to compress the styles\r
+                                       each(dom.select('*', o.node), function(el) {\r
+                                               el.removeAttribute('data-mce-style');\r
+                                       });\r
+                               }\r
+                       }\r
+               },\r
+\r
+               /**\r
+                * Converts the most common bullet and number formats in Office into a real semantic UL/LI list.\r
+                */\r
+               _convertLists : function(pl, o) {\r
+                       var dom = pl.editor.dom, listElm, li, lastMargin = -1, margin, levels = [], lastType, html;\r
+\r
+                       // Convert middot lists into real semantic lists\r
+                       each(dom.select('p', o.node), function(p) {\r
+                               var sib, val = '', type, html, idx, parents;\r
+\r
+                               // Get text node value at beginning of paragraph\r
+                               for (sib = p.firstChild; sib && sib.nodeType == 3; sib = sib.nextSibling)\r
+                                       val += sib.nodeValue;\r
+\r
+                               val = p.innerHTML.replace(/<\/?\w+[^>]*>/gi, '').replace(/&nbsp;/g, '\u00a0');\r
+\r
+                               // Detect unordered lists look for bullets\r
+                               if (/^(__MCE_ITEM__)+[\u2022\u00b7\u00a7\u00d8o\u25CF]\s*\u00a0*/.test(val))\r
+                                       type = 'ul';\r
+\r
+                               // Detect ordered lists 1., a. or ixv.\r
+                               if (/^__MCE_ITEM__\s*\w+\.\s*\u00a0+/.test(val))\r
+                                       type = 'ol';\r
+\r
+                               // Check if node value matches the list pattern: o&nbsp;&nbsp;\r
+                               if (type) {\r
+                                       margin = parseFloat(p.style.marginLeft || 0);\r
+\r
+                                       if (margin > lastMargin)\r
+                                               levels.push(margin);\r
+\r
+                                       if (!listElm || type != lastType) {\r
+                                               listElm = dom.create(type);\r
+                                               dom.insertAfter(listElm, p);\r
+                                       } else {\r
+                                               // Nested list element\r
+                                               if (margin > lastMargin) {\r
+                                                       listElm = li.appendChild(dom.create(type));\r
+                                               } else if (margin < lastMargin) {\r
+                                                       // Find parent level based on margin value\r
+                                                       idx = tinymce.inArray(levels, margin);\r
+                                                       parents = dom.getParents(listElm.parentNode, type);\r
+                                                       listElm = parents[parents.length - 1 - idx] || listElm;\r
+                                               }\r
+                                       }\r
+\r
+                                       // Remove middot or number spans if they exists\r
+                                       each(dom.select('span', p), function(span) {\r
+                                               var html = span.innerHTML.replace(/<\/?\w+[^>]*>/gi, '');\r
+\r
+                                               // Remove span with the middot or the number\r
+                                               if (type == 'ul' && /^__MCE_ITEM__[\u2022\u00b7\u00a7\u00d8o\u25CF]/.test(html))\r
+                                                       dom.remove(span);\r
+                                               else if (/^__MCE_ITEM__[\s\S]*\w+\.(&nbsp;|\u00a0)*\s*/.test(html))\r
+                                                       dom.remove(span);\r
+                                       });\r
+\r
+                                       html = p.innerHTML;\r
+\r
+                                       // Remove middot/list items\r
+                                       if (type == 'ul')\r
+                                               html = p.innerHTML.replace(/__MCE_ITEM__/g, '').replace(/^[\u2022\u00b7\u00a7\u00d8o\u25CF]\s*(&nbsp;|\u00a0)+\s*/, '');\r
+                                       else\r
+                                               html = p.innerHTML.replace(/__MCE_ITEM__/g, '').replace(/^\s*\w+\.(&nbsp;|\u00a0)+\s*/, '');\r
+\r
+                                       // Create li and add paragraph data into the new li\r
+                                       li = listElm.appendChild(dom.create('li', 0, html));\r
+                                       dom.remove(p);\r
+\r
+                                       lastMargin = margin;\r
+                                       lastType = type;\r
+                               } else\r
+                                       listElm = lastMargin = 0; // End list element\r
+                       });\r
+\r
+                       // Remove any left over makers\r
+                       html = o.node.innerHTML;\r
+                       if (html.indexOf('__MCE_ITEM__') != -1)\r
+                               o.node.innerHTML = html.replace(/__MCE_ITEM__/g, '');\r
+               },\r
+\r
+               /**\r
+                * Inserts the specified contents at the caret position.\r
+                */\r
+               _insert : function(h, skip_undo) {\r
+                       var ed = this.editor, r = ed.selection.getRng();\r
+\r
+                       // First delete the contents seems to work better on WebKit when the selection spans multiple list items or multiple table cells.\r
+                       if (!ed.selection.isCollapsed() && r.startContainer != r.endContainer)\r
+                               ed.getDoc().execCommand('Delete', false, null);\r
+\r
+                       ed.execCommand('mceInsertContent', false, h, {skip_undo : skip_undo});\r
+               },\r
+\r
+               /**\r
+                * Instead of the old plain text method which tried to re-create a paste operation, the\r
+                * new approach adds a plain text mode toggle switch that changes the behavior of paste.\r
+                * This function is passed the same input that the regular paste plugin produces.\r
+                * It performs additional scrubbing and produces (and inserts) the plain text.\r
+                * This approach leverages all of the great existing functionality in the paste\r
+                * plugin, and requires minimal changes to add the new functionality.\r
+                * Speednet - June 2009\r
+                */\r
+               _insertPlainText : function(content) {\r
+                       var ed = this.editor,\r
+                               linebr = getParam(ed, "paste_text_linebreaktype"),\r
+                               rl = getParam(ed, "paste_text_replacements"),\r
+                               is = tinymce.is;\r
+\r
+                       function process(items) {\r
+                               each(items, function(v) {\r
+                                       if (v.constructor == RegExp)\r
+                                               content = content.replace(v, "");\r
+                                       else\r
+                                               content = content.replace(v[0], v[1]);\r
+                               });\r
+                       };\r
+\r
+                       if ((typeof(content) === "string") && (content.length > 0)) {\r
+                               // If HTML content with line-breaking tags, then remove all cr/lf chars because only tags will break a line\r
+                               if (/<(?:p|br|h[1-6]|ul|ol|dl|table|t[rdh]|div|blockquote|fieldset|pre|address|center)[^>]*>/i.test(content)) {\r
+                                       process([\r
+                                               /[\n\r]+/g\r
+                                       ]);\r
+                               } else {\r
+                                       // Otherwise just get rid of carriage returns (only need linefeeds)\r
+                                       process([\r
+                                               /\r+/g\r
+                                       ]);\r
+                               }\r
+\r
+                               process([\r
+                                       [/<\/(?:p|h[1-6]|ul|ol|dl|table|div|blockquote|fieldset|pre|address|center)>/gi, "\n\n"],               // Block tags get a blank line after them\r
+                                       [/<br[^>]*>|<\/tr>/gi, "\n"],                           // Single linebreak for <br /> tags and table rows\r
+                                       [/<\/t[dh]>\s*<t[dh][^>]*>/gi, "\t"],           // Table cells get tabs betweem them\r
+                                       /<[a-z!\/?][^>]*>/gi,                                           // Delete all remaining tags\r
+                                       [/&nbsp;/gi, " "],                                                      // Convert non-break spaces to regular spaces (remember, *plain text*)\r
+                                       [/(?:(?!\n)\s)*(\n+)(?:(?!\n)\s)*/gi, "$1"],// Cool little RegExp deletes whitespace around linebreak chars.\r
+                                       [/\n{3,}/g, "\n\n"]                                                     // Max. 2 consecutive linebreaks\r
+                               ]);\r
+\r
+                               content = ed.dom.decode(tinymce.html.Entities.encodeRaw(content));\r
+\r
+                               // Perform default or custom replacements\r
+                               if (is(rl, "array")) {\r
+                                       process(rl);\r
+                               } else if (is(rl, "string")) {\r
+                                       process(new RegExp(rl, "gi"));\r
+                               }\r
+\r
+                               // Treat paragraphs as specified in the config\r
+                               if (linebr == "none") {\r
+                                       process([\r
+                                               [/\n+/g, " "]\r
+                                       ]);\r
+                               } else if (linebr == "br") {\r
+                                       process([\r
+                                               [/\n/g, "<br />"]\r
+                                       ]);\r
+                               } else {\r
+                                       process([\r
+                                               [/\n\n/g, "</p><p>"],\r
+                                               [/^(.*<\/p>)(<p>)$/, '<p>$1'],\r
+                                               [/\n/g, "<br />"]\r
+                                       ]);\r
+                               }\r
+\r
+                               ed.execCommand('mceInsertContent', false, content);\r
+                       }\r
+               },\r
+\r
+               /**\r
+                * This method will open the old style paste dialogs. Some users might want the old behavior but still use the new cleanup engine.\r
+                */\r
+               _legacySupport : function() {\r
+                       var t = this, ed = t.editor;\r
+\r
+                       // Register command(s) for backwards compatibility\r
+                       ed.addCommand("mcePasteWord", function() {\r
+                               ed.windowManager.open({\r
+                                       file: t.url + "/pasteword.htm",\r
+                                       width: parseInt(getParam(ed, "paste_dialog_width")),\r
+                                       height: parseInt(getParam(ed, "paste_dialog_height")),\r
+                                       inline: 1\r
+                               });\r
+                       });\r
+\r
+                       if (getParam(ed, "paste_text_use_dialog")) {\r
+                               ed.addCommand("mcePasteText", function() {\r
+                                       ed.windowManager.open({\r
+                                               file : t.url + "/pastetext.htm",\r
+                                               width: parseInt(getParam(ed, "paste_dialog_width")),\r
+                                               height: parseInt(getParam(ed, "paste_dialog_height")),\r
+                                               inline : 1\r
+                                       });\r
+                               });\r
+                       }\r
+\r
+                       // Register button for backwards compatibility\r
+                       ed.addButton("pasteword", {title : "paste.paste_word_desc", cmd : "mcePasteWord"});\r
+               }\r
+       });\r
 \r
-       div.innerHTML = '';\r
-       var rng = document.body.createTextRange();\r
-       rng.moveToElementText(div);\r
-       rng.execCommand('Paste');\r
-       var html = div.innerHTML;\r
-       div.innerHTML = '';\r
-       return html;\r
-}\r
+       // Register plugin\r
+       tinymce.PluginManager.add("paste", tinymce.plugins.PastePlugin);\r
+})();\r