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