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 )
|
---|
13 | {
|
---|
14 | var realHtml = element.attributes._cke_realelement,
|
---|
15 | realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
|
---|
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 lang = this.lang.fakeobjects;
|
---|
66 | var attributes =
|
---|
67 | {
|
---|
68 | 'class' : className,
|
---|
69 | src : CKEDITOR.getUrl( 'images/spacer.gif' ),
|
---|
70 | _cke_realelement : encodeURIComponent( realElement.getOuterHtml() ),
|
---|
71 | alt : lang[ realElementType ] || lang.unknown
|
---|
72 | };
|
---|
73 | if ( realElementType )
|
---|
74 | attributes._cke_real_element_type = realElementType;
|
---|
75 | if ( isResizable )
|
---|
76 | attributes._cke_resizable = isResizable;
|
---|
77 |
|
---|
78 | return this.document.createElement( 'img', { attributes : attributes } );
|
---|
79 | };
|
---|
80 |
|
---|
81 | CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
|
---|
82 | {
|
---|
83 | var writer = new CKEDITOR.htmlParser.basicWriter();
|
---|
84 |
|
---|
85 | realElement.writeHtml( writer );
|
---|
86 |
|
---|
87 | var html = writer.getHtml();
|
---|
88 | var lang = this.lang.fakeobjects;
|
---|
89 |
|
---|
90 | var attributes =
|
---|
91 | {
|
---|
92 | 'class' : className,
|
---|
93 | src : CKEDITOR.getUrl( 'images/spacer.gif' ),
|
---|
94 | _cke_realelement : encodeURIComponent( html ),
|
---|
95 | alt : lang[ realElementType ] || lang.unknown
|
---|
96 | };
|
---|
97 |
|
---|
98 | if ( realElementType )
|
---|
99 | attributes._cke_real_element_type = realElementType;
|
---|
100 |
|
---|
101 | if ( isResizable )
|
---|
102 | attributes._cke_resizable = isResizable;
|
---|
103 |
|
---|
104 | return new CKEDITOR.htmlParser.element( 'img', attributes );
|
---|
105 | };
|
---|
106 |
|
---|
107 | CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
|
---|
108 | {
|
---|
109 | var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) );
|
---|
110 | return CKEDITOR.dom.element.createFromHtml( html, this.document );
|
---|
111 | };
|
---|