Greetings,
I’m trying to override or extend the Element.show() and .hide() methods in mootools in order to add some WAI-Aria toggling. I was trying to use the Class.Refactor() method like this:
Element = Class.refactor(Element, {
show: function(displayString) {
result = this.previous(displayString);
// Do my thing
return result;
},
hide: function() {
result = this.previous();
// Do my thing
return result;
}
});
however, this is not working, previous is null and I think the reason is that Mootools injects those methods through Element.implement. So the methods are not native?
I have figured out how to completely replace .show and .hide but I would like to retain all of their existing functionality and just add to it. Any ideas?
not a refactor guy myself, but you can always do it ‘old school’ and save the previous function in a variable (
_prev_showand_prev_hidefor example), then do your override and call those functions from your new methods.second option would be to try extending Element into itself and call
this.parent(), this is the ‘unsafe’ version of Class.Refactor. [reference]