From 1d0fb77ec38e958d39a6e3bee5a67ec37059891e Mon Sep 17 00:00:00 2001 From: jdalton Date: Thu, 15 May 2008 16:32:00 -0500 Subject: [PATCH] Force Element.Methods.Simulated.hasAttribute() to return a boolean value. --- src/dom.js | 2 +- test/unit/dom_test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dom.js b/src/dom.js index f52bc71..8c82900 100644 --- a/src/dom.js +++ b/src/dom.js @@ -1028,7 +1028,7 @@ Element.Methods.Simulated = { hasAttribute: function(element, attribute) { attribute = Element._attributeTranslations.has[attribute] || attribute; var node = $(element).getAttributeNode(attribute); - return node && node.specified; + return !!(node && node.specified); } }; diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index 6aedb61..fa9abb1 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -1002,6 +1002,18 @@ new Test.Unit.Runner({ this.assertEqual('26', p.readAttribute('age')); }, + testElementHasAttribute: function() { + var label = $('write_attribute_label'); + this.assertIdentical(true, label.hasAttribute('for')); + this.assertIdentical(false, label.hasAttribute('htmlFor')); + this.assertIdentical(false, label.hasAttribute('className')); + this.assertIdentical(false, label.hasAttribute('rainbows')); + + var input = $('write_attribute_input'); + this.assertNotIdentical(null, input.hasAttribute('readonly')); + this.assertNotIdentical(null, input.hasAttribute('readOnly')); + }, + testNewElement: function() { this.assert(new Element('h1'));