source: trunk/admin/inc/ckeditor/_source/plugins/preview/plugin.js@ 430

Last change on this file since 430 was 239, checked in by luc, 9 years ago

Admin: correzione visulaizzazione immissione dati spoglio per Chrome e Safari - Aggiornamento dell'editor da FCKeditor a CKeditor , accessibili anche a Chrome e Safari.

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