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