2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @file Preview plugin.
14 modes : { wysiwyg:1, source:1 },
16 exec : function( editor )
19 config = editor.config,
20 baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',
21 isCustomDomain = CKEDITOR.env.isCustomDomain();
23 if ( config.fullPage )
25 sHTML = editor.getData()
26 .replace( /<head>/, '$&' + baseTag )
27 .replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview );
31 var bodyHtml = '<body ',
32 body = editor.document && editor.document.getBody();
36 if ( body.getAttribute( 'id' ) )
37 bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
38 if ( body.getAttribute( 'class' ) )
39 bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
45 editor.config.docType +
46 '<html dir="' + editor.config.contentsLangDirection + '">' +
49 '<title>' + editor.lang.preview + '</title>' +
50 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
51 '</head>' + bodyHtml +
56 var iWidth = 640, // 800 * 0.8,
57 iHeight = 420, // 600 * 0.7,
58 iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
61 var screen = window.screen;
62 iWidth = Math.round( screen.width * 0.8 );
63 iHeight = Math.round( screen.height * 0.7 );
64 iLeft = Math.round( screen.width * 0.1 );
71 window._cke_htmlToLoad = sHTML;
72 sOpenUrl = 'javascript:void( (function(){' +
74 'document.domain="' + document.domain + '";' +
75 'document.write( window.opener._cke_htmlToLoad );' +
77 'window.opener._cke_htmlToLoad = null;' +
81 var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
82 iWidth + ',height=' + iHeight + ',left=' + iLeft );
84 if ( !isCustomDomain )
86 oWindow.document.open();
87 oWindow.document.write( sHTML );
88 oWindow.document.close();
93 var pluginName = 'preview';
95 // Register a plugin named "preview".
96 CKEDITOR.plugins.add( pluginName,
98 init : function( editor )
100 editor.addCommand( pluginName, previewCmd );
101 editor.ui.addButton( 'Preview',
103 label : editor.lang.preview,