[BUGFIX] RTE: paste as plain text does not work in IE9
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 10 Oct 2012 16:28:27 +0000 (12:28 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Mon, 15 Oct 2012 15:25:25 +0000 (17:25 +0200)
Problem: IE9 may be configured to enable clipboard access, but most
users will not know how.
Solution: Use pasting pad.

Change-Id: I2f0a03547c91c51e022d6bdd4ed8c91474a08805
Resolves: #39389
Releases: 4.7, 6.0
Reviewed-on: http://review.typo3.org/15639
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/htmlarea/plugins/PlainText/plain-text.js

index f6b1bbe..f2ca348 100644 (file)
@@ -249,8 +249,8 @@ HTMLArea.PlainText = Ext.extend(HTMLArea.Plugin, {
                if (!this.getButton('PasteToggle').inactive) {
                        switch (this.currentBehaviour) {
                                case 'plainText':
-                                               // Only IE and WebKit will allow access to the clipboard content, in plain text only however
-                                       if (Ext.isIE || Ext.isWebKit) {
+                                       // Only IE before IE9 and Chrome will allow access to the clipboard content by default, in plain text only however
+                                       if (HTMLArea.isIEBeforeIE9 || Ext.isChrome) {
                                                var clipboardText = this.grabClipboardText(event);
                                                if (clipboardText) {
                                                        this.editor.getSelection().insertHtml(clipboardText);
@@ -260,8 +260,6 @@ HTMLArea.PlainText = Ext.extend(HTMLArea.Plugin, {
                                case 'pasteStructure':
                                case 'pasteFormat':
                                        if (Ext.isIE) {
-                                                       // Save the current selection
-                                               this.bookmark = this.editor.getBookMark().get(this.editor.getSelection().createRange());
                                                        // Show the pasting pad
                                                this.openPastingPad(
                                                        'PasteToggle',
@@ -272,8 +270,13 @@ HTMLArea.PlainText = Ext.extend(HTMLArea.Plugin, {
                                                                        height: 550
                                                                },
                                                                'PasteToggle'
-                                                       ));
-                                               event.browserEvent.returnValue = false;
+                                                       )
+                                               );
+                                               if (HTMLArea.isIEBeforeIE9) {
+                                                       event.browserEvent.returnValue = false;
+                                               } else {
+                                                       event.stopEvent();
+                                               }
                                                return false;
                                        } else {
                                                        // Redirect the paste operation to a hidden section
@@ -429,12 +432,24 @@ HTMLArea.PlainText = Ext.extend(HTMLArea.Plugin, {
         */
        onPastingPadAfterRender: function () {
                var iframe = this.dialog.getComponent('pasting-pad-iframe').getEl().dom;
-               var pastingPadDocument = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
-               this.pastingPadBody = pastingPadDocument.body;
+               this.pastingPadDocument = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
+               this.pastingPadBody = this.pastingPadDocument.body;
                this.pastingPadBody.contentEditable = true;
-                       // Start monitoring paste events
+               // Start monitoring paste events
                this.dialog.mon(Ext.get(this.pastingPadBody), 'paste', this.onPastingPadPaste, this);
+               // Try to keep focus on the pasting pad
+               this.dialog.mon(Ext.get(this.editor.document.documentElement), 'mouseover', function (event) { this.focusOnPastingPad(); }, this);
+               this.dialog.mon(Ext.get(this.editor.document.body), 'focus', function (event) { this.focusOnPastingPad(); }, this);
+               this.dialog.mon(Ext.get(this.pastingPadDocument.documentElement), 'mouseover', function (event) { this.focusOnPastingPad(); }, this);
+               this.focusOnPastingPad();
+       },
+       /*
+        * Bring focus and selection on the pasting pad
+        */
+       focusOnPastingPad: function () {
                this.pastingPadBody.focus();
+               this.pastingPadDocument.getSelection().selectAllChildren(this.pastingPadBody);
+               this.pastingPadDocument.getSelection().collapseToEnd();
        },
        /*
         * Handler invoked when content is pasted into the pasting pad
@@ -447,7 +462,19 @@ HTMLArea.PlainText = Ext.extend(HTMLArea.Plugin, {
         * Clean the contents of the pasting pad
         */
        cleanPastingPadContents: function () {
-               this.pastingPadBody.innerHTML = this.cleaners[this.currentBehaviour].render(this.pastingPadBody, false);
+               var content = '';
+               switch (this.currentBehaviour) {
+                       case 'plainText':
+                               // Get plain text content
+                               content = this.pastingPadBody.textContent;
+                               break;
+                       case 'pasteStructure':
+                       case 'pasteFormat':
+                               // Get clean content
+                               content = this.cleaners[this.currentBehaviour].render(this.pastingPadBody, false);
+                               break;
+               }
+               this.pastingPadBody.innerHTML = content;
                this.pastingPadBody.focus();
        },
        /*