]>
Commit | Line | Data |
---|---|---|
7adcb81e | 1 | /**\r |
3b35bd27 | 2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.\r |
7adcb81e IB |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license\r |
4 | */\r | |
5 | \r | |
6 | /**\r | |
7 | * @fileOverview Preview plugin.\r | |
8 | */\r | |
9 | \r | |
10 | ( function() {\r | |
11 | var pluginPath;\r | |
12 | \r | |
13 | var previewCmd = { modes: { wysiwyg: 1, source: 1 },\r | |
14 | canUndo: false,\r | |
15 | readOnly: 1,\r | |
16 | exec: function( editor ) {\r | |
17 | var sHTML,\r | |
18 | config = editor.config,\r | |
19 | baseTag = config.baseHref ? '<base href="' + config.baseHref + '"/>' : '',\r | |
20 | eventData;\r | |
21 | \r | |
22 | if ( config.fullPage )\r | |
23 | sHTML = editor.getData().replace( /<head>/, '$&' + baseTag ).replace( /[^>]*(?=<\/title>)/, '$& — ' + editor.lang.preview.preview );\r | |
24 | else {\r | |
25 | var bodyHtml = '<body ',\r | |
26 | body = editor.document && editor.document.getBody();\r | |
27 | \r | |
28 | if ( body ) {\r | |
29 | if ( body.getAttribute( 'id' ) )\r | |
30 | bodyHtml += 'id="' + body.getAttribute( 'id' ) + '" ';\r | |
31 | if ( body.getAttribute( 'class' ) )\r | |
32 | bodyHtml += 'class="' + body.getAttribute( 'class' ) + '" ';\r | |
33 | }\r | |
34 | \r | |
35 | bodyHtml += '>';\r | |
36 | \r | |
37 | sHTML = editor.config.docType + '<html dir="' + editor.config.contentsLangDirection + '">' +\r | |
38 | '<head>' +\r | |
39 | baseTag +\r | |
40 | '<title>' + editor.lang.preview.preview + '</title>' +\r | |
41 | CKEDITOR.tools.buildStyleHtml( editor.config.contentsCss ) +\r | |
42 | '</head>' + bodyHtml +\r | |
43 | editor.getData() +\r | |
44 | '</body></html>';\r | |
45 | }\r | |
46 | \r | |
47 | var iWidth = 640,\r | |
48 | // 800 * 0.8,\r | |
49 | iHeight = 420,\r | |
50 | // 600 * 0.7,\r | |
51 | iLeft = 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.\r | |
52 | try {\r | |
53 | var screen = window.screen;\r | |
54 | iWidth = Math.round( screen.width * 0.8 );\r | |
55 | iHeight = Math.round( screen.height * 0.7 );\r | |
56 | iLeft = Math.round( screen.width * 0.1 );\r | |
57 | } catch ( e ) {}\r | |
58 | \r | |
59 | // (#9907) Allow data manipulation before preview is displayed.\r | |
60 | // Also don't open the preview window when event cancelled.\r | |
61 | if ( editor.fire( 'contentPreview', eventData = { dataValue: sHTML } ) === false )\r | |
62 | return false;\r | |
63 | \r | |
64 | var sOpenUrl = '',\r | |
65 | ieLocation;\r | |
66 | \r | |
67 | if ( CKEDITOR.env.ie ) {\r | |
68 | window._cke_htmlToLoad = eventData.dataValue;\r | |
69 | ieLocation = 'javascript:void( (function(){' + // jshint ignore:line\r | |
70 | 'document.open();' +\r | |
71 | // Support for custom document.domain.\r | |
72 | // Strip comments and replace parent with window.opener in the function body.\r | |
73 | ( '(' + CKEDITOR.tools.fixDomain + ')();' ).replace( /\/\/.*?\n/g, '' ).replace( /parent\./g, 'window.opener.' ) +\r | |
74 | 'document.write( window.opener._cke_htmlToLoad );' +\r | |
75 | 'document.close();' +\r | |
76 | 'window.opener._cke_htmlToLoad = null;' +\r | |
77 | '})() )';\r | |
78 | // For IE we should use window.location rather than setting url in window.open. (#11146)\r | |
79 | sOpenUrl = '';\r | |
80 | }\r | |
81 | \r | |
82 | // With Firefox only, we need to open a special preview page, so\r | |
83 | // anchors will work properly on it. (#9047)\r | |
84 | if ( CKEDITOR.env.gecko ) {\r | |
85 | window._cke_htmlToLoad = eventData.dataValue;\r | |
86 | sOpenUrl = CKEDITOR.getUrl( pluginPath + 'preview.html' );\r | |
87 | }\r | |
88 | \r | |
89 | var oWindow = window.open( sOpenUrl, null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' +\r | |
90 | iWidth + ',height=' + iHeight + ',left=' + iLeft );\r | |
91 | \r | |
92 | // For IE we want to assign whole js stored in ieLocation, but in case of\r | |
93 | // popup blocker activation oWindow variable will be null. (#11597)\r | |
94 | if ( CKEDITOR.env.ie && oWindow )\r | |
95 | oWindow.location = ieLocation;\r | |
96 | \r | |
97 | if ( !CKEDITOR.env.ie && !CKEDITOR.env.gecko ) {\r | |
98 | var doc = oWindow.document;\r | |
99 | doc.open();\r | |
100 | doc.write( eventData.dataValue );\r | |
101 | doc.close();\r | |
102 | }\r | |
103 | \r | |
104 | return true;\r | |
105 | }\r | |
106 | };\r | |
107 | \r | |
108 | var pluginName = 'preview';\r | |
109 | \r | |
110 | // Register a plugin named "preview".\r | |
111 | CKEDITOR.plugins.add( pluginName, {\r | |
112 | // jscs:disable maximumLineLength\r | |
3b35bd27 | 113 | lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%\r |
7adcb81e IB |
114 | // jscs:enable maximumLineLength\r |
115 | icons: 'preview,preview-rtl', // %REMOVE_LINE_CORE%\r | |
116 | hidpi: true, // %REMOVE_LINE_CORE%\r | |
117 | init: function( editor ) {\r | |
118 | \r | |
119 | // Preview is not used for the inline creator.\r | |
120 | if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE )\r | |
121 | return;\r | |
122 | \r | |
123 | pluginPath = this.path;\r | |
124 | \r | |
125 | editor.addCommand( pluginName, previewCmd );\r | |
126 | editor.ui.addButton && editor.ui.addButton( 'Preview', {\r | |
127 | label: editor.lang.preview.preview,\r | |
128 | command: pluginName,\r | |
129 | toolbar: 'document,40'\r | |
130 | } );\r | |
131 | }\r | |
132 | } );\r | |
133 | } )();\r | |
134 | \r | |
135 | /**\r | |
136 | * Event fired when executing `preview` command, which allows additional data manipulation.\r | |
137 | * With this event, the raw HTML content of the preview window to be displayed can be altered\r | |
138 | * or modified.\r | |
139 | *\r | |
140 | * @event contentPreview\r | |
141 | * @member CKEDITOR\r | |
142 | * @param {CKEDITOR.editor} editor This editor instance.\r | |
143 | * @param data\r | |
144 | * @param {String} data.dataValue The data that will go to the preview.\r | |
145 | */\r |