From a260913a303df5ec8e92a439a90fd364969a4a31 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Wed, 30 Dec 2009 01:33:37 -0500 Subject: [PATCH] Remove SETATTRIBUTE_IGNORES_NAME feature test, replacing it with a simpler HAS_EXTENDED_CREATE_ELEMENT_SYNTAX one. This avoids invalid injection of FORM into a root element (HTML). --- src/dom/dom.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/dom/dom.js b/src/dom/dom.js index 7f0c054..2620f30 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -110,31 +110,26 @@ if (!Node.ELEMENT_NODE) { * // The new way: * var a = new Element('a', {'class': 'foo', href: '/foo.html'}).update("Next page"); **/ -(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"), - elInput = document.createElement("input"), - 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; +(function(global) { + + var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){ + try { + var el = document.createElement(''); + return el.tagName.toLowerCase() === 'input' && el.name === 'x'; + } + catch(err) { + return false; + } })(); var element = global.Element; + global.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; - if (SETATTRIBUTE_IGNORES_NAME && attributes.name) { + if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) { tagName = '<' + tagName + ' name="' + attributes.name + '">'; delete attributes.name; return Element.writeAttribute(document.createElement(tagName), attributes); @@ -142,12 +137,14 @@ if (!Node.ELEMENT_NODE) { if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName)); return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; + Object.extend(global.Element, element || { }); if (element) global.Element.prototype = element.prototype; + })(this); -Element.cache = { }; Element.idCounter = 1; +Element.cache = { }; Element.Methods = { /**