Skip to content

Instantly share code, notes, and snippets.

@odoe
Created May 22, 2014 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/7e6b13cfac66e5cc99a5 to your computer and use it in GitHub Desktop.
Save odoe/7e6b13cfac66e5cc99a5 to your computer and use it in GitHub Desktop.
Extension of dojo/on to toggle 2 event handlers
/*global define*/
/*jshint laxcomma:true*/
define([
'dojo/on'
], function(on) {
'use strict';
var _on = on;
_on.switchable = function(target, type, listener1, listener2) {
var funcs
, index
, currentListener
, signal;
funcs = [listener1, listener2];
index = 0;
currentListener = funcs[index];
signal = _on(target, type, function() {
return currentListener.apply(this, arguments);
});
signal.toggle = function() {
index = 1 - index;
currentListener = funcs[index];
};
return signal;
};
return _on;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment