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:
parent
e9bdaef0af
commit
043653a282
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue