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