diff --git a/CHANGELOG b/CHANGELOG index 87afc76..3b99dd2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Use feature testing in `Element#readAttribute` when taking care of Opera's `getAttribute('title')` quirk. (kangax) + * Use `Prototype.emptyFunction` consistently throughout unit tests. [#253 state:resolved] (Michael M Slusarz, John David Dalton, kangax) * deprecation extension: mark Array#reduce() as removed. [#569 state:resolved] (Tobie Langel) diff --git a/src/dom/dom.js b/src/dom/dom.js index c6cea5a..ffc2330 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -609,6 +609,15 @@ Element.Methods = { return isBuggy; })(); + // Opera 9.25 returns `null` instead of "" for getAttribute('title') + // when `title` attribute is not present + var GET_ATTRIBUTE_TITLE_RETURNS_NULL = (function(){ + var el = document.createElement('div'); + var isBuggy = (el.getAttribute('title') === null); + el = null; + return isBuggy; + })(); + return function(element, name) { element = $(element); // check boolean first, to get out of expression faster @@ -617,6 +626,9 @@ Element.Methods = { element.tagName.toUpperCase() == 'IFRAME') { return element.getAttribute('type'); } + if (GET_ATTRIBUTE_TITLE_RETURNS_NULL && name === 'title') { + return element.title; + } if (Prototype.Browser.IE) { var t = Element._attributeTranslations.read; if (t.values[name]) return t.values[name](element, name); @@ -1230,13 +1242,6 @@ if (Prototype.Browser.Opera) { } } ); - - Element.Methods.readAttribute = Element.Methods.readAttribute.wrap( - function(proceed, element, attribute) { - if (attribute === 'title') return element.title; - return proceed(element, attribute); - } - ); } else if (Prototype.Browser.IE) {