Remove sniffing from `Element` when detecting broken `setAttribute` in IE. [#571 state:resolved] (kangax)

This commit is contained in:
Andrew Dupont 2009-03-08 18:18:55 -05:00
parent ba2c26090b
commit fa12b00111
2 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* Remove sniffing from `Element` when detecting broken `setAttribute` in IE. [#571 state:resolved] (kangax)
* Remove sniffing from `Element.update` branching in favor of feature detection. [#574 state:resolved] (kangax)
* Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax)

View File

@ -71,12 +71,30 @@ if (!Node.ELEMENT_NODE) {
* Creates an HTML element with `tagName` as the tag name.
**/
(function(global) {
// setAttribute is broken in IE (particularly when setting name attribute)
// see: http://msdn.microsoft.com/en-us/library/ms536389.aspx
var SETATTRIBUTE_IGNORES_NAME = (function(){
var elForm = document.createElement("form");
var elInput = document.createElement("input");
var root = document.documentElement;
elInput.setAttribute("name", "test");
elForm.appendChild(elInput);
root.appendChild(elForm);
var isBuggy = elForm.elements
? (typeof elForm.elements.test == "undefined")
: null;
root.removeChild(elForm);
elForm = elInput = null;
return isBuggy;
})();
var element = global.Element;
global.Element = function(tagName, attributes) {
attributes = attributes || { };
tagName = tagName.toLowerCase();
var cache = Element.cache;
if (Prototype.Browser.IE && attributes.name) {
if (SETATTRIBUTE_IGNORES_NAME && attributes.name) {
tagName = '<' + tagName + ' name="' + attributes.name + '">';
delete attributes.name;
return Element.writeAttribute(document.createElement(tagName), attributes);