JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / clipboard / dialogs / paste.js
diff --git a/_source/plugins/clipboard/dialogs/paste.js b/_source/plugins/clipboard/dialogs/paste.js
new file mode 100644 (file)
index 0000000..a9e2c82
--- /dev/null
@@ -0,0 +1,167 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.dialog.add( 'paste', function( editor )\r
+{\r
+       var isCustomDomain = CKEDITOR.env.ie && document.domain != window.location.hostname;\r
+\r
+       return {\r
+               title : editor.lang.clipboard.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
+\r
+                       iframe.setStyles(\r
+                               {\r
+                                       width : '346px',\r
+                                       height : '130px',\r
+                                       'background-color' : 'white',\r
+                                       border : '1px solid black'\r
+                               } );\r
+                       iframe.setCustomData( 'dialog', this );\r
+\r
+                       var accTitle = lang.editorTitle.replace( '%1', lang.clipboard.title );\r
+\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( '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
+               onHide : function()\r
+               {\r
+                       if ( CKEDITOR.env.ie )\r
+                               this.getParentEditor().document.getBody().$.contentEditable = 'true';\r
+               },\r
+\r
+               onLoad : function()\r
+               {\r
+                       if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' )\r
+                               this.parts.contents.setStyle( 'overflow', 'hidden' );\r
+               },\r
+\r
+               onOk : function()\r
+               {\r
+                       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
+\r
+                       setTimeout( function(){\r
+                               editor.insertHtml( html );\r
+                       }, 0 );\r
+\r
+               },\r
+\r
+               contents : [\r
+                       {\r
+                               id : 'general',\r
+                               label : editor.lang.common.generalTab,\r
+                               elements : [\r
+                                       {\r
+                                               type : 'html',\r
+                                               id : 'securityMsg',\r
+                                               html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.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
+                                       },\r
+                                       {\r
+                                               type : 'html',\r
+                                               id : 'editing_area',\r
+                                               style : 'width: 100%; height: 100%;',\r
+                                               html : '<fieldset></fieldset>',\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
+\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
+                                                       }, 500 );\r
+                                               }\r
+                                       }\r
+                               ]\r
+                       }\r
+               ]\r
+       };\r
+});\r