JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.3
[ckeditor.git] / _source / plugins / clipboard / dialogs / paste.js
index 70527ad..e0813ec 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -10,19 +10,25 @@ CKEDITOR.dialog.add( 'paste', function( editor )
 \r
        function onPasteFrameLoad( win )\r
        {\r
-               var doc =  new CKEDITOR.dom.document( win.document ),\r
-                       $ = doc.$;\r
+               var doc = new CKEDITOR.dom.document( win.document ),\r
+                       docElement = doc.$;\r
 \r
-               doc.getById( "cke_actscrpt" ).remove();\r
+               var script = doc.getById( 'cke_actscrpt' );\r
+               script && script.remove();\r
 \r
                CKEDITOR.env.ie ?\r
-                       $.body.contentEditable = "true" :\r
-                       $.designMode = "on";\r
+                       docElement.body.contentEditable = "true" :\r
+                       docElement.designMode = "on";\r
 \r
-               CKEDITOR.env.ie && doc.getWindow().on( 'blur', function()\r
+               // IE before version 8 will leave cursor blinking inside the document after\r
+               // editor blurred unless we clean up the selection. (#4716)\r
+               if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )\r
                {\r
-                        $.body.contentEditable = "false";\r
-               } );\r
+                       doc.getWindow().on( 'blur', function()\r
+                       {\r
+                               docElement.selection.empty();\r
+                       } );\r
+               }\r
 \r
                doc.on( "keydown", function( e )\r
                {\r
@@ -60,22 +66,33 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                        // inserted iframe editable. (#3366)\r
                        this.parts.dialog.$.offsetHeight;\r
 \r
-                       var htmlToLoad = '<!doctype html><html><head><style>body { margin: 3px; height: 95%; } </style></head><body>' +\r
-                                                        '<script id="cke_actscrpt" type="text/javascript">' +\r
-                                                        'window.parent.CKEDITOR.tools.callFunction( ' + CKEDITOR.tools.addFunction( onPasteFrameLoad, this ) + ', this );' +\r
-                                                        '</script></body></html>';\r
+                       var htmlToLoad =\r
+                               '<html dir="' + editor.config.contentsLangDirection + '"' +\r
+                               ' lang="' + ( editor.config.contentsLanguage || editor.langCode ) + '">' +\r
+                                       '<head><style>body { margin: 3px; height: 95%; } </style></head><body>' +\r
+                                       '<script id="cke_actscrpt" type="text/javascript">' +\r
+                                       'window.parent.CKEDITOR.tools.callFunction( ' + CKEDITOR.tools.addFunction( onPasteFrameLoad, this ) + ', this );' +\r
+                                       '</script></body>' +\r
+                               '</html>';\r
+\r
+                       var src =\r
+                               CKEDITOR.env.air ?\r
+                                       'javascript:void(0)' :\r
+                               isCustomDomain ?\r
+                                       'javascript:void((function(){' +\r
+                                               'document.open();' +\r
+                                               'document.domain=\'' + document.domain + '\';' +\r
+                                               'document.close();' +\r
+                                               '})())"'\r
+                               :\r
+                                       '';\r
 \r
                        var iframe = CKEDITOR.dom.element.createFromHtml(\r
                                                '<iframe' +\r
+                                               ' class="cke_pasteframe"' +\r
                                                ' frameborder="0" ' +\r
                                                ' allowTransparency="true"' +\r
-                                               // Support for custom document.domain in IE.\r
-                                               ( isCustomDomain ?\r
-                                                       ' src="javascript:void((function(){' +\r
-                                                               'document.open();' +\r
-                                                               'document.domain=\'' + document.domain + '\';' +\r
-                                                               'document.close();' +\r
-                                                       '})())"' : '' ) +\r
+                                               ' src="' + src + '"' +\r
                                                ' role="region"' +\r
                                                ' aria-label="' + lang.pasteArea + '"' +\r
                                                ' aria-describedby="' + this.getContentElement( 'general', 'pasteMsg' ).domId + '"' +\r
@@ -83,24 +100,17 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                                                '></iframe>' );\r
 \r
                        iframe.on( 'load', function( e )\r
-                       {\r
-                               e.removeListener();\r
-                               var doc = iframe.getFrameDocument().$;\r
-                               // Custom domain handling is needed after each document.open().\r
-                               doc.open();\r
-                               if ( isCustomDomain )\r
-                                       doc.domain = document.domain;\r
-                               doc.write( htmlToLoad );\r
-                               doc.close();\r
-                       }, this );\r
-\r
-                       iframe.setStyles(\r
                                {\r
-                                       width : '346px',\r
-                                       height : '130px',\r
-                                       'background-color' : 'white',\r
-                                       border : '1px solid black'\r
-                               } );\r
+                                       e.removeListener();\r
+\r
+                                       var doc = iframe.getFrameDocument();\r
+                                       doc.write( htmlToLoad );\r
+\r
+                                       if ( CKEDITOR.env.air )\r
+                                               onPasteFrameLoad.call( this, doc.getWindow().$ );\r
+                               },\r
+                               this );\r
+\r
                        iframe.setCustomData( 'dialog', this );\r
 \r
                        var field = this.getContentElement( 'general', 'editing_area' ),\r
@@ -108,6 +118,25 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                        container.setHtml( '' );\r
                        container.append( iframe );\r
 \r
+                       // IE need a redirect on focus to make\r
+                       // the cursor blinking inside iframe. (#5461)\r
+                       if ( CKEDITOR.env.ie )\r
+                       {\r
+                               var focusGrabber = CKEDITOR.dom.element.createFromHtml( '<span tabindex="-1" style="position:absolute;" role="presentation"></span>' );\r
+                               focusGrabber.on( 'focus', function()\r
+                               {\r
+                                       iframe.$.contentWindow.focus();\r
+                               });\r
+                               container.append( focusGrabber );\r
+\r
+                               // Override focus handler on field.\r
+                               field.focus = function()\r
+                               {\r
+                                       focusGrabber.focus();\r
+                                       this.fire( 'focus' );\r
+                               };\r
+                       }\r
+\r
                        field.getInputElement = function(){ return iframe; };\r
 \r
                        // Force container to scale in IE.\r
@@ -135,7 +164,12 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                        var container = this.getContentElement( 'general', 'editing_area' ).getElement(),\r
                                iframe = container.getElementsByTag( 'iframe' ).getItem( 0 ),\r
                                editor = this.getParentEditor(),\r
-                               html = iframe.$.contentWindow.document.body.innerHTML;\r
+                               body = iframe.getFrameDocument().getBody(),\r
+                               bogus = body.getBogus(),\r
+                               html;\r
+                       bogus && bogus.remove();\r
+                       // Saving the contents in variable so changes until paste is complete will not take place (#7500)\r
+                       html = body.getHtml();\r
 \r
                        setTimeout( function(){\r
                                editor.fire( 'paste', { 'html' : html } );\r
@@ -165,16 +199,13 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                                                html : '',\r
                                                focus : function()\r
                                                {\r
-                                                       var win = this.getInputElement().$.contentWindow,\r
-                                                                body = win && win.document.body;\r
+                                                       var win = this.getInputElement().$.contentWindow;\r
 \r
                                                        // #3291 : JAWS needs the 500ms delay to detect that the editor iframe\r
                                                        // iframe is no longer editable. So that it will put the focus into the\r
                                                        // Paste from Word dialog's editable area instead.\r
                                                        setTimeout( function()\r
                                                        {\r
-                                                               // Reactivate design mode for IE to make the cursor blinking.\r
-                                                               CKEDITOR.env.ie && body && ( body.contentEditable = "true" );\r
                                                                win.focus();\r
                                                        }, 500 );\r
                                                }\r