]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/preview/plugin.js
7299999aef1834c0f8f2478c8dd2486f0f85f48c
2 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 * @fileOverview Preview plugin.
13 var previewCmd
= { modes: { wysiwyg: 1, source: 1 },
16 exec: function( editor
) {
18 config
= editor
.config
,
19 baseTag
= config
.baseHref
? '<base href="' + config
.baseHref
+ '"/>' : '',
22 if ( config
.fullPage
)
23 sHTML
= editor
.getData().replace( /<head>/, '$&' + baseTag
).replace( /[^>]*(?=<\/title>)/, '$& — ' + editor
.lang
.preview
.preview
);
25 var bodyHtml
= '<body ',
26 body
= editor
.document
&& editor
.document
.getBody();
29 if ( body
.getAttribute( 'id' ) )
30 bodyHtml
+= 'id="' + body
.getAttribute( 'id' ) + '" ';
31 if ( body
.getAttribute( 'class' ) )
32 bodyHtml
+= 'class="' + body
.getAttribute( 'class' ) + '" ';
37 sHTML
= editor
.config
.docType
+ '<html dir="' + editor
.config
.contentsLangDirection
+ '">' +
40 '<title>' + editor
.lang
.preview
.preview
+ '</title>' +
41 CKEDITOR
.tools
.buildStyleHtml( editor
.config
.contentsCss
) +
42 '</head>' + bodyHtml
+
51 iLeft
= 80; // (800 - 0.8 * 800) /2 = 800 * 0.1.
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 );
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 )
67 if ( CKEDITOR
.env
.ie
) {
68 window
._cke_htmlToLoad
= eventData
.dataValue
;
69 ieLocation
= 'javascript:void( (function(){' + // jshint ignore:line
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 );' +
76 'window.opener._cke_htmlToLoad = null;' +
78 // For IE we should use window.location rather than setting url in window.open. (#11146)
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' );
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
);
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
;
97 if ( !CKEDITOR
.env
.ie
&& !CKEDITOR
.env
.gecko
) {
98 var doc
= oWindow
.document
;
100 doc
.write( eventData
.dataValue
);
108 var pluginName
= 'preview';
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
) {
119 // Preview is not used for the inline creator.
120 if ( editor
.elementMode
== CKEDITOR
.ELEMENT_MODE_INLINE
)
123 pluginPath
= this.path
;
125 editor
.addCommand( pluginName
, previewCmd
);
126 editor
.ui
.addButton
&& editor
.ui
.addButton( 'Preview', {
127 label: editor
.lang
.preview
.preview
,
129 toolbar: 'document,40'
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
140 * @event contentPreview
142 * @param {CKEDITOR.editor} editor This editor instance.
144 * @param {String} data.dataValue The data that will go to the preview.