JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / clipboard / dialogs / paste.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 CKEDITOR.dialog.add( 'paste', function( editor )\r
7 {\r
8         var isCustomDomain = CKEDITOR.env.isCustomDomain();\r
9 \r
10         return {\r
11                 title : editor.lang.clipboard.title,\r
12 \r
13                 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,\r
14                 minHeight : CKEDITOR.env.quirks ? 250 : 245,\r
15                 htmlToLoad : '<!doctype html><script type="text/javascript">'\r
16                                 + 'window.onload = function()'\r
17                                 + '{'\r
18                                         + 'if ( ' + CKEDITOR.env.ie + ' ) '\r
19                                                 + 'document.body.contentEditable = "true";'\r
20                                         + 'else '\r
21                                                 + 'document.designMode = "on";'\r
22                                         + 'var iframe = new window.parent.CKEDITOR.dom.element( frameElement );'\r
23                                         + 'var dialog = iframe.getCustomData( "dialog" );'\r
24                       + ''\r
25                                         + 'iframe.getFrameDocument().on( "keydown", function( e )\\r
26                                                 {\\r
27                                                         if ( e.data.getKeystroke() == 27 )\\r
28                                                                 dialog.hide();\\r
29                                                 });'\r
30                                 + '};'\r
31                                 + '</script><style>body { margin: 3px; height: 95%; } </style><body></body>',\r
32 \r
33                 onShow : function()\r
34                 {\r
35                         if ( CKEDITOR.env.ie )\r
36                                 this.getParentEditor().document.getBody().$.contentEditable = 'false';\r
37 \r
38                         // FIREFOX BUG: Force the browser to render the dialog to make the to-be-\r
39                         // inserted iframe editable. (#3366)\r
40                         this.parts.dialog.$.offsetHeight;\r
41 \r
42                         var container = this.getContentElement( 'general', 'editing_area' ).getElement(),\r
43                                 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe src="javascript:void(0)" frameborder="0" allowtransparency="1"></iframe>' );\r
44 \r
45                         var lang = this.getParentEditor().lang;\r
46 \r
47                         iframe.setStyles(\r
48                                 {\r
49                                         width : '346px',\r
50                                         height : '130px',\r
51                                         'background-color' : 'white',\r
52                                         border : '1px solid black'\r
53                                 } );\r
54                         iframe.setCustomData( 'dialog', this );\r
55 \r
56                         var accTitle = lang.editorTitle.replace( '%1', lang.clipboard.title );\r
57 \r
58                         if ( CKEDITOR.env.ie )\r
59                                 container.setHtml( '<legend style="position:absolute;top:-1000000px;left:-1000000px;">'\r
60                                                 + CKEDITOR.tools.htmlEncode( accTitle )\r
61                                                 + '</legend>' );\r
62                         else\r
63                         {\r
64                                 container.setHtml( '' );\r
65                                 container.setAttributes(\r
66                                         {\r
67                                                 role : 'region',\r
68                                                 title : accTitle\r
69                                         } );\r
70                                 iframe.setAttributes(\r
71                                         {\r
72                                                 role : 'region',\r
73                                                 title : ' '\r
74                                         } );\r
75                         }\r
76                         container.append( iframe );\r
77                         if ( CKEDITOR.env.ie )\r
78                                 container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' );\r
79 \r
80                         if ( isCustomDomain )\r
81                         {\r
82                                 CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad;\r
83                                 iframe.setAttribute( 'src',\r
84                                         'javascript:void( (function(){' +\r
85                                                    'document.open();' +\r
86                                                    'document.domain="' + document.domain + '";' +\r
87                                                    'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' +\r
88                                                    'delete window.parent.CKEDITOR._cke_htmlToLoad;' +\r
89                                                    'document.close();' +\r
90                                         '})() )' );\r
91                         }\r
92                         else\r
93                         {\r
94                                 var doc = iframe.$.contentWindow.document;\r
95                                 doc.open();\r
96                                 doc.write( this.definition.htmlToLoad );\r
97                                 doc.close();\r
98                         }\r
99                 },\r
100 \r
101                 onHide : function()\r
102                 {\r
103                         if ( CKEDITOR.env.ie )\r
104                                 this.getParentEditor().document.getBody().$.contentEditable = 'true';\r
105                 },\r
106 \r
107                 onLoad : function()\r
108                 {\r
109                         if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' )\r
110                                 this.parts.contents.setStyle( 'overflow', 'hidden' );\r
111                 },\r
112 \r
113                 onOk : function()\r
114                 {\r
115                         var container = this.getContentElement( 'general', 'editing_area' ).getElement(),\r
116                                 iframe = container.getElementsByTag( 'iframe' ).getItem( 0 ),\r
117                                 editor = this.getParentEditor(),\r
118                                 html = iframe.$.contentWindow.document.body.innerHTML;\r
119 \r
120                         setTimeout( function(){\r
121                                 editor.fire( 'paste', { 'html' : html } );\r
122                         }, 0 );\r
123 \r
124                 },\r
125 \r
126                 contents : [\r
127                         {\r
128                                 id : 'general',\r
129                                 label : editor.lang.common.generalTab,\r
130                                 elements : [\r
131                                         {\r
132                                                 type : 'html',\r
133                                                 id : 'securityMsg',\r
134                                                 html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.securityMsg + '</div>'\r
135                                         },\r
136                                         {\r
137                                                 type : 'html',\r
138                                                 id : 'pasteMsg',\r
139                                                 html : '<div style="white-space:normal;width:340px;">'+editor.lang.clipboard.pasteMsg +'</div>'\r
140                                         },\r
141                                         {\r
142                                                 type : 'html',\r
143                                                 id : 'editing_area',\r
144                                                 style : 'width: 100%; height: 100%;',\r
145                                                 html : '<fieldset></fieldset>',\r
146                                                 focus : function()\r
147                                                 {\r
148                                                         var div = this.getElement();\r
149                                                         var iframe = div.getElementsByTag( 'iframe' );\r
150                                                         if ( iframe.count() < 1 )\r
151                                                                 return;\r
152                                                         iframe = iframe.getItem( 0 );\r
153 \r
154                                                         // #3291 : JAWS needs the 500ms delay to detect that the editor iframe\r
155                                                         // iframe is no longer editable. So that it will put the focus into the\r
156                                                         // Paste from Word dialog's editable area instead.\r
157                                                         setTimeout( function()\r
158                                                         {\r
159                                                                 iframe.$.contentWindow.focus();\r
160                                                         }, 500 );\r
161                                                 }\r
162                                         }\r
163                                 ]\r
164                         }\r
165                 ]\r
166         };\r
167 });\r