1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5
  6 (function()
  7 {
  8 	var htmlFilterRules =
  9 	{
 10 		elements :
 11 		{
 12 			$ : function( element, filter )
 13 			{
 14 				var realHtml = element.attributes._cke_realelement;
 15 					realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ), filter ),
 16 					realElement = realFragment && realFragment.children[ 0 ];
 17
 18 				if ( realElement )
 19 				{
 20 					// If we have width/height in the element, we must move it into
 21 					// the real element.
 22
 23 					var style = element.attributes.style;
 24
 25 					if ( style )
 26 					{
 27 						// Get the width from the style.
 28 						var match = /(?:^|\s)width\s*:\s*(\d+)/.exec( style ),
 29 							width = match && match[1];
 30
 31 						// Get the height from the style.
 32 						match = /(?:^|\s)height\s*:\s*(\d+)/.exec( style );
 33 						var height = match && match[1];
 34
 35 						if ( width )
 36 							realElement.attributes.width = width;
 37
 38 						if ( height )
 39 							realElement.attributes.height = height;
 40 					}
 41 				}
 42
 43 				return realElement;
 44 			}
 45 		}
 46 	};
 47
 48 	CKEDITOR.plugins.add( 'fakeobjects',
 49 	{
 50 		requires : [ 'htmlwriter' ],
 51
 52 		afterInit : function( editor )
 53 		{
 54 			var dataProcessor = editor.dataProcessor,
 55 				htmlFilter = dataProcessor && dataProcessor.htmlFilter;
 56
 57 			if ( htmlFilter )
 58 				htmlFilter.addRules( htmlFilterRules );
 59 		}
 60 	});
 61 })();
 62
 63 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
 64 {
 65 	var attributes =
 66 	{
 67 		'class' : className,
 68 		src : CKEDITOR.getUrl( 'images/spacer.gif' ),
 69 		_cke_realelement : encodeURIComponent( realElement.getOuterHtml() )
 70 	};
 71 	if ( realElementType )
 72 		attributes._cke_real_element_type = realElementType;
 73 	if ( isResizable )
 74 		attributes._cke_resizable = isResizable;
 75
 76 	return this.document.createElement( 'img', { attributes : attributes } );
 77 };
 78
 79 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
 80 {
 81 	var writer = new CKEDITOR.htmlParser.basicWriter();
 82
 83 	realElement.writeHtml( writer );
 84
 85 	var html = writer.getHtml();
 86
 87 	var attributes =
 88 	{
 89 		'class' : className,
 90 		src : CKEDITOR.getUrl( 'images/spacer.gif' ),
 91 		_cke_realelement : encodeURIComponent( html )
 92 	};
 93
 94 	if ( realElementType )
 95 		attributes._cke_real_element_type = realElementType;
 96
 97 	if ( isResizable )
 98 		attributes._cke_resizable = isResizable;
 99
100 	return new CKEDITOR.htmlParser.element( 'img', attributes );
101 };
102
103 CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
104 {
105 	var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) );
106 	return CKEDITOR.dom.element.createFromHtml( html, this.document );
107 };
108