Permalink
Browse files

Fix odd behavior with `new Element('select')` in IE6-7. [#480 state:r…

…esolved] (Bruce Harris, kangax, Andrew Dupont)
  • Loading branch information...
savetheclocktower committed Oct 17, 2010
1 parent 1fcf2e0 commit aeb45325d40f4a31c3c3b2687ede876b2c7e3c1c
Showing with 16 additions and 5 deletions.
  1. +2 −0 CHANGELOG
  2. +14 −5 src/dom/dom.js
View
@@ -1,3 +1,5 @@
+* Fix odd behavior with `new Element('select')` in IE6-7. [#480 state:resolved] (Bruce Harris, kangax, Andrew Dupont)
+
* Extend BUTTON elements with everything defined in Form.Element.Methods. Ensure BUTTON elements are traversed in Form.getElements and serialized in Form.serialize. (Luis Gomez, Samuel Lebeau, kangax, Andrew Dupont)
* Ensure Object.isFunction returns `false` for RegExp objects. [#661 state:resolved] (James, kangax, Andrew Dupont)
View
@@ -154,7 +154,18 @@ if (!Node.ELEMENT_NODE) {
* var a = new Element('a', {'class': 'foo', href: '/foo.html'}).update("Next page");
**/
-(function(global) {
+(function(global) {
+ // For performance reasons, we create new elements by cloning a "blank"
+ // version of a given element. But sometimes this causes problems. Skip
+ // the cache if:
+ // (a) We're creating a SELECT element (troublesome in IE6);
+ // (b) We're setting the `type` attribute on an INPUT element
+ // (troublesome in IE9).
+ function shouldUseCache(tagName, attributes) {
+ if (tagName === 'select') return false;
+ if ('type' in attributes) return false;
+ return true;
+ }
var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
try {
@@ -181,10 +192,8 @@ if (!Node.ELEMENT_NODE) {
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
- // Don't use the cache if we're setting the `type` attribute, as on an
- // INPUT element. This prevents an issue with IE9 beta.
- var node = ('type' in attributes) ? document.createElement(tagName) :
- cache[tagName].cloneNode(false);
+ var node = shouldUseCache(tagName, attributes) ?
+ cache[tagName].cloneNode(false) : document.createElement(tagName);
return Element.writeAttribute(node, attributes);
};

0 comments on commit aeb4532

Please sign in to comment.