source: sandbox/filemanager/tp/fckeditor/editor/_source/internals/fckxhtml_ie.js @ 1575

Revision 1575, 7.6 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

  • Property svn:executable set to *
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/**
96 * Used to clean up HTML that has been processed FCKXHtml._AppendNode().
97 *
98 * For objects corresponding to HTML elements, Internet Explorer will
99 * treat a property as if it were an attribute set on that element.
100 *
101 * http://msdn.microsoft.com/en-us/library/ms533026(VS.85).aspx#Accessing_Element_Pr
102 *
103 * FCKXHtml._AppendNode() sets the property _fckxhtmljob on node objects
104 * corresponding HTML elements to mark them as having been processed.
105 * Counting these properties as attributes will cripple style removal
106 * because FCK.Styles.RemoveFromSelection() will not remove an element
107 * as long as it still has attributes.
108 *
109 * refs #2156 and #2834
110 */
111
112FCKXHtml._RemoveXHtmlJobProperties = function ( node )
113{
114        // Select only nodes of type ELEMENT_NODE
115        if (!node || !node.nodeType || node.nodeType != 1)
116                return ;
117
118        // Clear the _fckhtmljob attribute.
119        if ( typeof node._fckxhtmljob !== 'undefined' )
120                node.removeAttribute('_fckxhtmljob') ;
121
122        // Recurse upon child nodes.
123        if ( node.hasChildNodes() )
124        {
125                var childNodes = node.childNodes ;
126                for ( var i = childNodes.length - 1 ; i >= 0 ; i-- )
127                        FCKXHtml._RemoveXHtmlJobProperties( childNodes.item(i) ) ;
128        }
129}
130
131// On very rare cases, IE is loosing the "align" attribute for DIV. (right align and apply bulleted list)
132FCKXHtml.TagProcessors['div'] = function( node, htmlNode )
133{
134        if ( htmlNode.align.length > 0 )
135                FCKXHtml._AppendAttribute( node, 'align', htmlNode.align ) ;
136
137        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
138
139        return node ;
140}
141
142// IE automatically changes <FONT> tags to <FONT size=+0>.
143FCKXHtml.TagProcessors['font'] = function( node, htmlNode )
144{
145        if ( node.attributes.length == 0 )
146                node = FCKXHtml.XML.createDocumentFragment() ;
147
148        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
149
150        return node ;
151}
152
153FCKXHtml.TagProcessors['form'] = function( node, htmlNode )
154{
155        if ( htmlNode.acceptCharset && htmlNode.acceptCharset.length > 0 && htmlNode.acceptCharset != 'UNKNOWN' )
156                FCKXHtml._AppendAttribute( node, 'accept-charset', htmlNode.acceptCharset ) ;
157
158        // IE has a bug and htmlNode.attributes['name'].specified=false if there is
159        // no element with id="name" inside the form (#360 and SF-BUG-1155726).
160        var nameAtt = htmlNode.attributes['name'] ;
161
162        if ( nameAtt && nameAtt.value.length > 0 )
163                FCKXHtml._AppendAttribute( node, 'name', nameAtt.value ) ;
164
165        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
166
167        return node ;
168}
169
170// IE doens't see the value attribute as an attribute for the <INPUT> tag.
171FCKXHtml.TagProcessors['input'] = function( node, htmlNode )
172{
173        if ( htmlNode.name )
174                FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
175
176        if ( htmlNode.value && !node.attributes.getNamedItem( 'value' ) )
177                FCKXHtml._AppendAttribute( node, 'value', htmlNode.value ) ;
178
179        if ( !node.attributes.getNamedItem( 'type' ) )
180                FCKXHtml._AppendAttribute( node, 'type', 'text' ) ;
181
182        return node ;
183}
184
185FCKXHtml.TagProcessors['label'] = function( node, htmlNode )
186{
187        if ( htmlNode.htmlFor.length > 0 )
188                FCKXHtml._AppendAttribute( node, 'for', htmlNode.htmlFor ) ;
189
190        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
191
192        return node ;
193}
194
195// Fix behavior for IE, it doesn't read back the .name on newly created maps
196FCKXHtml.TagProcessors['map'] = function( node, htmlNode )
197{
198        if ( ! node.attributes.getNamedItem( 'name' ) )
199        {
200                var name = htmlNode.name ;
201                if ( name )
202                        FCKXHtml._AppendAttribute( node, 'name', name ) ;
203        }
204
205        node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
206
207        return node ;
208}
209
210FCKXHtml.TagProcessors['meta'] = function( node, htmlNode )
211{
212        var oHttpEquiv = node.attributes.getNamedItem( 'http-equiv' ) ;
213
214        if ( oHttpEquiv == null || oHttpEquiv.value.length == 0 )
215        {
216                // Get the http-equiv value from the outerHTML.
217                var sHttpEquiv = htmlNode.outerHTML.match( FCKRegexLib.MetaHttpEquiv ) ;
218
219                if ( sHttpEquiv )
220                {
221                        sHttpEquiv = sHttpEquiv[1] ;
222                        FCKXHtml._AppendAttribute( node, 'http-equiv', sHttpEquiv ) ;
223                }
224        }
225
226        return node ;
227}
228
229// IE ignores the "SELECTED" attribute so we must add it manually.
230FCKXHtml.TagProcessors['option'] = function( node, htmlNode )
231{
232        if ( htmlNode.selected && !node.attributes.getNamedItem( 'selected' ) )
233                FCKXHtml._AppendAttribute( node, 'selected', 'selected' ) ;
234
235        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
236
237        return node ;
238}
239
240// IE doens't hold the name attribute as an attribute for the <TEXTAREA> and <SELECT> tags.
241FCKXHtml.TagProcessors['textarea'] = FCKXHtml.TagProcessors['select'] = function( node, htmlNode )
242{
243        if ( htmlNode.name )
244                FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;
245
246        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
247
248        return node ;
249}
Note: See TracBrowser for help on using the repository browser.