Skip to content

Commit

Permalink
Fix odd behavior with new Element('select') in IE6-7. [#480 state:r…
Browse files Browse the repository at this point in the history
…esolved] (Bruce Harris, kangax, Andrew Dupont)
  • Loading branch information
savetheclocktower committed Oct 17, 2010
1 parent 1fcf2e0 commit aeb4532
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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)
Expand Down
19 changes: 14 additions & 5 deletions src/dom/dom.js
Expand Up @@ -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 {
Expand All @@ -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);
};
Expand Down

0 comments on commit aeb4532

Please sign in to comment.