]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/clipboard/dialogs/paste.js
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
6 CKEDITOR
.dialog
.add( 'paste', function( editor
) {
7 var lang
= editor
.lang
.clipboard
,
8 clipboard
= CKEDITOR
.plugins
.clipboard
,
11 function onPasteFrameLoad( win
) {
12 var doc
= new CKEDITOR
.dom
.document( win
.document
),
14 script
= doc
.getById( 'cke_actscrpt' );
16 script
&& script
.remove();
18 body
.setAttribute( 'contenteditable', true );
20 // Forward dataTransfer (#13883).
21 body
.on( clipboard
.mainPasteEvent
, function( evt
) {
22 var dataTransfer
= clipboard
.initPasteDataTransfer( evt
);
24 if ( !lastDataTransfer
) {
25 lastDataTransfer
= dataTransfer
;
27 // For two paste with the same dataTransfer we can use that dataTransfer (two internal pastes are
28 // considered as an internal paste).
29 if ( dataTransfer
!= lastDataTransfer
) {
30 // If there were two paste with different DataTransfer objects create a new, empty, data transfer
31 // and use it (one internal and one external paste are considered as external paste).
32 lastDataTransfer
= clipboard
.initPasteDataTransfer();
36 // IE before version 8 will leave cursor blinking inside the document after
37 // editor blurred unless we clean up the selection. (#4716)
38 if ( CKEDITOR
.env
.ie
&& CKEDITOR
.env
.version
< 8 ) {
39 doc
.getWindow().on( 'blur', function() {
40 doc
.$.selection
.empty();
44 doc
.on( 'keydown', function( e
) {
45 var domEvent
= e
.data
,
46 key
= domEvent
.getKeystroke(),
56 case CKEDITOR
.SHIFT
+ 9:
57 this.changeFocus( 1 );
61 processed
&& domEvent
.preventDefault();
64 editor
.fire( 'ariaWidget', new CKEDITOR
.dom
.element( win
.frameElement
) );
66 // Handle pending focus.
67 if ( doc
.getWindow().getFrame().removeCustomData( 'pendingFocus' ) )
71 // If pasteDialogCommit wasn't canceled by e.g. editor.getClipboardData
72 // then fire paste event.
73 // Do not use editor#paste, because it would start from beforePaste event.
74 editor
.on( 'pasteDialogCommit', function( evt
) {
76 editor
.fire( 'paste', {
78 dataValue: evt
.data
.dataValue
,
80 dataTransfer: evt
.data
.dataTransfer
|| clipboard
.initPasteDataTransfer()
82 }, null, null, 1000 );
87 minWidth: CKEDITOR
.env
.ie
&& CKEDITOR
.env
.quirks
? 370 : 350,
88 minHeight: CKEDITOR
.env
.quirks
? 250 : 245,
90 // FIREFOX BUG: Force the browser to render the dialog to make the to-be-
91 // inserted iframe editable. (#3366)
92 this.parts
.dialog
.$.offsetHeight
;
96 // Set dialog title to the custom value (set e.g. in editor.openDialog callback) and reset this value.
97 // If custom title not set, use default one.
98 this.parts
.title
.setHtml( this.customTitle
|| lang
.title
);
99 this.customTitle
= null;
103 if ( ( CKEDITOR
.env
.ie7Compat
|| CKEDITOR
.env
.ie6Compat
) && editor
.lang
.dir
== 'rtl' )
104 this.parts
.contents
.setStyle( 'overflow', 'hidden' );
108 this.commitContent();
113 label: editor
.lang
.common
.generalTab
,
118 html: '<div style="white-space:normal;width:340px">' + lang
.securityMsg
+ '</div>'
123 html: '<div style="white-space:normal;width:340px">' + lang
.pasteMsg
+ '</div>'
128 style: 'width:100%;height:100%',
131 var iframe
= this.getInputElement(),
132 doc
= iframe
.getFrameDocument(),
133 body
= doc
.getBody();
135 // Frame content may not loaded at the moment.
136 if ( !body
|| body
.isReadOnly() )
137 iframe
.setCustomData( 'pendingFocus', 1 );
142 var dialog
= this.getDialog();
143 var htmlToLoad
= '<html dir="' + editor
.config
.contentsLangDirection
+ '"' +
144 ' lang="' + ( editor
.config
.contentsLanguage
|| editor
.langCode
) + '">' +
145 '<head><style>body{margin:3px;height:95%;word-break:break-all;}</style></head><body>' +
146 '<script id="cke_actscrpt" type="text/javascript">' +
147 'window.parent.CKEDITOR.tools.callFunction(' + CKEDITOR
.tools
.addFunction( onPasteFrameLoad
, dialog
) + ',this);' +
153 'javascript:void(0)' : // jshint ignore:line
154 ( CKEDITOR
.env
.ie
&& !CKEDITOR
.env
.edge
) ?
155 'javascript:void((function(){' + encodeURIComponent( // jshint ignore:line
157 '(' + CKEDITOR
.tools
.fixDomain
+ ')();' +
162 var iframe
= CKEDITOR
.dom
.element
.createFromHtml( '<iframe' +
163 ' class="cke_pasteframe"' +
164 ' frameborder="0" ' +
165 ' allowTransparency="true"' +
166 ' src="' + src
+ '"' +
167 ' aria-label="' + lang
.pasteArea
+ '"' +
168 ' aria-describedby="' + dialog
.getContentElement( 'general', 'pasteMsg' ).domId
+ '"' +
171 // Reset last data transfer.
172 lastDataTransfer
= null;
174 iframe
.on( 'load', function( e
) {
177 var doc
= iframe
.getFrameDocument();
178 doc
.write( htmlToLoad
);
180 editor
.focusManager
.add( doc
.getBody() );
182 if ( CKEDITOR
.env
.air
)
183 onPasteFrameLoad
.call( this, doc
.getWindow().$ );
186 iframe
.setCustomData( 'dialog', dialog
);
188 var container
= this.getElement();
189 container
.setHtml( '' );
190 container
.append( iframe
);
192 // IE need a redirect on focus to make
193 // the cursor blinking inside iframe. (#5461)
194 if ( CKEDITOR
.env
.ie
&& !CKEDITOR
.env
.edge
) {
195 var focusGrabber
= CKEDITOR
.dom
.element
.createFromHtml( '<span tabindex="-1" style="position:absolute" role="presentation"></span>' );
196 focusGrabber
.on( 'focus', function() {
197 // Since fixDomain is called in src attribute,
198 // IE needs some slight delay to correctly move focus.
199 setTimeout( function() {
200 iframe
.$.contentWindow
.focus();
203 container
.append( focusGrabber
);
205 // Override focus handler on field.
206 this.focus = function() {
207 focusGrabber
.focus();
208 this.fire( 'focus' );
212 this.getInputElement = function() {
216 // Force container to scale in IE.
217 if ( CKEDITOR
.env
.ie
) {
218 container
.setStyle( 'display', 'block' );
219 container
.setStyle( 'height', ( iframe
.$.offsetHeight
+ 2 ) + 'px' );
223 var editor
= this.getDialog().getParentEditor(),
224 body
= this.getInputElement().getFrameDocument().getBody(),
225 bogus
= body
.getBogus(),
227 bogus
&& bogus
.remove();
229 // Saving the contents so changes until paste is complete will not take place (#7500)
230 html
= body
.getHtml();
232 // Opera needs some time to think about what has happened and what it should do now.
233 setTimeout( function() {
234 editor
.fire( 'pasteDialogCommit', {
236 // Avoid error if there was no paste so lastDataTransfer is null.
237 dataTransfer: lastDataTransfer
|| clipboard
.initPasteDataTransfer()
248 * Internal event to pass paste dialog's data to the listeners.
251 * @event pasteDialogCommit
252 * @member CKEDITOR.editor
253 * @param {CKEDITOR.editor} editor This editor instance.