| 1 | /* |
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. |
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * @file Preview plugin. |
| 8 | */ |
| 9 | |
| 10 | (function() |
| 11 | { |
| 12 | var previewCmd = |
| 13 | { |
| 14 | exec : function( editor ) |
| 15 | { |
| 16 | var sHTML, |
| 17 | isCustomDomain = CKEDITOR.env.ie && document.domain != window.location.hostname; |
| 18 | if ( editor.config.fullPage ) |
| 19 | sHTML = editor.getData(); |
| 20 | else |
| 21 | { |
| 22 | var bodyHtml = '<body ', |
| 23 | body = CKEDITOR.document.getBody(), |
| 24 | baseTag = ( editor.config.baseHref.length > 0 ) ? '<base href="' + editor.config.baseHref + '" _cktemp="true"></base>' : ''; |
| 25 | |
| 26 | if ( body.getAttribute( 'id' ) ) |
| 27 | bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" '; |
| 28 | if ( body.getAttribute( 'class' ) ) |
| 29 | bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" '; |
| 30 | bodyHtml += '>'; |
| 31 | |
| 32 | sHTML = |
| 33 | editor.config.docType + |
| 34 | '<html dir="' + editor.config.contentsLangDirection + '">' + |
| 35 | '<head>' + |
| 36 | baseTag + |
| 37 | '<title>' + editor.lang.preview + '</title>' + |
| 38 | '<link href="' + editor.config.contentsCss + '" type="text/css" rel="stylesheet" _cktemp="true"/>' + |
| 39 | '</head>' + bodyHtml + |
| 40 | editor.getData() + |
| 41 | '</body></html>'; |
| 42 | } |
| 43 | |
| 44 | var iWidth = 640; // 800 * 0.8, |
| 45 | iHeight = 420; // 600 * 0.7, |
| 46 | iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1. |
| 47 | try |
| 48 | { |
| 49 | iWidth = Math.Round( screen.width * 0.8 ); |
| 50 | iHeight = Math.Round( screen.height * 0.7 ); |
| 51 | iLeft = Math.Round( screen.width * 0.1 ); |
| 52 | } |
| 53 | catch ( e ){} |
| 54 | |
| 55 | var sOpenUrl = ''; |
| 56 | if ( isCustomDomain ) |
| 57 | { |
| 58 | window._cke_htmlToLoad = sHTML; |
| 59 | sOpenUrl = 'javascript:void( (function(){' + |
| 60 | 'document.open();' + |
| 61 | 'document.domain="' + document.domain + '";' + |
| 62 | 'document.write( window.opener._cke_htmlToLoad );' + |
| 63 | 'document.close();' + |
| 64 | 'window.opener._cke_htmlToLoad = null;' + |
| 65 | '})() )'; |
| 66 | } |
| 67 | |
| 68 | var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + |
| 69 | iWidth + ',height=' + iHeight + ',left=' + iLeft ); |
| 70 | |
| 71 | if ( !isCustomDomain ) |
| 72 | { |
| 73 | oWindow.document.write( sHTML ); |
| 74 | oWindow.document.close(); |
| 75 | } |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | var pluginName = 'preview'; |
| 80 | |
| 81 | // Register a plugin named "save". |
| 82 | CKEDITOR.plugins.add( pluginName, |
| 83 | { |
| 84 | init : function( editor, pluginPath ) |
| 85 | { |
| 86 | editor.addCommand( pluginName, previewCmd ); |
| 87 | editor.ui.addButton( 'Preview', |
| 88 | { |
| 89 | label : editor.lang.preview, |
| 90 | command : pluginName |
| 91 | }); |
| 92 | } |
| 93 | }); |
| 94 | })(); |