123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
-
- ( function() {
- var cssStyle = CKEDITOR.htmlParser.cssStyle,
- cssLength = CKEDITOR.tools.cssLength;
- var cssLengthRegex = /^((?:\d*(?:\.\d+))|(?:\d+))(.*)?$/i;
-
-
- function replaceCssLength( length1, length2 ) {
- var parts1 = cssLengthRegex.exec( length1 ),
- parts2 = cssLengthRegex.exec( length2 );
-
-
- if ( parts1 ) {
- if ( !parts1[ 2 ] && parts2[ 2 ] == 'px' )
- return parts2[ 1 ];
- if ( parts1[ 2 ] == 'px' && !parts2[ 2 ] )
- return parts2[ 1 ] + 'px';
- }
- return length2;
- }
- CKEDITOR.plugins.add( 'fakeobjects', {
-
- lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,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,oc,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn',
-
- init: function( editor ) {
-
-
- editor.filter.allow( 'img[!data-cke-realelement,src,alt,title](*){*}', 'fakeobjects' );
- },
- afterInit: function( editor ) {
- var dataProcessor = editor.dataProcessor,
- htmlFilter = dataProcessor && dataProcessor.htmlFilter;
- if ( htmlFilter ) {
- htmlFilter.addRules( createHtmlFilterRules( editor ), {
- applyToAll: true
- } );
- }
- }
- } );
-
- CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable ) {
- var lang = this.lang.fakeobjects,
- label = lang[ realElementType ] || lang.unknown;
- var attributes = {
- 'class': className,
- 'data-cke-realelement': encodeURIComponent( realElement.getOuterHtml() ),
- 'data-cke-real-node-type': realElement.type,
- alt: label,
- title: label,
- align: realElement.getAttribute( 'align' ) || ''
- };
-
- if ( !CKEDITOR.env.hc )
- attributes.src = CKEDITOR.tools.transparentImageData;
- if ( realElementType )
- attributes[ 'data-cke-real-element-type' ] = realElementType;
- if ( isResizable ) {
- attributes[ 'data-cke-resizable' ] = isResizable;
- var fakeStyle = new cssStyle();
- var width = realElement.getAttribute( 'width' ),
- height = realElement.getAttribute( 'height' );
- width && ( fakeStyle.rules.width = cssLength( width ) );
- height && ( fakeStyle.rules.height = cssLength( height ) );
- fakeStyle.populate( attributes );
- }
- return this.document.createElement( 'img', { attributes: attributes } );
- };
-
- CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable ) {
- var lang = this.lang.fakeobjects,
- label = lang[ realElementType ] || lang.unknown,
- html;
- var writer = new CKEDITOR.htmlParser.basicWriter();
- realElement.writeHtml( writer );
- html = writer.getHtml();
- var attributes = {
- 'class': className,
- 'data-cke-realelement': encodeURIComponent( html ),
- 'data-cke-real-node-type': realElement.type,
- alt: label,
- title: label,
- align: realElement.attributes.align || ''
- };
-
- if ( !CKEDITOR.env.hc )
- attributes.src = CKEDITOR.tools.transparentImageData;
- if ( realElementType )
- attributes[ 'data-cke-real-element-type' ] = realElementType;
- if ( isResizable ) {
- attributes[ 'data-cke-resizable' ] = isResizable;
- var realAttrs = realElement.attributes,
- fakeStyle = new cssStyle();
- var width = realAttrs.width,
- height = realAttrs.height;
- width !== undefined && ( fakeStyle.rules.width = cssLength( width ) );
- height !== undefined && ( fakeStyle.rules.height = cssLength( height ) );
- fakeStyle.populate( attributes );
- }
- return new CKEDITOR.htmlParser.element( 'img', attributes );
- };
-
- CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement ) {
- if ( fakeElement.data( 'cke-real-node-type' ) != CKEDITOR.NODE_ELEMENT )
- return null;
- var realElementHtml = decodeURIComponent( fakeElement.data( 'cke-realelement' ) ),
- filteredHtml = filterHtml( this, realElementHtml ),
- realElement = CKEDITOR.dom.element.createFromHtml( filteredHtml, this.document );
- if ( fakeElement.data( 'cke-resizable' ) ) {
- var width = fakeElement.getStyle( 'width' ),
- height = fakeElement.getStyle( 'height' );
- width && realElement.setAttribute( 'width', replaceCssLength( realElement.getAttribute( 'width' ), width ) );
- height && realElement.setAttribute( 'height', replaceCssLength( realElement.getAttribute( 'height' ), height ) );
- }
- return realElement;
- };
- function createHtmlFilterRules( editor ) {
- return {
- elements: {
- $: function( element ) {
- var attributes = element.attributes,
- realHtml = attributes && attributes[ 'data-cke-realelement' ],
- filteredRealHtml = filterHtml( editor, decodeURIComponent( realHtml ) ),
- realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( filteredRealHtml ),
- realElement = realFragment && realFragment.children[ 0 ];
-
- if ( realElement && element.attributes[ 'data-cke-resizable' ] ) {
- var styles = new cssStyle( element ).rules,
- realAttrs = realElement.attributes,
- width = styles.width,
- height = styles.height;
- width && ( realAttrs.width = replaceCssLength( realAttrs.width, width ) );
- height && ( realAttrs.height = replaceCssLength( realAttrs.height, height ) );
- }
- return realElement;
- }
- }
- };
- }
-
-
-
- function filterHtml( editor, html ) {
- var unprefixedElements = [],
- prefixRegex = /^cke:/i,
- dataFilter = new CKEDITOR.htmlParser.filter( {
- elements: {
- '^': function( element ) {
- if ( prefixRegex.test( element.name ) ) {
- element.name = element.name.replace( prefixRegex, '' );
- unprefixedElements.push( element );
- }
- },
- iframe: function( element ) {
- element.children = [];
- }
- }
- } ),
- acfFilter = editor.activeFilter,
- writer = new CKEDITOR.htmlParser.basicWriter(),
- fragment = CKEDITOR.htmlParser.fragment.fromHtml( html );
- dataFilter.applyTo( fragment );
- acfFilter.applyTo( fragment );
- CKEDITOR.tools.array.forEach( unprefixedElements, function( element ) {
- element.name = 'cke:' + element.name;
- } );
- fragment.writeHtml( writer );
- return writer.getHtml();
- }
- } )();
|