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 	var iframeId = 'cke_' + CKEDITOR.tools.getNextNumber();
 11
 12 	// For document.domain compatibility (#123) we must do all the magic in
 13 	// the URL for IE.
 14 	var src =
 15 		isCustomDomain ?
 16 			'javascript:void((function(){' +
 17 				'document.open();' +
 18 				'document.domain=\'' + document.domain + '\';' +
 19 				'document.write( window.parent.CKEDITOR._htmlToLoad );' +
 20 				'document.close();' +
 21 				'document.body.contentEditable = true;' +
 22 				'delete window.parent.CKEDITOR._htmlToLoad;' +
 23 				'window.focus();' +
 24 			'})())'
 25 		:
 26 			'javascript:void(0)';
 27
 28 	var iframeHtml =
 29 		'<iframe' +
 30 			' src="' + src + '"' +
 31 			' id="' + iframeId + '"' +
 32 			' style="width:346px;background-color:white;height:130px;border:1px solid black"' +
 33 			' frameborder="0"' +
 34 			' allowtransparency="1">' +
 35 		'</iframe>';
 36
 37 	var htmlToLoad =
 38 		'<!doctype html>' +
 39 		'<script type="text/javascript">' +
 40 			'window.onload = function()' +
 41 			'{' +
 42 				( CKEDITOR.env.ie ?
 43 					'document.body.contentEditable = "true";' :
 44 					'document.designMode = "on";' ) +
 45 				'window.focus();' +
 46 			'};' +
 47 			// Avoid errors if the pasted content has any script that
 48 			// fails. (#389)
 49 			'window.onerror = function()' +
 50 			'{' +
 51 				'return true;' +
 52 			'};' +
 53 		'</script><body style="margin:3px"></body>';
 54
 55 	return {
 56 		title : editor.lang.clipboard.title,
 57
 58 		minWidth : 400,
 59 		minHeight : 330,
 60
 61 		onShow : function()
 62 		{
 63 			if ( isCustomDomain )
 64 				CKEDITOR._htmlToLoad = htmlToLoad;
 65 			else
 66 			{
 67 				var iframe = CKEDITOR.document.getById( iframeId );
 68
 69 				var $doc = iframe.$.contentWindow.document;
 70 				$doc.open();
 71 				$doc.write( htmlToLoad );
 72 				$doc.close();
 73
 74 				iframe.$.contentWindow.focus();
 75 			}
 76 		},
 77
 78 		onOk : function()
 79 		{
 80 			var iframe = CKEDITOR.document.getById( iframeId );
 81
 82 			var body = new CKEDITOR.dom.element(
 83 				iframe.$.contentDocument ?
 84 					oBody = iframe.$.contentDocument.body :
 85 					oBody = iframe.$.contentWindow.document.body ) ;
 86
 87 			var html = body.getHtml();
 88
 89 			// Fix relative anchor URLs (IE automatically adds the current page URL).
 90 			var re = new RegExp( window.location + "#", 'g' );
 91 			html = html.replace( re, '#');
 92
 93 			this.restoreSelection();
 94 			this.clearSavedSelection();
 95
 96 			this.getParentEditor().insertHtml( html );
 97 		},
 98
 99 		contents : [
100 			{
101 				id : 'general',
102 				label : editor.lang.common.generalTab,
103 				elements : [
104 					{
105 						type : 'html',
106 						id : 'securityMsg',
107 						html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.securityMsg + '</div>'
108 					},
109 					{
110 						type : 'html',
111 						id : 'pasteMsg',
112 						html : '<div style="white-space:normal;width:340px;">'+editor.lang.clipboard.pasteMsg +'</div>'
113 					},
114 					{
115 						type : 'html',
116 						id : 'content',
117 						style : 'width:340px;height:130px',
118 						html : '<div>' + iframeHtml + '</div>'
119 					}
120 				]
121 			}
122 		]
123 	};
124 });
125