[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, 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 )
|
---|
| 13 | {
|
---|
| 14 | var attributes = element.attributes,
|
---|
| 15 | realHtml = attributes && attributes._cke_realelement,
|
---|
| 16 | realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
|
---|
| 17 | realElement = realFragment && realFragment.children[ 0 ];
|
---|
| 18 |
|
---|
| 19 | // If we have width/height in the element, we must move it into
|
---|
| 20 | // the real element.
|
---|
| 21 | if ( realElement && element.attributes._cke_resizable )
|
---|
| 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+)/i.exec( style ),
|
---|
| 29 | width = match && match[1];
|
---|
| 30 |
|
---|
| 31 | // Get the height from the style.
|
---|
| 32 | match = /(?:^|\s)height\s*:\s*(\d+)/i.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 lang = this.lang.fakeobjects;
|
---|
| 66 |
|
---|
| 67 | var attributes =
|
---|
| 68 | {
|
---|
| 69 | 'class' : className,
|
---|
| 70 | src : CKEDITOR.getUrl( 'images/spacer.gif' ),
|
---|
| 71 | _cke_realelement : encodeURIComponent( realElement.getOuterHtml() ),
|
---|
| 72 | _cke_real_node_type : realElement.type,
|
---|
| 73 | alt : lang[ realElementType ] || lang.unknown
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | if ( realElementType )
|
---|
| 77 | attributes._cke_real_element_type = realElementType;
|
---|
| 78 |
|
---|
| 79 | if ( isResizable )
|
---|
| 80 | attributes._cke_resizable = isResizable;
|
---|
| 81 |
|
---|
| 82 | return this.document.createElement( 'img', { attributes : attributes } );
|
---|
| 83 | };
|
---|
| 84 |
|
---|
| 85 | CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
|
---|
| 86 | {
|
---|
| 87 | var lang = this.lang.fakeobjects,
|
---|
| 88 | html;
|
---|
| 89 |
|
---|
| 90 | var writer = new CKEDITOR.htmlParser.basicWriter();
|
---|
| 91 | realElement.writeHtml( writer );
|
---|
| 92 | html = writer.getHtml();
|
---|
| 93 |
|
---|
| 94 | var attributes =
|
---|
| 95 | {
|
---|
| 96 | 'class' : className,
|
---|
| 97 | src : CKEDITOR.getUrl( 'images/spacer.gif' ),
|
---|
| 98 | _cke_realelement : encodeURIComponent( html ),
|
---|
| 99 | _cke_real_node_type : realElement.type,
|
---|
| 100 | alt : lang[ realElementType ] || lang.unknown
|
---|
| 101 | };
|
---|
| 102 |
|
---|
| 103 | if ( realElementType )
|
---|
| 104 | attributes._cke_real_element_type = realElementType;
|
---|
| 105 |
|
---|
| 106 | if ( isResizable )
|
---|
| 107 | attributes._cke_resizable = isResizable;
|
---|
| 108 |
|
---|
| 109 | return new CKEDITOR.htmlParser.element( 'img', attributes );
|
---|
| 110 | };
|
---|
| 111 |
|
---|
| 112 | CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
|
---|
| 113 | {
|
---|
| 114 | if ( fakeElement.getAttribute( '_cke_real_node_type' ) != CKEDITOR.NODE_ELEMENT )
|
---|
| 115 | return null;
|
---|
| 116 |
|
---|
| 117 | return CKEDITOR.dom.element.createFromHtml(
|
---|
| 118 | decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) ),
|
---|
| 119 | this.document );
|
---|
| 120 | };
|
---|