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.isCustomDomain();
\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 type="text/css" rel="stylesheet" href="' +
\r
41 [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +
\r
43 '</head>' + bodyHtml +
\r
48 var iWidth = 640, // 800 * 0.8,
\r
49 iHeight = 420, // 600 * 0.7,
\r
50 iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
\r
53 var screen = window.screen;
\r
54 iWidth = Math.round( screen.width * 0.8 );
\r
55 iHeight = Math.round( screen.height * 0.7 );
\r
56 iLeft = Math.round( screen.width * 0.1 );
\r
61 if ( isCustomDomain )
\r
63 window._cke_htmlToLoad = sHTML;
\r
64 sOpenUrl = 'javascript:void( (function(){' +
\r
65 'document.open();' +
\r
66 'document.domain="' + document.domain + '";' +
\r
67 'document.write( window.opener._cke_htmlToLoad );' +
\r
68 'document.close();' +
\r
69 'window.opener._cke_htmlToLoad = null;' +
\r
73 var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
\r
74 iWidth + ',height=' + iHeight + ',left=' + iLeft );
\r
76 if ( !isCustomDomain )
\r
78 oWindow.document.open();
\r
79 oWindow.document.write( sHTML );
\r
80 oWindow.document.close();
\r
85 var pluginName = 'preview';
\r
87 // Register a plugin named "preview".
\r
88 CKEDITOR.plugins.add( pluginName,
\r
90 init : function( editor )
\r
92 editor.addCommand( pluginName, previewCmd );
\r
93 editor.ui.addButton( 'Preview',
\r
95 label : editor.lang.preview,
\r
96 command : pluginName
\r