Skip to content

Commit

Permalink
Allow passing just an event and ID to turn off listener
Browse files Browse the repository at this point in the history
Fixes #767
  • Loading branch information
goldfire committed May 19, 2017
1 parent 8f3c569 commit 5cfdb52
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,10 +1548,17 @@
var events = self['_on' + event];
var i = 0;

if (fn) {
// Allow passing just an event and ID.
if (typeof fn === 'number') {
id = fn;
fn = null;
}

if (fn || id) {
// Loop through event store and remove the passed function.
for (i=0; i<events.length; i++) {
if (fn === events[i].fn && id === events[i].id) {
var isId = (id === events[i].id);
if (fn === events[i].fn && isId || !fn && isId) {
events.splice(i, 1);
break;
}
Expand Down

0 comments on commit 5cfdb52

Please sign in to comment.