diff options
| author | lsces <lester@lsces.co.uk> | 2012-06-10 19:03:48 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2012-06-10 19:03:48 +0100 |
| commit | f3ce03a71d3dd1c7dcbe474197fb1588949735db (patch) | |
| tree | 7c31cd62ef0e2790966f96498e553f22fa4e08d3 /_source/plugins/fakeobjects/plugin.js | |
| parent | 23b8cf2a890c7de389616702fd23c9c465311a59 (diff) | |
| download | ckeditor-f3ce03a71d3dd1c7dcbe474197fb1588949735db.tar.gz ckeditor-f3ce03a71d3dd1c7dcbe474197fb1588949735db.tar.bz2 ckeditor-f3ce03a71d3dd1c7dcbe474197fb1588949735db.zip | |
Update to CKEditor version 3.6.3
Diffstat (limited to '_source/plugins/fakeobjects/plugin.js')
| -rw-r--r-- | _source/plugins/fakeobjects/plugin.js | 297 |
1 files changed, 175 insertions, 122 deletions
diff --git a/_source/plugins/fakeobjects/plugin.js b/_source/plugins/fakeobjects/plugin.js index bb21062..f55922a 100644 --- a/_source/plugins/fakeobjects/plugin.js +++ b/_source/plugins/fakeobjects/plugin.js @@ -1,122 +1,175 @@ -/* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. -For licensing, see LICENSE.html or http://ckeditor.com/license -*/ - -(function() -{ - var htmlFilterRules = - { - elements : - { - $ : function( element ) - { - var attributes = element.attributes, - realHtml = attributes && attributes._cke_realelement, - realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ), - realElement = realFragment && realFragment.children[ 0 ]; - - // If we have width/height in the element, we must move it into - // the real element. - if ( realElement && element.attributes._cke_resizable ) - { - var style = element.attributes.style; - - if ( style ) - { - // Get the width from the style. - var match = /(?:^|\s)width\s*:\s*(\d+)/i.exec( style ), - width = match && match[1]; - - // Get the height from the style. - match = /(?:^|\s)height\s*:\s*(\d+)/i.exec( style ); - var height = match && match[1]; - - if ( width ) - realElement.attributes.width = width; - - if ( height ) - realElement.attributes.height = height; - } - } - - return realElement; - } - } - }; - - CKEDITOR.plugins.add( 'fakeobjects', - { - requires : [ 'htmlwriter' ], - - afterInit : function( editor ) - { - var dataProcessor = editor.dataProcessor, - htmlFilter = dataProcessor && dataProcessor.htmlFilter; - - if ( htmlFilter ) - htmlFilter.addRules( htmlFilterRules ); - } - }); -})(); - -CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable ) -{ - var lang = this.lang.fakeobjects; - - var attributes = - { - 'class' : className, - src : CKEDITOR.getUrl( 'images/spacer.gif' ), - _cke_realelement : encodeURIComponent( realElement.getOuterHtml() ), - _cke_real_node_type : realElement.type, - alt : lang[ realElementType ] || lang.unknown, - align : realElement.getAttribute( 'align' ) || '' - }; - - if ( realElementType ) - attributes._cke_real_element_type = realElementType; - - if ( isResizable ) - attributes._cke_resizable = isResizable; - - return this.document.createElement( 'img', { attributes : attributes } ); -}; - -CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable ) -{ - var lang = this.lang.fakeobjects, - html; - - var writer = new CKEDITOR.htmlParser.basicWriter(); - realElement.writeHtml( writer ); - html = writer.getHtml(); - - var attributes = - { - 'class' : className, - src : CKEDITOR.getUrl( 'images/spacer.gif' ), - _cke_realelement : encodeURIComponent( html ), - _cke_real_node_type : realElement.type, - alt : lang[ realElementType ] || lang.unknown, - align : realElement.attributes.align || '' - }; - - if ( realElementType ) - attributes._cke_real_element_type = realElementType; - - if ( isResizable ) - attributes._cke_resizable = isResizable; - - return new CKEDITOR.htmlParser.element( 'img', attributes ); -}; - -CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement ) -{ - if ( fakeElement.getAttribute( '_cke_real_node_type' ) != CKEDITOR.NODE_ELEMENT ) - return null; - - return CKEDITOR.dom.element.createFromHtml( - decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) ), - this.document ); -}; +/*
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
+For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+
+(function()
+{
+ var cssStyle = CKEDITOR.htmlParser.cssStyle,
+ cssLength = CKEDITOR.tools.cssLength;
+
+ var cssLengthRegex = /^((?:\d*(?:\.\d+))|(?:\d+))(.*)?$/i;
+
+ /*
+ * Replacing the former CSS length value with the later one, with
+ * adjustment to the length unit.
+ */
+ function replaceCssLength( length1, length2 )
+ {
+ var parts1 = cssLengthRegex.exec( length1 ),
+ parts2 = cssLengthRegex.exec( length2 );
+
+ // Omit pixel length unit when necessary,
+ // e.g. replaceCssLength( 10, '20px' ) -> 20
+ if ( parts1 )
+ {
+ if ( !parts1[ 2 ] && parts2[ 2 ] == 'px' )
+ return parts2[ 1 ];
+ if ( parts1[ 2 ] == 'px' && !parts2[ 2 ] )
+ return parts2[ 1 ] + 'px';
+ }
+
+ return length2;
+ }
+
+ var htmlFilterRules =
+ {
+ elements :
+ {
+ $ : function( element )
+ {
+ var attributes = element.attributes,
+ realHtml = attributes && attributes[ 'data-cke-realelement' ],
+ realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
+ realElement = realFragment && realFragment.children[ 0 ];
+
+ // Width/height in the fake object are subjected to clone into the real element.
+ 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;
+ }
+ }
+ };
+
+ CKEDITOR.plugins.add( 'fakeobjects',
+ {
+ requires : [ 'htmlwriter' ],
+
+ afterInit : function( editor )
+ {
+ var dataProcessor = editor.dataProcessor,
+ htmlFilter = dataProcessor && dataProcessor.htmlFilter;
+
+ if ( htmlFilter )
+ htmlFilter.addRules( htmlFilterRules );
+ }
+ });
+
+ CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
+ {
+ var lang = this.lang.fakeobjects,
+ label = lang[ realElementType ] || lang.unknown;
+
+ var attributes =
+ {
+ 'class' : className,
+ src : CKEDITOR.getUrl( 'images/spacer.gif' ),
+ 'data-cke-realelement' : encodeURIComponent( realElement.getOuterHtml() ),
+ 'data-cke-real-node-type' : realElement.type,
+ alt : label,
+ title : label,
+ align : realElement.getAttribute( 'align' ) || ''
+ };
+
+ 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,
+ src : CKEDITOR.getUrl( 'images/spacer.gif' ),
+ 'data-cke-realelement' : encodeURIComponent( html ),
+ 'data-cke-real-node-type' : realElement.type,
+ alt : label,
+ title : label,
+ align : realElement.attributes.align || ''
+ };
+
+ 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 element = CKEDITOR.dom.element.createFromHtml(
+ decodeURIComponent( fakeElement.data( 'cke-realelement' ) ),
+ this.document );
+
+ if ( fakeElement.data( 'cke-resizable') )
+ {
+ var width = fakeElement.getStyle( 'width' ),
+ height = fakeElement.getStyle( 'height' );
+
+ width && element.setAttribute( 'width', replaceCssLength( element.getAttribute( 'width' ), width ) );
+ height && element.setAttribute( 'height', replaceCssLength( element.getAttribute( 'height' ), height ) );
+ }
+
+ return element;
+ };
+
+})();
|
