]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/fakeobjects/plugin.js
a054a99f41c04d0c618e9a86df2291373eb8d961
2 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 var cssStyle
= CKEDITOR
.htmlParser
.cssStyle
,
8 cssLength
= CKEDITOR
.tools
.cssLength
;
10 var cssLengthRegex
= /^((?:\d*(?:\.\d+))|(?:\d+))(.*)?$/i;
12 // Replacing the former CSS length value with the later one, with
13 // adjustment to the length unit.
14 function replaceCssLength( length1
, length2
) {
15 var parts1
= cssLengthRegex
.exec( length1
),
16 parts2
= cssLengthRegex
.exec( length2
);
18 // Omit pixel length unit when necessary,
19 // e.g. replaceCssLength( 10, '20px' ) -> 20
21 if ( !parts1
[ 2 ] && parts2
[ 2 ] == 'px' )
23 if ( parts1
[ 2 ] == 'px' && !parts2
[ 2 ] )
24 return parts2
[ 1 ] + 'px';
30 var htmlFilterRules
= {
32 $: function( element
) {
33 var attributes
= element
.attributes
,
34 realHtml
= attributes
&& attributes
[ 'data-cke-realelement' ],
35 realFragment
= realHtml
&& new CKEDITOR
.htmlParser
.fragment
.fromHtml( decodeURIComponent( realHtml
) ),
36 realElement
= realFragment
&& realFragment
.children
[ 0 ];
38 // Width/height in the fake object are subjected to clone into the real element.
39 if ( realElement
&& element
.attributes
[ 'data-cke-resizable' ] ) {
40 var styles
= new cssStyle( element
).rules
,
41 realAttrs
= realElement
.attributes
,
43 height
= styles
.height
;
45 width
&& ( realAttrs
.width
= replaceCssLength( realAttrs
.width
, width
) );
46 height
&& ( realAttrs
.height
= replaceCssLength( realAttrs
.height
, height
) );
54 CKEDITOR
.plugins
.add( 'fakeobjects', {
55 // jscs:disable maximumLineLength
56 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%
57 // jscs:enable maximumLineLength
59 init: function( editor
) {
60 // Allow image with all styles and classes plus src, alt and title attributes.
61 // We need them when fakeobject is pasted.
62 editor
.filter
.allow( 'img[!data-cke-realelement,src,alt,title](*){*}', 'fakeobjects' );
65 afterInit: function( editor
) {
66 var dataProcessor
= editor
.dataProcessor
,
67 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
70 htmlFilter
.addRules( htmlFilterRules
, {
78 * @member CKEDITOR.editor
81 CKEDITOR
.editor
.prototype.createFakeElement = function( realElement
, className
, realElementType
, isResizable
) {
82 var lang
= this.lang
.fakeobjects
,
83 label
= lang
[ realElementType
] || lang
.unknown
;
87 'data-cke-realelement': encodeURIComponent( realElement
.getOuterHtml() ),
88 'data-cke-real-node-type': realElement
.type
,
91 align: realElement
.getAttribute( 'align' ) || ''
94 // Do not set "src" on high-contrast so the alt text is displayed. (#8945)
95 if ( !CKEDITOR
.env
.hc
)
96 attributes
.src
= CKEDITOR
.tools
.transparentImageData
;
98 if ( realElementType
)
99 attributes
[ 'data-cke-real-element-type' ] = realElementType
;
102 attributes
[ 'data-cke-resizable' ] = isResizable
;
104 var fakeStyle
= new cssStyle();
106 var width
= realElement
.getAttribute( 'width' ),
107 height
= realElement
.getAttribute( 'height' );
109 width
&& ( fakeStyle
.rules
.width
= cssLength( width
) );
110 height
&& ( fakeStyle
.rules
.height
= cssLength( height
) );
111 fakeStyle
.populate( attributes
);
114 return this.document
.createElement( 'img', { attributes: attributes
} );
118 * @member CKEDITOR.editor
121 CKEDITOR
.editor
.prototype.createFakeParserElement = function( realElement
, className
, realElementType
, isResizable
) {
122 var lang
= this.lang
.fakeobjects
,
123 label
= lang
[ realElementType
] || lang
.unknown
,
126 var writer
= new CKEDITOR
.htmlParser
.basicWriter();
127 realElement
.writeHtml( writer
);
128 html
= writer
.getHtml();
132 'data-cke-realelement': encodeURIComponent( html
),
133 'data-cke-real-node-type': realElement
.type
,
136 align: realElement
.attributes
.align
|| ''
139 // Do not set "src" on high-contrast so the alt text is displayed. (#8945)
140 if ( !CKEDITOR
.env
.hc
)
141 attributes
.src
= CKEDITOR
.tools
.transparentImageData
;
143 if ( realElementType
)
144 attributes
[ 'data-cke-real-element-type' ] = realElementType
;
147 attributes
[ 'data-cke-resizable' ] = isResizable
;
148 var realAttrs
= realElement
.attributes
,
149 fakeStyle
= new cssStyle();
151 var width
= realAttrs
.width
,
152 height
= realAttrs
.height
;
154 width
!== undefined && ( fakeStyle
.rules
.width
= cssLength( width
) );
155 height
!== undefined && ( fakeStyle
.rules
.height
= cssLength( height
) );
156 fakeStyle
.populate( attributes
);
159 return new CKEDITOR
.htmlParser
.element( 'img', attributes
);
163 * @member CKEDITOR.editor
166 CKEDITOR
.editor
.prototype.restoreRealElement = function( fakeElement
) {
167 if ( fakeElement
.data( 'cke-real-node-type' ) != CKEDITOR
.NODE_ELEMENT
)
170 var element
= CKEDITOR
.dom
.element
.createFromHtml( decodeURIComponent( fakeElement
.data( 'cke-realelement' ) ), this.document
);
172 if ( fakeElement
.data( 'cke-resizable' ) ) {
173 var width
= fakeElement
.getStyle( 'width' ),
174 height
= fakeElement
.getStyle( 'height' );
176 width
&& element
.setAttribute( 'width', replaceCssLength( element
.getAttribute( 'width' ), width
) );
177 height
&& element
.setAttribute( 'height', replaceCssLength( element
.getAttribute( 'height' ), height
) );