In YUI3, is it possible to connect one handler to several events?

so is something like this possible?

Y.one("input.units").on("keyup change", function(e){
    ...
});

jquery equivalent

$("input.units").bind("keyup change", function(e){
    ...
});
+5
source share
3 answers

Yes it is possible. Just pass an array of event names instead of the string:

Y.one('input.units').on(['keyup', 'change'], function (e) {
    // ...
});
+10
source

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);
+1
source

EDIT: YUI . . .

. - :

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

Node.on(), , . , , .

, Y , , YUI().use. .

+1
source

All Articles