X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpreview%2Fplugin.js;h=3132a45a965ed46e1639088ea8618bcad4ccc3eb;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=6d3a369ca16c6aff4ed813e7f61f10c1043491d2;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/plugins/preview/plugin.js b/_source/plugins/preview/plugin.js index 6d3a369..3132a45 100644 --- a/_source/plugins/preview/plugin.js +++ b/_source/plugins/preview/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -9,26 +9,39 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { + var pluginPath; + var previewCmd = { modes : { wysiwyg:1, source:1 }, canUndo : false, + readOnly : 1, exec : function( editor ) { var sHTML, + config = editor.config, + baseTag = config.baseHref ? '' : '', isCustomDomain = CKEDITOR.env.isCustomDomain(); - if ( editor.config.fullPage ) - sHTML = editor.getData(); + + if ( config.fullPage ) + { + sHTML = editor.getData() + .replace( //, '$&' + baseTag ) + .replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview ); + } else { var bodyHtml = ' 0 ) ? '' : ''; + body = editor.document && editor.document.getBody(); + + if ( body ) + { + if ( body.getAttribute( 'id' ) ) + bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" '; + if ( body.getAttribute( 'class' ) ) + bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" '; + } - if ( body.getAttribute( 'id' ) ) - bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" '; - if ( body.getAttribute( 'class' ) ) - bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" '; bodyHtml += '>'; sHTML = @@ -37,9 +50,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license '' + baseTag + '' + editor.lang.preview + '' + - '' + + CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) + '' + bodyHtml + editor.getData() + ''; @@ -70,13 +81,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license '})() )'; } + // With Firefox only, we need to open a special preview page, so + // anchors will work properly on it. (#9047) + if ( CKEDITOR.env.gecko ) + { + window._cke_htmlToLoad = sHTML; + sOpenUrl = pluginPath + 'preview.html'; + } + var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft ); - if ( !isCustomDomain ) + if ( !isCustomDomain && !CKEDITOR.env.gecko ) { - oWindow.document.write( sHTML ); - oWindow.document.close(); + var doc = oWindow.document; + doc.open(); + doc.write( sHTML ); + doc.close(); + + // Chrome will need this to show the embedded. (#8016) + CKEDITOR.env.webkit && setTimeout( function() { doc.body.innerHTML += ''; }, 0 ); } } }; @@ -88,6 +112,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { init : function( editor ) { + pluginPath = this.path; + editor.addCommand( pluginName, previewCmd ); editor.ui.addButton( 'Preview', {