[795] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 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 | |
---|
| 25 | FCKXHtml._GetMainXmlString = function() |
---|
| 26 | { |
---|
| 27 | return this.MainNode.xml ; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node, nodeName ) |
---|
| 31 | { |
---|
| 32 | var aAttributes = htmlNode.attributes ; |
---|
| 33 | |
---|
| 34 | for ( var n = 0 ; n < aAttributes.length ; n++ ) |
---|
| 35 | { |
---|
| 36 | var oAttribute = aAttributes[n] ; |
---|
| 37 | |
---|
| 38 | if ( oAttribute.specified ) |
---|
| 39 | { |
---|
| 40 | var sAttName = oAttribute.nodeName.toLowerCase() ; |
---|
| 41 | var sAttValue ; |
---|
| 42 | |
---|
| 43 | // Ignore any attribute starting with "_fck". |
---|
| 44 | if ( sAttName.StartsWith( '_fck' ) ) |
---|
| 45 | continue ; |
---|
| 46 | // The following must be done because of a bug on IE regarding the style |
---|
| 47 | // attribute. It returns "null" for the nodeValue. |
---|
| 48 | else if ( sAttName == 'style' ) |
---|
| 49 | sAttValue = htmlNode.style.cssText.replace( FCKRegexLib.StyleProperties, FCKTools.ToLowerCase ) ; |
---|
| 50 | // There are two cases when the oAttribute.nodeValue must be used: |
---|
| 51 | // - for the "class" attribute |
---|
| 52 | // - for events attributes (on IE only). |
---|
| 53 | else if ( sAttName == 'class' || sAttName.indexOf('on') == 0 ) |
---|
| 54 | sAttValue = oAttribute.nodeValue ; |
---|
| 55 | else if ( nodeName == 'body' && sAttName == 'contenteditable' ) |
---|
| 56 | continue ; |
---|
| 57 | // XHTML doens't support attribute minimization like "CHECKED". It must be trasformed to cheched="checked". |
---|
| 58 | else if ( oAttribute.nodeValue === true ) |
---|
| 59 | sAttValue = sAttName ; |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | // We must use getAttribute to get it exactly as it is defined. |
---|
| 63 | // There are some rare cases that IE throws an error here, so we must try/catch. |
---|
| 64 | try |
---|
| 65 | { |
---|
| 66 | sAttValue = htmlNode.getAttribute( sAttName, 2 ) ; |
---|
| 67 | } |
---|
| 68 | catch (e) {} |
---|
| 69 | } |
---|
| 70 | this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | FCKXHtml.TagProcessors['meta'] = function( node, htmlNode ) |
---|
| 76 | { |
---|
| 77 | var oHttpEquiv = node.attributes.getNamedItem( 'http-equiv' ) ; |
---|
| 78 | |
---|
| 79 | if ( oHttpEquiv == null || oHttpEquiv.value.length == 0 ) |
---|
| 80 | { |
---|
| 81 | // Get the http-equiv value from the outerHTML. |
---|
| 82 | var sHttpEquiv = htmlNode.outerHTML.match( FCKRegexLib.MetaHttpEquiv ) ; |
---|
| 83 | |
---|
| 84 | if ( sHttpEquiv ) |
---|
| 85 | { |
---|
| 86 | sHttpEquiv = sHttpEquiv[1] ; |
---|
| 87 | FCKXHtml._AppendAttribute( node, 'http-equiv', sHttpEquiv ) ; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | return node ; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // IE automaticaly changes <FONT> tags to <FONT size=+0>. |
---|
| 95 | FCKXHtml.TagProcessors['font'] = function( node, htmlNode ) |
---|
| 96 | { |
---|
| 97 | if ( node.attributes.length == 0 ) |
---|
| 98 | node = FCKXHtml.XML.createDocumentFragment() ; |
---|
| 99 | |
---|
| 100 | node = FCKXHtml._AppendChildNodes( node, htmlNode ) ; |
---|
| 101 | |
---|
| 102 | return node ; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // IE doens't see the value attribute as an attribute for the <INPUT> tag. |
---|
| 106 | FCKXHtml.TagProcessors['input'] = function( node, htmlNode ) |
---|
| 107 | { |
---|
| 108 | if ( htmlNode.name ) |
---|
| 109 | FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ; |
---|
| 110 | |
---|
| 111 | if ( htmlNode.value && !node.attributes.getNamedItem( 'value' ) ) |
---|
| 112 | FCKXHtml._AppendAttribute( node, 'value', htmlNode.value ) ; |
---|
| 113 | |
---|
| 114 | if ( !node.attributes.getNamedItem( 'type' ) ) |
---|
| 115 | FCKXHtml._AppendAttribute( node, 'type', 'text' ) ; |
---|
| 116 | |
---|
| 117 | return node ; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | // IE ignores the "SELECTED" attribute so we must add it manually. |
---|
| 121 | FCKXHtml.TagProcessors['option'] = function( node, htmlNode ) |
---|
| 122 | { |
---|
| 123 | if ( htmlNode.selected && !node.attributes.getNamedItem( 'selected' ) ) |
---|
| 124 | FCKXHtml._AppendAttribute( node, 'selected', 'selected' ) ; |
---|
| 125 | |
---|
| 126 | node = FCKXHtml._AppendChildNodes( node, htmlNode ) ; |
---|
| 127 | |
---|
| 128 | return node ; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | // IE ignores the "COORDS" and "SHAPE" attribute so we must add it manually. |
---|
| 132 | FCKXHtml.TagProcessors['area'] = function( node, htmlNode ) |
---|
| 133 | { |
---|
| 134 | if ( ! node.attributes.getNamedItem( 'coords' ) ) |
---|
| 135 | { |
---|
| 136 | var sCoords = htmlNode.getAttribute( 'coords', 2 ) ; |
---|
| 137 | if ( sCoords && sCoords != '0,0,0' ) |
---|
| 138 | FCKXHtml._AppendAttribute( node, 'coords', sCoords ) ; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if ( ! node.attributes.getNamedItem( 'shape' ) ) |
---|
| 142 | { |
---|
| 143 | var sShape = htmlNode.getAttribute( 'shape', 2 ) ; |
---|
| 144 | if ( sShape && sShape.length > 0 ) |
---|
| 145 | FCKXHtml._AppendAttribute( node, 'shape', sShape ) ; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | return node ; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | FCKXHtml.TagProcessors['label'] = function( node, htmlNode ) |
---|
| 152 | { |
---|
| 153 | if ( htmlNode.htmlFor.length > 0 ) |
---|
| 154 | FCKXHtml._AppendAttribute( node, 'for', htmlNode.htmlFor ) ; |
---|
| 155 | |
---|
| 156 | node = FCKXHtml._AppendChildNodes( node, htmlNode ) ; |
---|
| 157 | |
---|
| 158 | return node ; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | FCKXHtml.TagProcessors['form'] = function( node, htmlNode ) |
---|
| 162 | { |
---|
| 163 | if ( htmlNode.acceptCharset && htmlNode.acceptCharset.length > 0 && htmlNode.acceptCharset != 'UNKNOWN' ) |
---|
| 164 | FCKXHtml._AppendAttribute( node, 'accept-charset', htmlNode.acceptCharset ) ; |
---|
| 165 | |
---|
| 166 | if ( htmlNode.name ) |
---|
| 167 | FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ; |
---|
| 168 | |
---|
| 169 | node = FCKXHtml._AppendChildNodes( node, htmlNode ) ; |
---|
| 170 | |
---|
| 171 | return node ; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | // IE doens't hold the name attribute as an attribute for the <TEXTAREA> and <SELECT> tags. |
---|
| 175 | FCKXHtml.TagProcessors['textarea'] = FCKXHtml.TagProcessors['select'] = function( node, htmlNode ) |
---|
| 176 | { |
---|
| 177 | if ( htmlNode.name ) |
---|
| 178 | FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ; |
---|
| 179 | |
---|
| 180 | node = FCKXHtml._AppendChildNodes( node, htmlNode ) ; |
---|
| 181 | |
---|
| 182 | return node ; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | // On very rare cases, IE is loosing the "align" attribute for DIV. (right align and apply bulleted list) |
---|
| 186 | FCKXHtml.TagProcessors['div'] = function( node, htmlNode ) |
---|
| 187 | { |
---|
| 188 | if ( htmlNode.align.length > 0 ) |
---|
| 189 | FCKXHtml._AppendAttribute( node, 'align', htmlNode.align ) ; |
---|
| 190 | |
---|
| 191 | node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ; |
---|
| 192 | |
---|
| 193 | return node ; |
---|
| 194 | } |
---|