Created
May 22, 2014 17:19
-
-
Save odoe/7e6b13cfac66e5cc99a5 to your computer and use it in GitHub Desktop.
Extension of dojo/on to toggle 2 event handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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