2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Defines the FCKXHtml object, responsible for the XHTML operations.
\r
25 FCKXHtml._GetMainXmlString = function()
\r
27 return this.MainNode.xml ;
\r
30 FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node, nodeName )
\r
32 var aAttributes = htmlNode.attributes,
\r
35 for ( var n = 0 ; n < aAttributes.length ; n++ )
\r
37 var oAttribute = aAttributes[n] ;
\r
39 if ( oAttribute.specified )
\r
41 var sAttName = oAttribute.nodeName.toLowerCase() ;
\r
44 // Ignore any attribute starting with "_fck".
\r
45 if ( sAttName.StartsWith( '_fck' ) )
\r
47 // The following must be done because of a bug on IE regarding the style
\r
48 // attribute. It returns "null" for the nodeValue.
\r
49 else if ( sAttName == 'style' )
\r
51 // Just mark it to do it later in this function.
\r
55 // There are two cases when the oAttribute.nodeValue must be used:
\r
56 // - for the "class" attribute
\r
57 // - for events attributes (on IE only).
\r
58 else if ( sAttName == 'class' )
\r
60 sAttValue = oAttribute.nodeValue.replace( FCKRegexLib.FCK_Class, '' ) ;
\r
61 if ( sAttValue.length == 0 )
\r
64 else if ( sAttName.indexOf('on') == 0 )
\r
65 sAttValue = oAttribute.nodeValue ;
\r
66 else if ( nodeName == 'body' && sAttName == 'contenteditable' )
\r
68 // XHTML doens't support attribute minimization like "CHECKED". It must be transformed to checked="checked".
\r
69 else if ( oAttribute.nodeValue === true )
\r
70 sAttValue = sAttName ;
\r
73 // We must use getAttribute to get it exactly as it is defined.
\r
74 // There are some rare cases that IE throws an error here, so we must try/catch.
\r
77 sAttValue = htmlNode.getAttribute( sAttName, 2 ) ;
\r
81 this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ;
\r
85 // IE loses the style attribute in JavaScript-created elements tags. (#2390)
\r
86 if ( bHasStyle || htmlNode.style.cssText.length > 0 )
\r
88 var data = FCKTools.ProtectFormStyles( htmlNode ) ;
\r
89 var sStyleValue = htmlNode.style.cssText.replace( FCKRegexLib.StyleProperties, FCKTools.ToLowerCase ) ;
\r
90 FCKTools.RestoreFormStyles( htmlNode, data ) ;
\r
91 this._AppendAttribute( node, 'style', sStyleValue ) ;
\r
95 // On very rare cases, IE is loosing the "align" attribute for DIV. (right align and apply bulleted list)
\r
96 FCKXHtml.TagProcessors['div'] = function( node, htmlNode )
\r
98 if ( htmlNode.align.length > 0 )
\r
99 FCKXHtml._AppendAttribute( node, 'align', htmlNode.align ) ;
\r
101 node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
\r
106 // IE automatically changes <FONT> tags to <FONT size=+0>.
\r
107 FCKXHtml.TagProcessors['font'] = function( node, htmlNode )
\r
109 if ( node.attributes.length == 0 )
\r
110 node = FCKXHtml.XML.createDocumentFragment() ;
\r
112 node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
\r
117 FCKXHtml.TagProcessors['form'] = function( node, htmlNode )
\r
119 if ( htmlNode.acceptCharset && htmlNode.acceptCharset.length > 0 && htmlNode.acceptCharset != 'UNKNOWN' )
\r
120 FCKXHtml._AppendAttribute( node, 'accept-charset', htmlNode.acceptCharset ) ;
\r
122 // IE has a bug and htmlNode.attributes['name'].specified=false if there is
\r
123 // no element with id="name" inside the form (#360 and SF-BUG-1155726).
\r
124 var nameAtt = htmlNode.attributes['name'] ;
\r
126 if ( nameAtt && nameAtt.value.length > 0 )
\r
127 FCKXHtml._AppendAttribute( node, 'name', nameAtt.value ) ;
\r
129 node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
\r
134 // IE doens't see the value attribute as an attribute for the <INPUT> tag.
\r
135 FCKXHtml.TagProcessors['input'] = function( node, htmlNode )
\r
137 if ( htmlNode.name )
\r
138 FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
\r
140 if ( htmlNode.value && !node.attributes.getNamedItem( 'value' ) )
\r
141 FCKXHtml._AppendAttribute( node, 'value', htmlNode.value ) ;
\r
143 if ( !node.attributes.getNamedItem( 'type' ) )
\r
144 FCKXHtml._AppendAttribute( node, 'type', 'text' ) ;
\r
149 FCKXHtml.TagProcessors['label'] = function( node, htmlNode )
\r
151 if ( htmlNode.htmlFor.length > 0 )
\r
152 FCKXHtml._AppendAttribute( node, 'for', htmlNode.htmlFor ) ;
\r
154 node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
\r
159 // Fix behavior for IE, it doesn't read back the .name on newly created maps
\r
160 FCKXHtml.TagProcessors['map'] = function( node, htmlNode )
\r
162 if ( ! node.attributes.getNamedItem( 'name' ) )
\r
164 var name = htmlNode.name ;
\r
166 FCKXHtml._AppendAttribute( node, 'name', name ) ;
\r
169 node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
\r
174 FCKXHtml.TagProcessors['meta'] = function( node, htmlNode )
\r
176 var oHttpEquiv = node.attributes.getNamedItem( 'http-equiv' ) ;
\r
178 if ( oHttpEquiv == null || oHttpEquiv.value.length == 0 )
\r
180 // Get the http-equiv value from the outerHTML.
\r
181 var sHttpEquiv = htmlNode.outerHTML.match( FCKRegexLib.MetaHttpEquiv ) ;
\r
185 sHttpEquiv = sHttpEquiv[1] ;
\r
186 FCKXHtml._AppendAttribute( node, 'http-equiv', sHttpEquiv ) ;
\r
193 // IE ignores the "SELECTED" attribute so we must add it manually.
\r
194 FCKXHtml.TagProcessors['option'] = function( node, htmlNode )
\r
196 if ( htmlNode.selected && !node.attributes.getNamedItem( 'selected' ) )
\r
197 FCKXHtml._AppendAttribute( node, 'selected', 'selected' ) ;
\r
199 node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
\r
204 // IE doens't hold the name attribute as an attribute for the <TEXTAREA> and <SELECT> tags.
\r
205 FCKXHtml.TagProcessors['textarea'] = FCKXHtml.TagProcessors['select'] = function( node, htmlNode )
\r
207 if ( htmlNode.name )
\r
208 FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
\r
210 node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
\r