2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @file Preview plugin.
\r
14 modes : { wysiwyg:1, source:1 },
\r
16 exec : function( editor )
\r
19 isCustomDomain = CKEDITOR.env.ie && document.domain != window.location.hostname;
\r
20 if ( editor.config.fullPage )
\r
21 sHTML = editor.getData();
\r
24 var bodyHtml = '<body ',
\r
25 body = CKEDITOR.document.getBody(),
\r
26 baseTag = ( editor.config.baseHref.length > 0 ) ? '<base href="' + editor.config.baseHref + '" _cktemp="true"></base>' : '';
\r
28 if ( body.getAttribute( 'id' ) )
\r
29 bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
\r
30 if ( body.getAttribute( 'class' ) )
\r
31 bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
\r
35 editor.config.docType +
\r
36 '<html dir="' + editor.config.contentsLangDirection + '">' +
\r
39 '<title>' + editor.lang.preview + '</title>' +
\r
40 '<link href="' + editor.config.contentsCss + '" type="text/css" rel="stylesheet" _cktemp="true"/>' +
\r
41 '</head>' + bodyHtml +
\r
46 var iWidth = 640, // 800 * 0.8,
\r
47 iHeight = 420, // 600 * 0.7,
\r
48 iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
\r
51 var screen = window.screen;
\r
52 iWidth = Math.round( screen.width * 0.8 );
\r
53 iHeight = Math.round( screen.height * 0.7 );
\r
54 iLeft = Math.round( screen.width * 0.1 );
\r
59 if ( isCustomDomain )
\r
61 window._cke_htmlToLoad = sHTML;
\r
62 sOpenUrl = 'javascript:void( (function(){' +
\r
63 'document.open();' +
\r
64 'document.domain="' + document.domain + '";' +
\r
65 'document.write( window.opener._cke_htmlToLoad );' +
\r
66 'document.close();' +
\r
67 'window.opener._cke_htmlToLoad = null;' +
\r
71 var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
\r
72 iWidth + ',height=' + iHeight + ',left=' + iLeft );
\r
74 if ( !isCustomDomain )
\r
76 oWindow.document.write( sHTML );
\r
77 oWindow.document.close();
\r
82 var pluginName = 'preview';
\r
84 // Register a plugin named "preview".
\r
85 CKEDITOR.plugins.add( pluginName,
\r
87 init : function( editor )
\r
89 editor.addCommand( pluginName, previewCmd );
\r
90 editor.ui.addButton( 'Preview',
\r
92 label : editor.lang.preview,
\r
93 command : pluginName
\r