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 },
17 exec : function( editor )
20 config = editor.config,
21 baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',
22 isCustomDomain = CKEDITOR.env.isCustomDomain();
24 if ( config.fullPage )
26 sHTML = editor.getData()
27 .replace( /<head>/, '$&' + baseTag )
28 .replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview );
32 var bodyHtml = '<body ',
33 body = editor.document && editor.document.getBody();
37 if ( body.getAttribute( 'id' ) )
38 bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
39 if ( body.getAttribute( 'class' ) )
40 bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
46 editor.config.docType +
47 '<html dir="' + editor.config.contentsLangDirection + '">' +
50 '<title>' + editor.lang.preview + '</title>' +
51 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
52 '</head>' + bodyHtml +
57 var iWidth = 640, // 800 * 0.8,
58 iHeight = 420, // 600 * 0.7,
59 iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
62 var screen = window.screen;
63 iWidth = Math.round( screen.width * 0.8 );
64 iHeight = Math.round( screen.height * 0.7 );
65 iLeft = Math.round( screen.width * 0.1 );
72 window._cke_htmlToLoad = sHTML;
73 sOpenUrl = 'javascript:void( (function(){' +
75 'document.domain="' + document.domain + '";' +
76 'document.write( window.opener._cke_htmlToLoad );' +
78 'window.opener._cke_htmlToLoad = null;' +
82 var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
83 iWidth + ',height=' + iHeight + ',left=' + iLeft );
85 if ( !isCustomDomain )
87 var doc = oWindow.document;
92 // Chrome will need this to show the embedded. (#8016)
93 CKEDITOR.env.webkit && setTimeout( function() { doc.body.innerHTML += ''; }, 0 );
98 var pluginName = 'preview';
100 // Register a plugin named "preview".
101 CKEDITOR.plugins.add( pluginName,
103 init : function( editor )
105 editor.addCommand( pluginName, previewCmd );
106 editor.ui.addButton( 'Preview',
108 label : editor.lang.preview,