prototype: Element.addMethods should add methods to Element as well as Element.Methods. Closes #7888.

This commit is contained in:
Sam Stephenson 2007-04-24 05:23:41 +00:00
parent 7a324b859c
commit 63342b9c01
3 changed files with 24 additions and 1 deletions

View File

@ -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]

View File

@ -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 };

View File

@ -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) {