so is something like this possible?
Y.one("input.units").on("keyup change", function(e){
...
});
the jquery equivalent is
$("input.units").bind("keyup change", function(e){
...
});
Yes, this is possible. Just pass an array of event names instead of a string:
Y.one('input.units').on(['keyup', 'change'], function (e) {
// ...
});
Why not try something like this:
var actionFunction = function(e) { /* stuff goes here */ };
node.one("input.units").on("keyup", actionFunction);
node.one("input.units").on("change", actionFunction);
EDIT: YUI supports this natively. See Ryan's answer below.
No. You could do something like this, though:
YUI().use("node", "oop", function (Y) {
var on = Y.Node.prototype.on;
function detachOne(handle) {
handle.detach();
}
Y.mix(Y.Node.prototype, {
on: function (type, fn, context) {
var args = Y.Array(arguments),
types = args[0].split(" "),
handles = [];
Y.each(types, function (type) {
args[0] = type;
handles.push(on.apply(this, args));
})
return {
detach: Y.bind(Y.each, null, handles, detachOne)
};
}
}, true);
})
This code wraps Node.on() to accept a string of space-delimited event types. It returns an object with a single method, detach, which detaches your handler from all of the events.
Note that this code only affects the Y instance inside its sandbox, so you should put it inside the function that you pass to YUI().use
. It would also be easy to package it up as a module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With