source: extensions/FCKEditor/editor/_source/internals/fckxhtml_ie.js @ 3295

Last change on this file since 3295 was 3295, checked in by patdenice, 15 years ago

New extension added:
FCK Editor (2.0.a)

File size: 6.5 KB
Line 
1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 *  - GNU General Public License Version 2 or later (the "GPL")
11 *    http://www.gnu.org/licenses/gpl.html
12 *
13 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 *    http://www.gnu.org/licenses/lgpl.html
15 *
16 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17 *    http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * Defines the FCKXHtml object, responsible for the XHTML operations.
22 * IE specific.
23 */
24
25FCKXHtml._GetMainXmlString = function()
26{
27        return this.MainNode.xml ;
28}
29
30FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node, nodeName )
31{
32        var aAttributes = htmlNode.attributes,
33                bHasStyle ;
34
35        for ( var n = 0 ; n < aAttributes.length ; n++ )
36        {
37                var oAttribute = aAttributes[n] ;
38
39                if ( oAttribute.specified )
40                {
41                        var sAttName = oAttribute.nodeName.toLowerCase() ;
42                        var sAttValue ;
43
44                        // Ignore any attribute starting with "_fck".
45                        if ( sAttName.StartsWith( '_fck' ) )
46                                continue ;
47                        // The following must be done because of a bug on IE regarding the style
48                        // attribute. It returns "null" for the nodeValue.
49                        else if ( sAttName == 'style' )
50                        {
51                                // Just mark it to do it later in this function.
52                                bHasStyle = true ;
53                                continue ;
54                        }
55                        // There are two cases when the oAttribute.nodeValue must be used:
56                        //              - for the "class" attribute
57                        //              - for events attributes (on IE only).
58                        else if ( sAttName == 'class' )
59                        {
60                                sAttValue = oAttribute.nodeValue.replace( FCKRegexLib.FCK_Class, '' ) ;
61                                if ( sAttValue.length == 0 )
62                                        continue ;
63                        }
64                        else if ( sAttName.indexOf('on') == 0 )
65                                sAttValue = oAttribute.nodeValue ;
66                        else if ( nodeName == 'body' && sAttName == 'contenteditable' )
67                                continue ;
68                        // XHTML doens't support attribute minimization like "CHECKED". It must be transformed to checked="checked".
69                        else if ( oAttribute.nodeValue === true )
70                                sAttValue = sAttName ;
71                        else
72                        {
73                                // We must use getAttribute to get it exactly as it is defined.
74                                // There are some rare cases that IE throws an error here, so we must try/catch.
75                                try
76                                {
77                                        sAttValue = htmlNode.getAttribute( sAttName, 2 ) ;
78                                }
79                                catch (e) {}
80                        }
81                        this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ;
82                }
83        }
84
85        // IE loses the style attribute in JavaScript-created elements tags. (#2390)
86        if ( bHasStyle || htmlNode.style.cssText.length > 0 )
87        {
88                var data = FCKTools.ProtectFormStyles( htmlNode ) ;
89                var sStyleValue = htmlNode.style.cssText.replace( FCKRegexLib.StyleProperties, FCKTools.ToLowerCase ) ;
90                FCKTools.RestoreFormStyles( htmlNode, data ) ;
91                this._AppendAttribute( node, 'style', sStyleValue ) ;
92        }
93}
94
95// On very rare cases, IE is loosing the "align" attribute for DIV. (right align and apply bulleted list)
96FCKXHtml.TagProcessors['div'] = function( node, htmlNode )
97{
98        if ( htmlNode.align.length > 0 )
99                FCKXHtml._AppendAttribute( node, 'align', htmlNode.align ) ;
100
101        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
102
103        return node ;
104}
105
106// IE automatically changes <FONT> tags to <FONT size=+0>.
107FCKXHtml.TagProcessors['font'] = function( node, htmlNode )
108{
109        if ( node.attributes.length == 0 )
110                node = FCKXHtml.XML.createDocumentFragment() ;
111
112        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
113
114        return node ;
115}
116
117FCKXHtml.TagProcessors['form'] = function( node, htmlNode )
118{
119        if ( htmlNode.acceptCharset && htmlNode.acceptCharset.length > 0 && htmlNode.acceptCharset != 'UNKNOWN' )
120                FCKXHtml._AppendAttribute( node, 'accept-charset', htmlNode.acceptCharset ) ;
121
122        // IE has a bug and htmlNode.attributes['name'].specified=false if there is
123        // no element with id="name" inside the form (#360 and SF-BUG-1155726).
124        var nameAtt = htmlNode.attributes['name'] ;
125
126        if ( nameAtt && nameAtt.value.length > 0 )
127                FCKXHtml._AppendAttribute( node, 'name', nameAtt.value ) ;
128
129        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
130
131        return node ;
132}
133
134// IE doens't see the value attribute as an attribute for the <INPUT> tag.
135FCKXHtml.TagProcessors['input'] = function( node, htmlNode )
136{
137        if ( htmlNode.name )
138                FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
139
140        if ( htmlNode.value && !node.attributes.getNamedItem( 'value' ) )
141                FCKXHtml._AppendAttribute( node, 'value', htmlNode.value ) ;
142
143        if ( !node.attributes.getNamedItem( 'type' ) )
144                FCKXHtml._AppendAttribute( node, 'type', 'text' ) ;
145
146        return node ;
147}
148
149FCKXHtml.TagProcessors['label'] = function( node, htmlNode )
150{
151        if ( htmlNode.htmlFor.length > 0 )
152                FCKXHtml._AppendAttribute( node, 'for', htmlNode.htmlFor ) ;
153
154        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
155
156        return node ;
157}
158
159// Fix behavior for IE, it doesn't read back the .name on newly created maps
160FCKXHtml.TagProcessors['map'] = function( node, htmlNode )
161{
162        if ( ! node.attributes.getNamedItem( 'name' ) )
163        {
164                var name = htmlNode.name ;
165                if ( name )
166                        FCKXHtml._AppendAttribute( node, 'name', name ) ;
167        }
168
169        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
170
171        return node ;
172}
173
174FCKXHtml.TagProcessors['meta'] = function( node, htmlNode )
175{
176        var oHttpEquiv = node.attributes.getNamedItem( 'http-equiv' ) ;
177
178        if ( oHttpEquiv == null || oHttpEquiv.value.length == 0 )
179        {
180                // Get the http-equiv value from the outerHTML.
181                var sHttpEquiv = htmlNode.outerHTML.match( FCKRegexLib.MetaHttpEquiv ) ;
182
183                if ( sHttpEquiv )
184                {
185                        sHttpEquiv = sHttpEquiv[1] ;
186                        FCKXHtml._AppendAttribute( node, 'http-equiv', sHttpEquiv ) ;
187                }
188        }
189
190        return node ;
191}
192
193// IE ignores the "SELECTED" attribute so we must add it manually.
194FCKXHtml.TagProcessors['option'] = function( node, htmlNode )
195{
196        if ( htmlNode.selected && !node.attributes.getNamedItem( 'selected' ) )
197                FCKXHtml._AppendAttribute( node, 'selected', 'selected' ) ;
198
199        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
200
201        return node ;
202}
203
204// IE doens't hold the name attribute as an attribute for the <TEXTAREA> and <SELECT> tags.
205FCKXHtml.TagProcessors['textarea'] = FCKXHtml.TagProcessors['select'] = function( node, htmlNode )
206{
207        if ( htmlNode.name )
208                FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
209
210        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
211
212        return node ;
213}
Note: See TracBrowser for help on using the repository browser.