Skip to content

Commit

Permalink
Make sure getAttribute is used without flag when accessing the "typ…
Browse files Browse the repository at this point in the history
…e" attribute of an iframe (IE throws error otherwise). [#118 state:resolved] (Zekid, kangax)
  • Loading branch information
savetheclocktower committed Feb 24, 2009
1 parent e9bdaef commit 043653a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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)
Expand Down
47 changes: 35 additions & 12 deletions src/dom/dom.js
Expand Up @@ -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(){

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 element.getAttribute(name);
},
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);
Expand Down
5 changes: 5 additions & 0 deletions test/unit/dom_test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 043653a

Please sign in to comment.