From 63342b9c01b823c668ea77498c5f02fa6ea3460e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 24 Apr 2007 05:23:41 +0000 Subject: [PATCH] prototype: Element.addMethods should add methods to Element as well as Element.Methods. Closes #7888. --- CHANGELOG | 2 ++ src/dom.js | 3 +++ test/unit/dom.html | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 76abecb..d2b1994 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Element.addMethods should add methods to Element as well as Element.Methods. Closes #7888. [Andrew Dupont] + * Add support for per-request onCreate callbacks to Ajax.Request. Closes #8011. [Andrew Dupont] * Don't call evalResponse() when an Ajax response has no Content-type header. Closes #7827. [Tobie Langel] diff --git a/src/dom.js b/src/dom.js index 7c4de17..e2406fb 100644 --- a/src/dom.js +++ b/src/dom.js @@ -633,6 +633,9 @@ Element.addMethods = function(methods) { copy(T[tag], klass.prototype); } } + + Object.extend(Element, Element.Methods); + delete Element.ByTag; }; var Toggle = { display: Element.toggle }; diff --git a/test/unit/dom.html b/test/unit/dom.html index 2afb10c..6b4e541 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -272,6 +272,10 @@ var testVar = 'to be updated', testVar2 = ''; + Element.addMethods({ + hashBrowns: function(element) { return 'hash browns'; } + }); + Element.addMethods("LI", { pancakes: function(element) { return "pancakes"; } }); @@ -929,7 +933,16 @@ window.scrollTo(0, 0); }}, - testSpecificElementMethods: function() {with(this) { + testCustomElementMethods: function() {with(this) { + var elem = $('navigation_test_f'); + assertRespondsTo('hashBrowns', elem); + assertEqual('hash browns', elem.hashBrowns()); + + assertRespondsTo('hashBrowns', Element); + assertEqual('hash browns', Element.hashBrowns(elem)); + }}, + + testSpecificCustomElementMethods: function() {with(this) { var elem = $('navigation_test_f'); assert(Element.Methods.ByTag[elem.tagName]); @@ -947,6 +960,11 @@ assertRespondsTo('orangeJuice', elem2); assertEqual("orange juice", elem.orangeJuice()); assertEqual("orange juice", elem2.orangeJuice()); + + assert(typeof Element.orangeJuice == 'undefined'); + assert(typeof Element.pancakes == 'undefined'); + assert(typeof Element.waffles == 'undefined'); + }}, testScriptFragment: function() {with(this) {