Blame view

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