Nation Notes module contributed by Z&H Healthcare.
[openemr.git] / library / custom_template / ckeditor / _source / plugins / preview / plugin.js
blob517addb6201514894077dd64cfc1d68ae40042fd
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 /**
7  * @file Preview plugin.
8  */
10 (function()
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();
23                         if ( config.fullPage )
24                         {
25                                 sHTML = editor.getData()
26                                                 .replace( /<head>/, '$&' + baseTag )
27                                                 .replace( /[^>]*(?=<\/title>)/, '$& &mdash; ' + editor.lang.preview );
28                         }
29                         else
30                         {
31                                 var bodyHtml = '<body ',
32                                                 body = editor.document && editor.document.getBody();
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                                 }
42                                 bodyHtml += '>';
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                         }
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 ){}
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                         }
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 );
84                         if ( !isCustomDomain )
85                         {
86                                 oWindow.document.open();
87                                 oWindow.document.write( sHTML );
88                                 oWindow.document.close();
89                         }
90                 }
91         };
93         var pluginName = 'preview';
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 })();