Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(jqLite): support space-seperated events in off
Browse files Browse the repository at this point in the history
Closes #3256
  • Loading branch information
ajoslin authored and IgorMinar committed Jul 31, 2013
1 parent f274c0a commit bdd4e98
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ function JQLiteOff(element, type, fn) {
delete events[type];
});
} else {
if (isUndefined(fn)) {
removeEventListenerFn(element, type, events[type]);
delete events[type];
} else {
arrayRemove(events[type], fn);
}
forEach(type.split(' '), function(type) {
if (isUndefined(fn)) {
removeEventListenerFn(element, type, events[type]);
delete events[type];
} else {
arrayRemove(events[type], fn);
}
});
}
}

Expand Down
51 changes: 51 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,31 @@ describe('jqLite', function() {
});


it('should deregister all listeners for types separated by spaces', function() {
var aElem = jqLite(a),
clickSpy = jasmine.createSpy('click'),
mouseoverSpy = jasmine.createSpy('mouseover');

aElem.on('click', clickSpy);
aElem.on('mouseover', mouseoverSpy);

browserTrigger(a, 'click');
expect(clickSpy).toHaveBeenCalledOnce();
browserTrigger(a, 'mouseover');
expect(mouseoverSpy).toHaveBeenCalledOnce();

clickSpy.reset();
mouseoverSpy.reset();

aElem.off('click mouseover');

browserTrigger(a, 'click');
expect(clickSpy).not.toHaveBeenCalled();
browserTrigger(a, 'mouseover');
expect(mouseoverSpy).not.toHaveBeenCalled();
});


it('should deregister specific listener', function() {
var aElem = jqLite(a),
clickSpy1 = jasmine.createSpy('click1'),
Expand Down Expand Up @@ -974,6 +999,32 @@ describe('jqLite', function() {
browserTrigger(a, 'click');
expect(clickSpy2).not.toHaveBeenCalled();
});


it('should deregister specific listener for multiple types separated by spaces', function() {
var aElem = jqLite(a),
masterSpy = jasmine.createSpy('master'),
extraSpy = jasmine.createSpy('extra');

aElem.on('click', masterSpy);
aElem.on('click', extraSpy);
aElem.on('mouseover', masterSpy);

browserTrigger(a, 'click');
browserTrigger(a, 'mouseover');
expect(masterSpy.callCount).toBe(2);
expect(extraSpy).toHaveBeenCalledOnce();

masterSpy.reset();
extraSpy.reset();

aElem.off('click mouseover', masterSpy);

browserTrigger(a, 'click');
browserTrigger(a, 'mouseover');
expect(masterSpy).not.toHaveBeenCalled();
expect(extraSpy).toHaveBeenCalledOnce();
});
});


Expand Down

0 comments on commit bdd4e98

Please sign in to comment.