diff options
| author | Lester Caine <lester@lsces.co.uk> | 2009-11-24 23:57:24 +0000 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2009-11-24 23:57:24 +0000 |
| commit | 8630f2bc4d63b3320f5469d9532a1cba1dddb7a3 (patch) | |
| tree | f3c3122e110458a94aae544164b82fd67f1ae5e0 /_source/plugins/fakeobjects/plugin.js | |
| parent | e24cb83aa7f7685a4811e5c8d39541bae7b15cb2 (diff) | |
| download | ckeditor-8630f2bc4d63b3320f5469d9532a1cba1dddb7a3.tar.gz ckeditor-8630f2bc4d63b3320f5469d9532a1cba1dddb7a3.tar.bz2 ckeditor-8630f2bc4d63b3320f5469d9532a1cba1dddb7a3.zip | |
ckeditor 3.0.1 'raw' - needs reordering a little, but samples currently functional
Diffstat (limited to '_source/plugins/fakeobjects/plugin.js')
| -rw-r--r-- | _source/plugins/fakeobjects/plugin.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/_source/plugins/fakeobjects/plugin.js b/_source/plugins/fakeobjects/plugin.js new file mode 100644 index 0000000..8d761ab --- /dev/null +++ b/_source/plugins/fakeobjects/plugin.js @@ -0,0 +1,111 @@ +/* +Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ + +(function() +{ + var htmlFilterRules = + { + elements : + { + $ : function( element ) + { + var realHtml = element.attributes._cke_realelement, + realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ), + realElement = realFragment && realFragment.children[ 0 ]; + + if ( realElement ) + { + // If we have width/height in the element, we must move it into + // the real element. + + var style = element.attributes.style; + + if ( style ) + { + // Get the width from the style. + var match = /(?:^|\s)width\s*:\s*(\d+)/.exec( style ), + width = match && match[1]; + + // Get the height from the style. + match = /(?:^|\s)height\s*:\s*(\d+)/.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() ), + alt : lang[ realElementType ] || lang.unknown + }; + 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 writer = new CKEDITOR.htmlParser.basicWriter(); + + realElement.writeHtml( writer ); + + var html = writer.getHtml(); + var lang = this.lang.fakeobjects; + + var attributes = + { + 'class' : className, + src : CKEDITOR.getUrl( 'images/spacer.gif' ), + _cke_realelement : encodeURIComponent( html ), + alt : lang[ realElementType ] || lang.unknown + }; + + 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 ) +{ + var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) ); + return CKEDITOR.dom.element.createFromHtml( html, this.document ); +}; |
