JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2
[ckeditor.git] / _source / plugins / clipboard / dialogs / paste.js
index 8903892..70527ad 100644 (file)
@@ -5,44 +5,94 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 CKEDITOR.dialog.add( 'paste', function( editor )\r
 {\r
+       var lang = editor.lang.clipboard;\r
        var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
 \r
+       function onPasteFrameLoad( win )\r
+       {\r
+               var doc =  new CKEDITOR.dom.document( win.document ),\r
+                       $ = doc.$;\r
+\r
+               doc.getById( "cke_actscrpt" ).remove();\r
+\r
+               CKEDITOR.env.ie ?\r
+                       $.body.contentEditable = "true" :\r
+                       $.designMode = "on";\r
+\r
+               CKEDITOR.env.ie && doc.getWindow().on( 'blur', function()\r
+               {\r
+                        $.body.contentEditable = "false";\r
+               } );\r
+\r
+               doc.on( "keydown", function( e )\r
+               {\r
+                       var domEvent = e.data,\r
+                               key = domEvent.getKeystroke(),\r
+                               processed;\r
+\r
+                       switch( key )\r
+                       {\r
+                               case 27 :\r
+                                       this.hide();\r
+                                       processed = 1;\r
+                                       break;\r
+\r
+                               case 9 :\r
+                               case CKEDITOR.SHIFT + 9 :\r
+                                       this.changeFocus( true );\r
+                                       processed = 1;\r
+                       }\r
+\r
+                       processed && domEvent.preventDefault();\r
+               }, this );\r
+\r
+               editor.fire( 'ariaWidget', new CKEDITOR.dom.element( win.frameElement ) );\r
+       }\r
+\r
        return {\r
-               title : editor.lang.clipboard.title,\r
+               title : lang.title,\r
 \r
                minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,\r
                minHeight : CKEDITOR.env.quirks ? 250 : 245,\r
-               htmlToLoad : '<!doctype html><script type="text/javascript">'\r
-                               + 'window.onload = function()'\r
-                               + '{'\r
-                                       + 'if ( ' + CKEDITOR.env.ie + ' ) '\r
-                                               + 'document.body.contentEditable = "true";'\r
-                                       + 'else '\r
-                                               + 'document.designMode = "on";'\r
-                                       + 'var iframe = new window.parent.CKEDITOR.dom.element( frameElement );'\r
-                                       + 'var dialog = iframe.getCustomData( "dialog" );'\r
-                     + ''\r
-                                       + 'iframe.getFrameDocument().on( "keydown", function( e )\\r
-                                               {\\r
-                                                       if ( e.data.getKeystroke() == 27 )\\r
-                                                               dialog.hide();\\r
-                                               });'\r
-                               + '};'\r
-                               + '</script><style>body { margin: 3px; height: 95%; } </style><body></body>',\r
-\r
                onShow : function()\r
                {\r
-                       if ( CKEDITOR.env.ie )\r
-                               this.getParentEditor().document.getBody().$.contentEditable = 'false';\r
-\r
                        // FIREFOX BUG: Force the browser to render the dialog to make the to-be-\r
                        // inserted iframe editable. (#3366)\r
                        this.parts.dialog.$.offsetHeight;\r
 \r
-                       var container = this.getContentElement( 'general', 'editing_area' ).getElement(),\r
-                               iframe = CKEDITOR.dom.element.createFromHtml( '<iframe src="javascript:void(0)" frameborder="0" allowtransparency="1"></iframe>' );\r
-\r
-                       var lang = this.getParentEditor().lang;\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
+\r
+                       var iframe = CKEDITOR.dom.element.createFromHtml(\r
+                                               '<iframe' +\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
+                                               ' role="region"' +\r
+                                               ' aria-label="' + lang.pasteArea + '"' +\r
+                                               ' aria-describedby="' + this.getContentElement( 'general', 'pasteMsg' ).domId + '"' +\r
+                                               ' aria-multiple="true"' +\r
+                                               '></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
@@ -53,48 +103,18 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                                } );\r
                        iframe.setCustomData( 'dialog', this );\r
 \r
-                       var accTitle = lang.editorTitle.replace( '%1', lang.clipboard.title );\r
+                       var field = this.getContentElement( 'general', 'editing_area' ),\r
+                               container = field.getElement();\r
+                       container.setHtml( '' );\r
+                       container.append( iframe );\r
+\r
+                       field.getInputElement = function(){ return iframe; };\r
 \r
+                       // Force container to scale in IE.\r
                        if ( CKEDITOR.env.ie )\r
-                               container.setHtml( '<legend style="position:absolute;top:-1000000px;left:-1000000px;">'\r
-                                               + CKEDITOR.tools.htmlEncode( accTitle )\r
-                                               + '</legend>' );\r
-                       else\r
                        {\r
-                               container.setHtml( '' );\r
-                               container.setAttributes(\r
-                                       {\r
-                                               role : 'region',\r
-                                               title : accTitle\r
-                                       } );\r
-                               iframe.setAttributes(\r
-                                       {\r
-                                               role : 'region',\r
-                                               title : ' '\r
-                                       } );\r
-                       }\r
-                       container.append( iframe );\r
-                       if ( CKEDITOR.env.ie )\r
+                               container.setStyle( 'display', 'block' );\r
                                container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' );\r
-\r
-                       if ( isCustomDomain )\r
-                       {\r
-                               CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad;\r
-                               iframe.setAttribute( 'src',\r
-                                       'javascript:void( (function(){' +\r
-                                                  'document.open();' +\r
-                                                  'document.domain="' + document.domain + '";' +\r
-                                                  'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' +\r
-                                                  'delete window.parent.CKEDITOR._cke_htmlToLoad;' +\r
-                                                  'document.close();' +\r
-                                       '})() )' );\r
-                       }\r
-                       else\r
-                       {\r
-                               var doc = iframe.$.contentWindow.document;\r
-                               doc.open();\r
-                               doc.write( this.definition.htmlToLoad );\r
-                               doc.close();\r
                        }\r
                },\r
 \r
@@ -131,32 +151,31 @@ CKEDITOR.dialog.add( 'paste', function( editor )
                                        {\r
                                                type : 'html',\r
                                                id : 'securityMsg',\r
-                                               html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.securityMsg + '</div>'\r
+                                               html : '<div style="white-space:normal;width:340px;">' + lang.securityMsg + '</div>'\r
                                        },\r
                                        {\r
                                                type : 'html',\r
                                                id : 'pasteMsg',\r
-                                               html : '<div style="white-space:normal;width:340px;">'+editor.lang.clipboard.pasteMsg +'</div>'\r
+                                               html : '<div style="white-space:normal;width:340px;">'+lang.pasteMsg +'</div>'\r
                                        },\r
                                        {\r
                                                type : 'html',\r
                                                id : 'editing_area',\r
                                                style : 'width: 100%; height: 100%;',\r
-                                               html : '<fieldset></fieldset>',\r
+                                               html : '',\r
                                                focus : function()\r
                                                {\r
-                                                       var div = this.getElement();\r
-                                                       var iframe = div.getElementsByTag( 'iframe' );\r
-                                                       if ( iframe.count() < 1 )\r
-                                                               return;\r
-                                                       iframe = iframe.getItem( 0 );\r
+                                                       var win = this.getInputElement().$.contentWindow,\r
+                                                                body = win && win.document.body;\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
-                                                               iframe.$.contentWindow.focus();\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
                                        }\r