From 06068431f7358c0278c784ea4bb0ad826cc1e620 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Fri, 20 Mar 2009 18:08:34 -0400 Subject: [PATCH] Fix for/htmlFor translation in IE8 --- CHANGELOG | 2 ++ src/dom/dom.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d6373bb..d0325dc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Fix another failure in IE8, `for`/`htmlFor` {get/set}Attribute translation. (kangax) + * Fix `Element#writeAttribute` and `Element#readAttribute` failures in IE8 due to lack of proper feature testing. (kangax) * Remove sniffing from one of the DOM tests, which produced failures in IE8. (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index 6ba0765..cad7f70 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1169,7 +1169,7 @@ Element._attributeTranslations = { write: { names: { className: 'class', - htmlFor: 'for' + htmlFor: 'for' }, values: { } } @@ -1309,13 +1309,14 @@ else if (Prototype.Browser.IE) { Element._attributeTranslations = (function(){ var classProp = 'className'; + var forProp = 'for'; + var el = document.createElement('div'); // try "className" first (IE <8) el.setAttribute(classProp, 'x'); if (el.className !== 'x') { - // try "class" (IE 8) el.setAttribute('class', 'x'); if (el.className === 'x') { @@ -1324,12 +1325,23 @@ else if (Prototype.Browser.IE) { } el = null; + el = document.createElement('label'); + el.setAttribute(forProp, 'x'); + if (el.htmlFor !== 'x') { + el.setAttribute('htmlFor', 'x'); + if (el.htmlFor === 'x') { + forProp = 'htmlFor'; + } + } + el = null; + return { read: { names: { 'class': classProp, 'className': classProp, - 'for': 'htmlFor' + 'for': forProp, + 'htmlFor': forProp }, values: { _getAttr: function(element, attribute) { @@ -1905,4 +1917,4 @@ Element.addMethods({ return value; } -}); +}); \ No newline at end of file