2 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @file Preview plugin.
\r
16 modes : { wysiwyg:1, source:1 },
\r
19 exec : function( editor )
\r
22 config = editor.config,
\r
23 baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',
\r
24 isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
26 if ( config.fullPage )
\r
28 sHTML = editor.getData()
\r
29 .replace( /<head>/, '$&' + baseTag )
\r
30 .replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview );
\r
34 var bodyHtml = '<body ',
\r
35 body = editor.document && editor.document.getBody();
\r
39 if ( body.getAttribute( 'id' ) )
\r
40 bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
\r
41 if ( body.getAttribute( 'class' ) )
\r
42 bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
\r
48 editor.config.docType +
\r
49 '<html dir="' + editor.config.contentsLangDirection + '">' +
\r
52 '<title>' + editor.lang.preview + '</title>' +
\r
53 CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
\r
54 '</head>' + bodyHtml +
\r
59 var iWidth = 640, // 800 * 0.8,
\r
60 iHeight = 420, // 600 * 0.7,
\r
61 iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
\r
64 var screen = window.screen;
\r
65 iWidth = Math.round( screen.width * 0.8 );
\r
66 iHeight = Math.round( screen.height * 0.7 );
\r
67 iLeft = Math.round( screen.width * 0.1 );
\r
72 if ( isCustomDomain )
\r
74 window._cke_htmlToLoad = sHTML;
\r
75 sOpenUrl = 'javascript:void( (function(){' +
\r
76 'document.open();' +
\r
77 'document.domain="' + document.domain + '";' +
\r
78 'document.write( window.opener._cke_htmlToLoad );' +
\r
79 'document.close();' +
\r
80 'window.opener._cke_htmlToLoad = null;' +
\r
84 // With Firefox only, we need to open a special preview page, so
\r
85 // anchors will work properly on it. (#9047)
\r
86 if ( CKEDITOR.env.gecko )
\r
88 window._cke_htmlToLoad = sHTML;
\r
89 sOpenUrl = pluginPath + 'preview.html';
\r
92 var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
\r
93 iWidth + ',height=' + iHeight + ',left=' + iLeft );
\r
95 if ( !isCustomDomain && !CKEDITOR.env.gecko )
\r
97 var doc = oWindow.document;
\r
102 // Chrome will need this to show the embedded. (#8016)
\r
103 CKEDITOR.env.webkit && setTimeout( function() { doc.body.innerHTML += ''; }, 0 );
\r
108 var pluginName = 'preview';
\r
110 // Register a plugin named "preview".
\r
111 CKEDITOR.plugins.add( pluginName,
\r
113 init : function( editor )
\r
115 pluginPath = this.path;
\r
117 editor.addCommand( pluginName, previewCmd );
\r
118 editor.ui.addButton( 'Preview',
\r
120 label : editor.lang.preview,
\r
121 command : pluginName
\r