Layout pour le dossier de skins cmf.
[ckeditor.git] / skins / ckeditor / _source / plugins / clipboard / dialogs / paste.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5
6 CKEDITOR.dialog.add( 'paste', function( editor )
7 {
8 var lang = editor.lang.clipboard;
9 var isCustomDomain = CKEDITOR.env.isCustomDomain();
10
11 function onPasteFrameLoad( win )
12 {
13 var doc = new CKEDITOR.dom.document( win.document ),
14 docElement = doc.$;
15
16 var script = doc.getById( 'cke_actscrpt' );
17 script && script.remove();
18
19 CKEDITOR.env.ie ?
20 docElement.body.contentEditable = "true" :
21 docElement.designMode = "on";
22
23 // IE before version 8 will leave cursor blinking inside the document after
24 // editor blurred unless we clean up the selection. (#4716)
25 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )
26 {
27 doc.getWindow().on( 'blur', function()
28 {
29 docElement.selection.empty();
30 } );
31 }
32
33 doc.on( "keydown", function( e )
34 {
35 var domEvent = e.data,
36 key = domEvent.getKeystroke(),
37 processed;
38
39 switch( key )
40 {
41 case 27 :
42 this.hide();
43 processed = 1;
44 break;
45
46 case 9 :
47 case CKEDITOR.SHIFT + 9 :
48 this.changeFocus( true );
49 processed = 1;
50 }
51
52 processed && domEvent.preventDefault();
53 }, this );
54
55 editor.fire( 'ariaWidget', new CKEDITOR.dom.element( win.frameElement ) );
56 }
57
58 return {
59 title : lang.title,
60
61 minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,
62 minHeight : CKEDITOR.env.quirks ? 250 : 245,
63 onShow : function()
64 {
65 // FIREFOX BUG: Force the browser to render the dialog to make the to-be-
66 // inserted iframe editable. (#3366)
67 this.parts.dialog.$.offsetHeight;
68
69 this.setupContent();
70 },
71
72 onHide : function()
73 {
74 if ( CKEDITOR.env.ie )
75 this.getParentEditor().document.getBody().$.contentEditable = 'true';
76 },
77
78 onLoad : function()
79 {
80 if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' )
81 this.parts.contents.setStyle( 'overflow', 'hidden' );
82 },
83
84 onOk : function()
85 {
86 this.commitContent();
87 },
88
89 contents : [
90 {
91 id : 'general',
92 label : editor.lang.common.generalTab,
93 elements : [
94 {
95 type : 'html',
96 id : 'securityMsg',
97 html : '<div style="white-space:normal;width:340px;">' + lang.securityMsg + '</div>'
98 },
99 {
100 type : 'html',
101 id : 'pasteMsg',
102 html : '<div style="white-space:normal;width:340px;">'+lang.pasteMsg +'</div>'
103 },
104 {
105 type : 'html',
106 id : 'editing_area',
107 style : 'width: 100%; height: 100%;',
108 html : '',
109 focus : function()
110 {
111 var win = this.getInputElement().$.contentWindow;
112
113 // #3291 : JAWS needs the 500ms delay to detect that the editor iframe
114 // iframe is no longer editable. So that it will put the focus into the
115 // Paste from Word dialog's editable area instead.
116 setTimeout( function()
117 {
118 win.focus();
119 }, 500 );
120 },
121 setup : function()
122 {
123 var dialog = this.getDialog();
124 var htmlToLoad =
125 '<html dir="' + editor.config.contentsLangDirection + '"' +
126 ' lang="' + ( editor.config.contentsLanguage || editor.langCode ) + '">' +
127 '<head><style>body { margin: 3px; height: 95%; } </style></head><body>' +
128 '<script id="cke_actscrpt" type="text/javascript">' +
129 'window.parent.CKEDITOR.tools.callFunction( ' + CKEDITOR.tools.addFunction( onPasteFrameLoad, dialog ) + ', this );' +
130 '</script></body>' +
131 '</html>';
132
133 var src =
134 CKEDITOR.env.air ?
135 'javascript:void(0)' :
136 isCustomDomain ?
137 'javascript:void((function(){' +
138 'document.open();' +
139 'document.domain=\'' + document.domain + '\';' +
140 'document.close();' +
141 '})())"'
142 :
143 '';
144
145 var iframe = CKEDITOR.dom.element.createFromHtml(
146 '<iframe' +
147 ' class="cke_pasteframe"' +
148 ' frameborder="0" ' +
149 ' allowTransparency="true"' +
150 ' src="' + src + '"' +
151 ' role="region"' +
152 ' aria-label="' + lang.pasteArea + '"' +
153 ' aria-describedby="' + dialog.getContentElement( 'general', 'pasteMsg' ).domId + '"' +
154 ' aria-multiple="true"' +
155 '></iframe>' );
156
157 iframe.on( 'load', function( e )
158 {
159 e.removeListener();
160
161 var doc = iframe.getFrameDocument();
162 doc.write( htmlToLoad );
163
164 if ( CKEDITOR.env.air )
165 onPasteFrameLoad.call( this, doc.getWindow().$ );
166 }, dialog );
167
168 iframe.setCustomData( 'dialog', dialog );
169
170 var container = this.getElement();
171 container.setHtml( '' );
172 container.append( iframe );
173
174 // IE need a redirect on focus to make
175 // the cursor blinking inside iframe. (#5461)
176 if ( CKEDITOR.env.ie )
177 {
178 var focusGrabber = CKEDITOR.dom.element.createFromHtml( '<span tabindex="-1" style="position:absolute;" role="presentation"></span>' );
179 focusGrabber.on( 'focus', function()
180 {
181 iframe.$.contentWindow.focus();
182 });
183 container.append( focusGrabber );
184
185 // Override focus handler on field.
186 this.focus = function()
187 {
188 focusGrabber.focus();
189 this.fire( 'focus' );
190 };
191 }
192
193 this.getInputElement = function(){ return iframe; };
194
195 // Force container to scale in IE.
196 if ( CKEDITOR.env.ie )
197 {
198 container.setStyle( 'display', 'block' );
199 container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' );
200 }
201 },
202 commit : function( data )
203 {
204 var container = this.getElement(),
205 editor = this.getDialog().getParentEditor(),
206 body = this.getInputElement().getFrameDocument().getBody(),
207 bogus = body.getBogus(),
208 html;
209 bogus && bogus.remove();
210
211 // Saving the contents so changes until paste is complete will not take place (#7500)
212 html = body.getHtml();
213
214 setTimeout( function(){
215 editor.fire( 'paste', { 'html' : html } );
216 }, 0 );
217 }
218 }
219 ]
220 }
221 ]
222 };
223 });