Make sure `getAttribute` is used without flag when accessing the "type" attribute of an iframe (IE throws error otherwise). [#118 state:resolved] (Zekid, kangax)

This commit is contained in:
Andrew Dupont 2009-02-23 20:20:21 -06:00
parent e9bdaef0af
commit 043653a282
3 changed files with 43 additions and 13 deletions

View File

@ -1,3 +1,5 @@
* Make sure `getAttribute` is used without flag when accessing the "type" attribute of an iframe (IE throws error otherwise). [#118 state:resolved] (Zekid, kangax)
* String#gsub should escape RegExp metacharacters when the first argument is a string. [#469 state:resolved] (michael, kangax)
* Fix order of replacement in String#unescapeHTML [#544 state:resolved] (SWeini, kangax)

View File

@ -274,20 +274,43 @@ Element.Methods = {
return id;
},
readAttribute: function(element, name) {
element = $(element);
if (Prototype.Browser.IE) {
var t = Element._attributeTranslations.read;
if (t.values[name]) return t.values[name](element, name);
if (t.names[name]) name = t.names[name];
if (name.include(':')) {
return (!element.attributes || !element.attributes[name]) ? null :
element.attributes[name].value;
}
}
readAttribute: (function(){
return element.getAttribute(name);
},
var iframeGetAttributeThrowsError = (function(){
var el = document.createElement('iframe'),
isBuggy = false;
document.documentElement.appendChild(el);
try {
el.getAttribute('type', 2);
} catch(e) {
isBuggy = true;
}
document.documentElement.removeChild(el);
el = null;
return isBuggy;
})();
return function(element, name) {
element = $(element);
// check boolean first, to get out of expression faster
if (iframeGetAttributeThrowsError &&
name === 'type' &&
element.tagName.toUpperCase() == 'IFRAME') {
return element.getAttribute('type');
}
if (Prototype.Browser.IE) {
var t = Element._attributeTranslations.read;
if (t.values[name]) return t.values[name](element, name);
if (t.names[name]) name = t.names[name];
if (name.include(':')) {
return (!element.attributes || !element.attributes[name]) ? null :
element.attributes[name].value;
}
}
return element.getAttribute(name);
}
})(),
writeAttribute: function(element, name, value) {
element = $(element);

View File

@ -933,6 +933,11 @@ new Test.Unit.Runner({
var table = $('write_attribute_table');
this.assertEqual('4', table.readAttribute('cellspacing'));
this.assertEqual('6', table.readAttribute('cellpadding'));
var el = document.createElement('iframe');
document.body.appendChild(el);
alert(Element.readAttribute(el, 'type'));
document.body.removeChild(el);
},
testElementWriteAttribute: function() {