2
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
3
For licensing, see LICENSE.html or http://ckeditor.com/license
7
* A lightweight representation of an HTML element.
8
* @param {String} name The element name.
9
* @param {Object} attributes And object holding all attributes defined for
14
CKEDITOR.htmlParser.element = function( name, attributes )
24
* Holds the attributes defined for this element.
28
this.attributes = attributes;
31
* The nodes that are direct children of this element.
37
var dtd = CKEDITOR.dtd,
38
isBlockLike = !!( dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] ),
39
isEmpty = !!dtd.$empty[ name ];
41
this.isEmpty = isEmpty;
42
this.isUnknown = !dtd[ name ];
47
isBlockLike : isBlockLike,
48
hasInlineStarted : isEmpty || !isBlockLike
54
// Used to sort attribute entries in an array, where the first element of
55
// each object is the attribute name.
56
var sortAttribs = function( a, b )
60
return a < b ? -1 : a > b ? 1 : 0;
63
CKEDITOR.htmlParser.element.prototype =
66
* The node type. This is a constant value set to {@link CKEDITOR.NODE_ELEMENT}.
70
type : CKEDITOR.NODE_ELEMENT,
73
* Adds a node to the element children list.
74
* @param {Object} node The node to be added. It can be any of of the
75
* following types: {@link CKEDITOR.htmlParser.element},
76
* {@link CKEDITOR.htmlParser.text} and
77
* {@link CKEDITOR.htmlParser.comment}.
81
add : CKEDITOR.htmlParser.fragment.prototype.add,
85
* @returns {CKEDITOR.htmlParser.element} The element clone.
90
return new CKEDITOR.htmlParser.element( this.name, this.attributes );
94
* Writes the element HTML to a CKEDITOR.htmlWriter.
95
* @param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
98
writeHtml : function( writer, filter )
100
var attributes = this.attributes;
102
// The "_cke_replacedata" indicates that this element is replacing
103
// a data snippet, which should be outputted as is.
104
if ( attributes._cke_replacedata )
106
writer.write( attributes._cke_replacedata );
110
// Ignore cke: prefixes when writing HTML.
112
writeName = element.name,
119
if ( !( writeName = filter.onElementName( writeName ) ) )
122
element.name = writeName;
124
if ( !( element = filter.onElement( element ) ) )
127
if ( element.name == writeName )
130
writeName = element.name;
131
if ( !writeName ) // Send children.
133
CKEDITOR.htmlParser.fragment.prototype.writeHtml.apply( element, arguments );
138
// The element may have been changed, so update the local
140
attributes = element.attributes;
144
writer.openTag( writeName, attributes );
146
if ( writer.sortAttributes )
148
// Copy all attributes to an array.
149
var attribsArray = [];
150
for ( a in attributes )
152
value = attributes[ a ];
154
if ( filter && ( !( a = filter.onAttributeName( a ) ) || ( value = filter.onAttribute( element, a, value ) ) === false ) )
157
attribsArray.push( [ a, value ] );
160
// Sort the attributes by name.
161
attribsArray.sort( sortAttribs );
163
// Send the attributes.
164
for ( var i = 0, len = attribsArray.length ; i < len ; i++ )
166
var attrib = attribsArray[ i ];
167
writer.attribute( attrib[0], attrib[1] );
172
for ( a in attributes )
174
value = attributes[ a ];
176
if ( filter && ( !( a = filter.onAttributeName( a ) ) || ( value = filter.onAttribute( element, a, value ) ) === false ) )
179
writer.attribute( a, value );
184
writer.openTagClose( writeName, element.isEmpty );
186
if ( !element.isEmpty )
189
CKEDITOR.htmlParser.fragment.prototype.writeHtml.apply( element, arguments );
191
// Close the element.
192
writer.closeTag( writeName );