Jquery .off vs dojo? -
what equivalent of jquery $.off(event)
remove event on element passing event name in dojo?
i tried :
dojo.disconnect(handle) // dont have handle event
how handle or there better way to it?
there no out of box solution far know of, have implement 1 yourself. however, dangerous feature, if disconnect event handlers of specific type.
however, use dojo/aspect
module intercept calls dojo/on
module, example:
aspect.around(arguments, 0, function(original) { on.signals = [ ]; return function(dom, name, handler) { console.log(arguments); on.signals.push({ signal: original.apply(this, arguments), name: name }); }; }, true);
i didn't find proper way put aspect around function itself, rather function wrapped inside object. used dirty trick , used arguments
array , because on
module first argument, put aspect around dojo/on
reference.
what happens when bind event handler using dojo/on
, save inside array. write own dojo/on::off()
function, example:
on.off = function(eventname) { arrayutils.foreach(on.signals, function(signal) { if (signal.name === eventname) { signal.signal.remove(); } }); };
now can use:
on.off("click");
to disconnect click event handlers.
a full example can found on jsfiddle: http://jsfiddle.net/lj5yg/ improved.
Comments
Post a Comment