/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
\r
(function()\r
{\r
+ var pluginPath;\r
+\r
var previewCmd =\r
{\r
modes : { wysiwyg:1, source:1 },\r
canUndo : false,\r
+ readOnly : 1,\r
exec : function( editor )\r
{\r
var sHTML,\r
+ config = editor.config,\r
+ baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',\r
isCustomDomain = CKEDITOR.env.isCustomDomain();\r
- if ( editor.config.fullPage )\r
- sHTML = editor.getData();\r
+\r
+ if ( config.fullPage )\r
+ {\r
+ sHTML = editor.getData()\r
+ .replace( /<head>/, '$&' + baseTag )\r
+ .replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview );\r
+ }\r
else\r
{\r
var bodyHtml = '<body ',\r
- body = CKEDITOR.document.getBody(),\r
- baseTag = ( editor.config.baseHref.length > 0 ) ? '<base href="' + editor.config.baseHref + '" _cktemp="true"></base>' : '';\r
+ body = editor.document && editor.document.getBody();\r
+\r
+ if ( body )\r
+ {\r
+ if ( body.getAttribute( 'id' ) )\r
+ bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';\r
+ if ( body.getAttribute( 'class' ) )\r
+ bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';\r
+ }\r
\r
- if ( body.getAttribute( 'id' ) )\r
- bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';\r
- if ( body.getAttribute( 'class' ) )\r
- bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';\r
bodyHtml += '>';\r
\r
sHTML =\r
'<head>' +\r
baseTag +\r
'<title>' + editor.lang.preview + '</title>' +\r
- '<link type="text/css" rel="stylesheet" href="' +\r
- [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +\r
- '">' +\r
+ CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +\r
'</head>' + bodyHtml +\r
editor.getData() +\r
'</body></html>';\r
'})() )';\r
}\r
\r
+ // With Firefox only, we need to open a special preview page, so\r
+ // anchors will work properly on it. (#9047)\r
+ if ( CKEDITOR.env.gecko )\r
+ {\r
+ window._cke_htmlToLoad = sHTML;\r
+ sOpenUrl = pluginPath + 'preview.html';\r
+ }\r
+\r
var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +\r
iWidth + ',height=' + iHeight + ',left=' + iLeft );\r
\r
- if ( !isCustomDomain )\r
+ if ( !isCustomDomain && !CKEDITOR.env.gecko )\r
{\r
- oWindow.document.open();\r
- oWindow.document.write( sHTML );\r
- oWindow.document.close();\r
+ var doc = oWindow.document;\r
+ doc.open();\r
+ doc.write( sHTML );\r
+ doc.close();\r
+\r
+ // Chrome will need this to show the embedded. (#8016)\r
+ CKEDITOR.env.webkit && setTimeout( function() { doc.body.innerHTML += ''; }, 0 );\r
}\r
}\r
};\r
{\r
init : function( editor )\r
{\r
+ pluginPath = this.path;\r
+\r
editor.addCommand( pluginName, previewCmd );\r
editor.ui.addButton( 'Preview',\r
{\r