X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fclipboard%2Fdialogs%2Fpaste.js;h=2bc3142b6f0255d6f5d4628a1fd50112f262dd07;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=8eeeea029722fd844ebb1d03fde08b9832fce91d;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/plugins/clipboard/dialogs/paste.js b/_source/plugins/clipboard/dialogs/paste.js index 8eeeea0..2bc3142 100644 --- a/_source/plugins/clipboard/dialogs/paste.js +++ b/_source/plugins/clipboard/dialogs/paste.js @@ -1,100 +1,142 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.dialog.add( 'paste', function( editor ) { + var lang = editor.lang.clipboard; var isCustomDomain = CKEDITOR.env.isCustomDomain(); + function onPasteFrameLoad( win ) + { + var doc = new CKEDITOR.dom.document( win.document ), + docElement = doc.$; + + doc.getById( 'cke_actscrpt' ).remove(); + + CKEDITOR.env.ie ? + docElement.body.contentEditable = "true" : + docElement.designMode = "on"; + + // IE before version 8 will leave cursor blinking inside the document after + // editor blurred unless we clean up the selection. (#4716) + if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) + { + doc.getWindow().on( 'blur', function() + { + docElement.selection.empty(); + } ); + } + + doc.on( "keydown", function( e ) + { + var domEvent = e.data, + key = domEvent.getKeystroke(), + processed; + + switch( key ) + { + case 27 : + this.hide(); + processed = 1; + break; + + case 9 : + case CKEDITOR.SHIFT + 9 : + this.changeFocus( true ); + processed = 1; + } + + processed && domEvent.preventDefault(); + }, this ); + + editor.fire( 'ariaWidget', new CKEDITOR.dom.element( win.frameElement ) ); + } + return { - title : editor.lang.clipboard.title, + title : lang.title, minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350, minHeight : CKEDITOR.env.quirks ? 250 : 245, - htmlToLoad : '', - onShow : function() { - if ( CKEDITOR.env.ie ) - this.getParentEditor().document.getBody().$.contentEditable = 'false'; - // FIREFOX BUG: Force the browser to render the dialog to make the to-be- // inserted iframe editable. (#3366) this.parts.dialog.$.offsetHeight; - var container = this.getContentElement( 'general', 'editing_area' ).getElement(), - iframe = CKEDITOR.dom.element.createFromHtml( '' ); - - var lang = this.getParentEditor().lang; + var htmlToLoad = + '' + + '' + + '' + + ''; + + var iframe = CKEDITOR.dom.element.createFromHtml( + '' ); + + iframe.on( 'load', function( e ) + { + e.removeListener(); + var doc = iframe.getFrameDocument().$; + // Custom domain handling is needed after each document.open(). + doc.open(); + if ( isCustomDomain ) + doc.domain = document.domain; + doc.write( htmlToLoad ); + doc.close(); + }, this ); - iframe.setStyles( - { - width : '346px', - height : '130px', - 'background-color' : 'white', - border : '1px solid black' - } ); iframe.setCustomData( 'dialog', this ); - var accTitle = lang.editorTitle.replace( '%1', lang.clipboard.title ); + var field = this.getContentElement( 'general', 'editing_area' ), + container = field.getElement(); + container.setHtml( '' ); + container.append( iframe ); + // IE need a redirect on focus to make + // the cursor blinking inside iframe. (#5461) if ( CKEDITOR.env.ie ) - container.setHtml( '' - + CKEDITOR.tools.htmlEncode( accTitle ) - + '' ); - else { - container.setHtml( '' ); - container.setAttributes( - { - role : 'region', - title : accTitle - } ); - iframe.setAttributes( - { - role : 'region', - title : ' ' - } ); - } - container.append( iframe ); - if ( CKEDITOR.env.ie ) - container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' ); + var focusGrabber = CKEDITOR.dom.element.createFromHtml( '' ); + focusGrabber.on( 'focus', function() + { + iframe.$.contentWindow.focus(); + }); + container.append( focusGrabber ); - if ( isCustomDomain ) - { - CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad; - iframe.setAttribute( 'src', - 'javascript:void( (function(){' + - 'document.open();' + - 'document.domain="' + document.domain + '";' + - 'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' + - 'delete window.parent.CKEDITOR._cke_htmlToLoad;' + - 'document.close();' + - '})() )' ); + // Override focus handler on field. + field.focus = function() + { + focusGrabber.focus(); + this.fire( 'focus' ); + }; } - else + + field.getInputElement = function(){ return iframe; }; + + // Force container to scale in IE. + if ( CKEDITOR.env.ie ) { - var doc = iframe.$.contentWindow.document; - doc.open(); - doc.write( this.definition.htmlToLoad ); - doc.close(); + container.setStyle( 'display', 'block' ); + container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' ); } }, @@ -118,7 +160,7 @@ CKEDITOR.dialog.add( 'paste', function( editor ) html = iframe.$.contentWindow.document.body.innerHTML; setTimeout( function(){ - editor.insertHtml( html ); + editor.fire( 'paste', { 'html' : html } ); }, 0 ); }, @@ -131,32 +173,28 @@ CKEDITOR.dialog.add( 'paste', function( editor ) { type : 'html', id : 'securityMsg', - html : '
' + editor.lang.clipboard.securityMsg + '
' + html : '
' + lang.securityMsg + '
' }, { type : 'html', id : 'pasteMsg', - html : '
'+editor.lang.clipboard.pasteMsg +'
' + html : '
'+lang.pasteMsg +'
' }, { type : 'html', id : 'editing_area', style : 'width: 100%; height: 100%;', - html : '
', + html : '', focus : function() { - var div = this.getElement(); - var iframe = div.getElementsByTag( 'iframe' ); - if ( iframe.count() < 1 ) - return; - iframe = iframe.getItem( 0 ); + var win = this.getInputElement().$.contentWindow; // #3291 : JAWS needs the 500ms delay to detect that the editor iframe // iframe is no longer editable. So that it will put the focus into the // Paste from Word dialog's editable area instead. setTimeout( function() { - iframe.$.contentWindow.focus(); + win.focus(); }, 500 ); } }