use different identifiers to avoid mixin events

This commit is contained in:
Martin Zimmermann 2014-08-11 12:48:05 +02:00
parent c8acd461d3
commit d9098b83f0

View File

@ -39,31 +39,31 @@ define(function() {
}); });
}; };
window.Element.prototype.toggle = function(type, on, off) { window.Element.prototype.toggle = function(type, a, b) {
/* /*
Toggle between two internal states on event :param type: e.g. to Toggle between two internal states on event :param type: e.g. to
cycle form visibility. Callback :param on: is called on first event, cycle form visibility. Callback :param a: is called on first event,
:param off: next time. :param b: next time.
You can skip to the next state without executing the callback with You can skip to the next state without executing the callback with
`toggler.next()`. You can prevent a cycle when you call `toggler.wait()` `toggler.next()`. You can prevent a cycle when you call `toggler.wait()`
during an event. during an event.
*/ */
function Toggle(el, on, off) { function Toggle(el, a, b) {
this.state = false; this.state = false;
this.el = el; this.el = el;
this.on = on; this.a = a;
this.off = off; this.b = b;
} }
Toggle.prototype.next = function next() { Toggle.prototype.next = function next() {
if (! this.state) { if (! this.state) {
this.state = true; this.state = true;
this.on(this); this.a(this);
} else { } else {
this.state = false; this.state = false;
this.off(this); this.b(this);
} }
}; };
@ -71,7 +71,7 @@ define(function() {
this.state = ! this.state; this.state = ! this.state;
}; };
var toggler = new Toggle(this, on, off); var toggler = new Toggle(this, a, b);
this.on(type, function() { this.on(type, function() {
toggler.next(); toggler.next();
}); });