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