[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, 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 | modes : { wysiwyg:1, source:1 },
|
---|
| 15 | canUndo : false,
|
---|
| 16 | exec : function( editor )
|
---|
| 17 | {
|
---|
| 18 | var sHTML,
|
---|
| 19 | config = editor.config,
|
---|
| 20 | baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',
|
---|
| 21 | isCustomDomain = CKEDITOR.env.isCustomDomain();
|
---|
| 22 |
|
---|
| 23 | if ( config.fullPage )
|
---|
| 24 | {
|
---|
| 25 | sHTML = editor.getData()
|
---|
| 26 | .replace( /<head>/, '$&' + baseTag )
|
---|
| 27 | .replace( /[^>]*(?=<\/title>)/, editor.lang.preview );
|
---|
| 28 | }
|
---|
| 29 | else
|
---|
| 30 | {
|
---|
| 31 | var bodyHtml = '<body ',
|
---|
| 32 | body = editor.document && editor.document.getBody();
|
---|
| 33 |
|
---|
| 34 | if ( body )
|
---|
| 35 | {
|
---|
| 36 | if ( body.getAttribute( 'id' ) )
|
---|
| 37 | bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
|
---|
| 38 | if ( body.getAttribute( 'class' ) )
|
---|
| 39 | bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | bodyHtml += '>';
|
---|
| 43 |
|
---|
| 44 | sHTML =
|
---|
| 45 | editor.config.docType +
|
---|
| 46 | '<html dir="' + editor.config.contentsLangDirection + '">' +
|
---|
| 47 | '<head>' +
|
---|
| 48 | baseTag +
|
---|
| 49 | '<title>' + editor.lang.preview + '</title>' +
|
---|
| 50 | CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +
|
---|
| 51 | '</head>' + bodyHtml +
|
---|
| 52 | editor.getData() +
|
---|
| 53 | '</body></html>';
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | var iWidth = 640, // 800 * 0.8,
|
---|
| 57 | iHeight = 420, // 600 * 0.7,
|
---|
| 58 | iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
|
---|
| 59 | try
|
---|
| 60 | {
|
---|
| 61 | var screen = window.screen;
|
---|
| 62 | iWidth = Math.round( screen.width * 0.8 );
|
---|
| 63 | iHeight = Math.round( screen.height * 0.7 );
|
---|
| 64 | iLeft = Math.round( screen.width * 0.1 );
|
---|
| 65 | }
|
---|
| 66 | catch ( e ){}
|
---|
| 67 |
|
---|
| 68 | var sOpenUrl = '';
|
---|
| 69 | if ( isCustomDomain )
|
---|
| 70 | {
|
---|
| 71 | window._cke_htmlToLoad = sHTML;
|
---|
| 72 | sOpenUrl = 'javascript:void( (function(){' +
|
---|
| 73 | 'document.open();' +
|
---|
| 74 | 'document.domain="' + document.domain + '";' +
|
---|
| 75 | 'document.write( window.opener._cke_htmlToLoad );' +
|
---|
| 76 | 'document.close();' +
|
---|
| 77 | 'window.opener._cke_htmlToLoad = null;' +
|
---|
| 78 | '})() )';
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
|
---|
| 82 | iWidth + ',height=' + iHeight + ',left=' + iLeft );
|
---|
| 83 |
|
---|
| 84 | if ( !isCustomDomain )
|
---|
| 85 | {
|
---|
| 86 | oWindow.document.open();
|
---|
| 87 | oWindow.document.write( sHTML );
|
---|
| 88 | oWindow.document.close();
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | var pluginName = 'preview';
|
---|
| 94 |
|
---|
| 95 | // Register a plugin named "preview".
|
---|
| 96 | CKEDITOR.plugins.add( pluginName,
|
---|
| 97 | {
|
---|
| 98 | init : function( editor )
|
---|
| 99 | {
|
---|
| 100 | editor.addCommand( pluginName, previewCmd );
|
---|
| 101 | editor.ui.addButton( 'Preview',
|
---|
| 102 | {
|
---|
| 103 | label : editor.lang.preview,
|
---|
| 104 | command : pluginName
|
---|
| 105 | });
|
---|
| 106 | }
|
---|
| 107 | });
|
---|
| 108 | })();
|
---|