diff -r 5882f0eebb34 -r e3b94bd055dc includes/clientside/tinymce/plugins/paste/editor_plugin_src.js
--- a/includes/clientside/tinymce/plugins/paste/editor_plugin_src.js Mon Dec 21 15:41:05 2009 -0500
+++ b/includes/clientside/tinymce/plugins/paste/editor_plugin_src.js Tue Dec 22 13:09:59 2009 -0500
@@ -1,81 +1,179 @@
/**
- * $Id: editor_plugin_src.js 919 2008-09-08 20:31:23Z spocke $
+ * $Id: editor_plugin_src.js 1225 2009-09-07 19:06:19Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
*/
(function() {
- var Event = tinymce.dom.Event;
+ var each = tinymce.each;
tinymce.create('tinymce.plugins.PastePlugin', {
init : function(ed, url) {
- var t = this;
+ var t = this, cb;
+
+ t.editor = ed;
+ t.url = url;
+
+ // Setup plugin events
+ t.onPreProcess = new tinymce.util.Dispatcher(t);
+ t.onPostProcess = new tinymce.util.Dispatcher(t);
- t.editor = ed;
+ // Register default handlers
+ t.onPreProcess.add(t._preProcess);
+ t.onPostProcess.add(t._postProcess);
+
+ // Register optional preprocess handler
+ t.onPreProcess.add(function(pl, o) {
+ ed.execCallback('paste_preprocess', pl, o);
+ });
+
+ // Register optional postprocess
+ t.onPostProcess.add(function(pl, o) {
+ ed.execCallback('paste_postprocess', pl, o);
+ });
- // Register commands
- ed.addCommand('mcePasteText', function(ui, v) {
- if (ui) {
- if ((ed.getParam('paste_use_dialog', true)) || (!tinymce.isIE)) {
- ed.windowManager.open({
- file : url + '/pastetext.htm',
- width : 450,
- height : 400,
- inline : 1
- }, {
- plugin_url : url
- });
- } else
- t._insertText(clipboardData.getData("Text"), true);
- } else
- t._insertText(v.html, v.linebreaks);
+ // This function executes the process handlers and inserts the contents
+ function process(o) {
+ var dom = ed.dom;
+
+ // Execute pre process handlers
+ t.onPreProcess.dispatch(t, o);
+
+ // Create DOM structure
+ o.node = dom.create('div', 0, o.content);
+
+ // Execute post process handlers
+ t.onPostProcess.dispatch(t, o);
+
+ // Serialize content
+ o.content = ed.serializer.serialize(o.node, {getInner : 1});
+
+ // Insert cleaned content. We need to handle insertion of contents containing block elements separately
+ if (/<(p|h[1-6]|ul|ol)/.test(o.content))
+ t._insertBlockContent(ed, dom, o.content);
+ else
+ t._insert(o.content);
+ };
+
+ // Add command for external usage
+ ed.addCommand('mceInsertClipboardContent', function(u, o) {
+ process(o);
});
- ed.addCommand('mcePasteWord', function(ui, v) {
- if (ui) {
- if ((ed.getParam('paste_use_dialog', true)) || (!tinymce.isIE)) {
- ed.windowManager.open({
- file : url + '/pasteword.htm',
- width : 450,
- height : 400,
- inline : 1
- }, {
- plugin_url : url
+ // This function grabs the contents from the clipboard by adding a
+ // hidden div and placing the caret inside it and after the browser paste
+ // is done it grabs that contents and processes that
+ function grabContent(e) {
+ var n, or, rng, sel = ed.selection, dom = ed.dom, body = ed.getBody(), posY;
+
+ if (dom.get('_mcePaste'))
+ return;
+
+ // Create container to paste into
+ n = dom.add(body, 'div', {id : '_mcePaste'}, '\uFEFF');
+
+ // If contentEditable mode we need to find out the position of the closest element
+ if (body != ed.getDoc().body)
+ posY = dom.getPos(ed.selection.getStart(), body).y;
+ else
+ posY = body.scrollTop;
+
+ // Styles needs to be applied after the element is added to the document since WebKit will otherwise remove all styles
+ dom.setStyles(n, {
+ position : 'absolute',
+ left : -10000,
+ top : posY,
+ width : 1,
+ height : 1,
+ overflow : 'hidden'
+ });
+
+ if (tinymce.isIE) {
+ // Select the container
+ rng = dom.doc.body.createTextRange();
+ rng.moveToElementText(n);
+ rng.execCommand('Paste');
+
+ // Remove container
+ dom.remove(n);
+
+ // Check if the contents was changed, if it wasn't then clipboard extraction failed probably due
+ // to IE security settings so we pass the junk though better than nothing right
+ if (n.innerHTML === '\uFEFF') {
+ ed.execCommand('mcePasteWord');
+ e.preventDefault();
+ return;
+ }
+
+ // Process contents
+ process({content : n.innerHTML});
+
+ // Block the real paste event
+ return tinymce.dom.Event.cancel(e);
+ } else {
+ or = ed.selection.getRng();
+
+ // Move caret into hidden div
+ n = n.firstChild;
+ rng = ed.getDoc().createRange();
+ rng.setStart(n, 0);
+ rng.setEnd(n, 1);
+ sel.setRng(rng);
+
+ // Wait a while and grab the pasted contents
+ window.setTimeout(function() {
+ var h = '', nl = dom.select('div[id=_mcePaste]');
+
+ // WebKit will split the div into multiple ones so this will loop through then all and join them to get the whole HTML string
+ each(nl, function(n) {
+ h += (dom.select('> span.Apple-style-span div', n)[0] || dom.select('> span.Apple-style-span', n)[0] || n).innerHTML;
});
- } else
- t._insertText(t._clipboardHTML());
- } else
- t._insertWordContent(v);
- });
+
+ // Remove the nodes
+ each(nl, function(n) {
+ dom.remove(n);
+ });
+
+ // Restore the old selection
+ if (or)
+ sel.setRng(or);
+
+ process({content : h});
+ }, 0);
+ }
+ };
- ed.addCommand('mceSelectAll', function() {
- ed.execCommand('selectall');
- });
+ // Check if we should use the new auto process method
+ if (ed.getParam('paste_auto_cleanup_on_paste', true)) {
+ // Is it's Opera or older FF use key handler
+ if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) {
+ ed.onKeyDown.add(function(ed, e) {
+ if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
+ grabContent(e);
+ });
+ } else {
+ // Grab contents on paste event on Gecko and WebKit
+ ed.onPaste.addToTop(function(ed, e) {
+ return grabContent(e);
+ });
+ }
+ }
- // 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'});
+ // Block all drag/drop events
+ if (ed.getParam('paste_block_drop')) {
+ ed.onInit.add(function() {
+ ed.dom.bind(ed.getBody(), ['dragend', 'dragover', 'draggesture', 'dragdrop', 'drop', 'drag'], function(e) {
+ e.preventDefault();
+ e.stopPropagation();
- if (ed.getParam("paste_auto_cleanup_on_paste", false)) {
- ed.onPaste.add(function(ed, e) {
- return t._handlePasteEvent(e)
+ return false;
+ });
});
}
- if (!tinymce.isIE && ed.getParam("paste_auto_cleanup_on_paste", false)) {
- // Force paste dialog if non IE browser
- ed.onKeyDown.add(function(ed, e) {
- if (e.ctrlKey && e.keyCode == 86) {
- window.setTimeout(function() {
- ed.execCommand("mcePasteText", true);
- }, 1);
-
- Event.cancel(e);
- }
- });
- }
+ // Add legacy support
+ t._legacySupport();
},
getInfo : function() {
@@ -88,304 +186,343 @@
};
},
- // Private methods
+ _preProcess : function(pl, o) {
+ var ed = this.editor, h = o.content, process, stripClass;
- _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');
+ //console.log('Before preprocess:' + o.content);
- if (html && html.length > 0)
- ed.execCommand('mcePasteWord', false, html);
+ function process(items) {
+ each(items, function(v) {
+ // Remove or replace
+ if (v.constructor == RegExp)
+ h = h.replace(v, '');
+ else
+ h = h.replace(v[0], v[1]);
+ });
+ };
- return Event.cancel(e);
- },
-
- _insertText : function(content, bLinebreaks) {
- content = this.editor.dom.encode(content);
+ // Detect Word content and process it more aggressive
+ if (/(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/.test(h) || o.wordContent) {
+ o.wordContent = true; // Mark the pasted contents as word specific content
+ //console.log('Word contents detected.');
- if (content && content.length > 0) {
- // Delete any highlighted text before pasting
- if (!this.editor.selection.isCollapsed())
- this.editor.execCommand("Delete");
+ // Process away some basic content
+ process([
+ /^\s*( )+/g, // nbsp entities at the start of contents
+ /( |
]*>)+\s*$/g // nbsp entities at the end of contents
+ ]);
- 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
'); - content = content.replace(/\r\r/g, '
'); - content = content.replace(/\n\n/g, '
'); - - // Has paragraphs - if ((pos = content.indexOf('
')) != -1) {
- this.editor.execCommand("Delete");
+ process([
+ //gi, // Word comments
+ /<\/?(img|font|meta|link|style|div|v:\w+)[^>]*>/gi, // Remove some tags including VML content
+ /<\\?\?xml[^>]*>/gi, // XML namespace declarations
+ /<\/?o:[^>]*>/gi, // MS namespaced elements into for line-though
+ /