a31ebfad398bda0642ede38aadcc448316e6495f
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 oWindow
.document
.open();
88 oWindow
.document
.write( sHTML
);
89 oWindow
.document
.close();
94 var pluginName
= 'preview';
96 // Register a plugin named "preview".
97 CKEDITOR
.plugins
.add( pluginName
,
99 init : function( editor
)
101 editor
.addCommand( pluginName
, previewCmd
);
102 editor
.ui
.addButton( 'Preview',
104 label
: editor
.lang
.preview
,