source: sandbox/2.3-MailArchiver/filemanager/tp/ckeditor/_source/plugins/preview/plugin.js @ 6779

Revision 6779, 2.7 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1/*
2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
3For 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                                isCustomDomain = CKEDITOR.env.isCustomDomain();
20                        if ( editor.config.fullPage )
21                                sHTML = editor.getData();
22                        else
23                        {
24                                var bodyHtml = '<body ',
25                                        body = CKEDITOR.document.getBody(),
26                                        baseTag = ( editor.config.baseHref.length > 0 ) ? '<base href="' + editor.config.baseHref + '" _cktemp="true"></base>' : '';
27
28                                if ( body.getAttribute( 'id' ) )
29                                        bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';
30                                if ( body.getAttribute( 'class' ) )
31                                        bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';
32                                bodyHtml += '>';
33
34                                sHTML =
35                                        editor.config.docType +
36                                        '<html dir="' + editor.config.contentsLangDirection + '">' +
37                                        '<head>' +
38                                        baseTag +
39                                        '<title>' + editor.lang.preview + '</title>' +
40                                        '<link type="text/css" rel="stylesheet" href="' +
41                                        [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +
42                                        '">' +
43                                        '</head>' + bodyHtml +
44                                        editor.getData() +
45                                        '</body></html>';
46                        }
47
48                        var iWidth      = 640,  // 800 * 0.8,
49                                iHeight = 420,  // 600 * 0.7,
50                                iLeft   = 80;   // (800 - 0.8 * 800) /2 = 800 * 0.1.
51                        try
52                        {
53                                var screen = window.screen;
54                                iWidth = Math.round( screen.width * 0.8 );
55                                iHeight = Math.round( screen.height * 0.7 );
56                                iLeft = Math.round( screen.width * 0.1 );
57                        }
58                        catch ( e ){}
59
60                        var sOpenUrl = '';
61                        if ( isCustomDomain )
62                        {
63                                window._cke_htmlToLoad = sHTML;
64                                sOpenUrl = 'javascript:void( (function(){' +
65                                        'document.open();' +
66                                        'document.domain="' + document.domain + '";' +
67                                        'document.write( window.opener._cke_htmlToLoad );' +
68                                        'document.close();' +
69                                        'window.opener._cke_htmlToLoad = null;' +
70                                        '})() )';
71                        }
72
73                        var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +
74                                iWidth + ',height=' + iHeight + ',left=' + iLeft );
75
76                        if ( !isCustomDomain )
77                        {
78                                oWindow.document.write( sHTML );
79                                oWindow.document.close();
80                        }
81                }
82        };
83
84        var pluginName = 'preview';
85
86        // Register a plugin named "preview".
87        CKEDITOR.plugins.add( pluginName,
88        {
89                init : function( editor )
90                {
91                        editor.addCommand( pluginName, previewCmd );
92                        editor.ui.addButton( 'Preview',
93                                {
94                                        label : editor.lang.preview,
95                                        command : pluginName
96                                });
97                }
98        });
99})();
Note: See TracBrowser for help on using the repository browser.