import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / internals / fckxhtml_ie.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Defines the FCKXHtml object, responsible for the XHTML operations.\r
22  * IE specific.\r
23  */\r
24 \r
25 FCKXHtml._GetMainXmlString = function()\r
26 {\r
27         return this.MainNode.xml ;\r
28 }\r
29 \r
30 FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node, nodeName )\r
31 {\r
32         var aAttributes = htmlNode.attributes,\r
33                 bHasStyle ;\r
34 \r
35         for ( var n = 0 ; n < aAttributes.length ; n++ )\r
36         {\r
37                 var oAttribute = aAttributes[n] ;\r
38 \r
39                 if ( oAttribute.specified )\r
40                 {\r
41                         var sAttName = oAttribute.nodeName.toLowerCase() ;\r
42                         var sAttValue ;\r
43 \r
44                         // Ignore any attribute starting with "_fck".\r
45                         if ( sAttName.StartsWith( '_fck' ) )\r
46                                 continue ;\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
50                         {\r
51                                 // Just mark it to do it later in this function.\r
52                                 bHasStyle = true ;\r
53                                 continue ;\r
54                         }\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
59                         {\r
60                                 sAttValue = oAttribute.nodeValue.replace( FCKRegexLib.FCK_Class, '' ) ;\r
61                                 if ( sAttValue.length == 0 )\r
62                                         continue ;\r
63                         }\r
64                         else if ( sAttName.indexOf('on') == 0 )\r
65                                 sAttValue = oAttribute.nodeValue ;\r
66                         else if ( nodeName == 'body' && sAttName == 'contenteditable' )\r
67                                 continue ;\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
71                         else\r
72                         {\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
75                                 try\r
76                                 {\r
77                                         sAttValue = htmlNode.getAttribute( sAttName, 2 ) ;\r
78                                 }\r
79                                 catch (e) {}\r
80                         }\r
81                         this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ;\r
82                 }\r
83         }\r
84 \r
85         // IE loses the style attribute in JavaScript-created elements tags. (#2390)\r
86         if ( bHasStyle || htmlNode.style.cssText.length > 0 )\r
87         {\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
92         }\r
93 }\r
94 \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
97 {\r
98         if ( htmlNode.align.length > 0 )\r
99                 FCKXHtml._AppendAttribute( node, 'align', htmlNode.align ) ;\r
100 \r
101         node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;\r
102 \r
103         return node ;\r
104 }\r
105 \r
106 // IE automatically changes <FONT> tags to <FONT size=+0>.\r
107 FCKXHtml.TagProcessors['font'] = function( node, htmlNode )\r
108 {\r
109         if ( node.attributes.length == 0 )\r
110                 node = FCKXHtml.XML.createDocumentFragment() ;\r
111 \r
112         node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;\r
113 \r
114         return node ;\r
115 }\r
116 \r
117 FCKXHtml.TagProcessors['form'] = function( node, htmlNode )\r
118 {\r
119         if ( htmlNode.acceptCharset && htmlNode.acceptCharset.length > 0 && htmlNode.acceptCharset != 'UNKNOWN' )\r
120                 FCKXHtml._AppendAttribute( node, 'accept-charset', htmlNode.acceptCharset ) ;\r
121 \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
125 \r
126         if ( nameAtt && nameAtt.value.length > 0 )\r
127                 FCKXHtml._AppendAttribute( node, 'name', nameAtt.value ) ;\r
128 \r
129         node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;\r
130 \r
131         return node ;\r
132 }\r
133 \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
136 {\r
137         if ( htmlNode.name )\r
138                 FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;\r
139 \r
140         if ( htmlNode.value && !node.attributes.getNamedItem( 'value' ) )\r
141                 FCKXHtml._AppendAttribute( node, 'value', htmlNode.value ) ;\r
142 \r
143         if ( !node.attributes.getNamedItem( 'type' ) )\r
144                 FCKXHtml._AppendAttribute( node, 'type', 'text' ) ;\r
145 \r
146         return node ;\r
147 }\r
148 \r
149 FCKXHtml.TagProcessors['label'] = function( node, htmlNode )\r
150 {\r
151         if ( htmlNode.htmlFor.length > 0 )\r
152                 FCKXHtml._AppendAttribute( node, 'for', htmlNode.htmlFor ) ;\r
153 \r
154         node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;\r
155 \r
156         return node ;\r
157 }\r
158 \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
161 {\r
162         if ( ! node.attributes.getNamedItem( 'name' ) )\r
163         {\r
164                 var name = htmlNode.name ;\r
165                 if ( name )\r
166                         FCKXHtml._AppendAttribute( node, 'name', name ) ;\r
167         }\r
168 \r
169         node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;\r
170 \r
171         return node ;\r
172 }\r
173 \r
174 FCKXHtml.TagProcessors['meta'] = function( node, htmlNode )\r
175 {\r
176         var oHttpEquiv = node.attributes.getNamedItem( 'http-equiv' ) ;\r
177 \r
178         if ( oHttpEquiv == null || oHttpEquiv.value.length == 0 )\r
179         {\r
180                 // Get the http-equiv value from the outerHTML.\r
181                 var sHttpEquiv = htmlNode.outerHTML.match( FCKRegexLib.MetaHttpEquiv ) ;\r
182 \r
183                 if ( sHttpEquiv )\r
184                 {\r
185                         sHttpEquiv = sHttpEquiv[1] ;\r
186                         FCKXHtml._AppendAttribute( node, 'http-equiv', sHttpEquiv ) ;\r
187                 }\r
188         }\r
189 \r
190         return node ;\r
191 }\r
192 \r
193 // IE ignores the "SELECTED" attribute so we must add it manually.\r
194 FCKXHtml.TagProcessors['option'] = function( node, htmlNode )\r
195 {\r
196         if ( htmlNode.selected && !node.attributes.getNamedItem( 'selected' ) )\r
197                 FCKXHtml._AppendAttribute( node, 'selected', 'selected' ) ;\r
198 \r
199         node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;\r
200 \r
201         return node ;\r
202 }\r
203 \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
206 {\r
207         if ( htmlNode.name )\r
208                 FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;\r
209 \r
210         node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;\r
211 \r
212         return node ;\r
213 }\r