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

Commit

Permalink
fix(jqLite): deregister special mouseenter / mouseleave events co…
Browse files Browse the repository at this point in the history
…rrectly

Closes #12795
Closes #12799
  • Loading branch information
petebacondarwin committed Nov 12, 2015
1 parent 9b6f6e6 commit a16b7df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,13 @@ forEach({
var types = type.indexOf(' ') >= 0 ? type.split(' ') : [type];
var i = types.length;

var addHandler = function(type, specialHandlerWrapper) {
var addHandler = function(type, specialHandlerWrapper, noEventListener) {
var eventFns = events[type];

if (!eventFns) {
eventFns = events[type] = [];
eventFns.specialHandlerWrapper = specialHandlerWrapper;
if (type !== '$destroy') {
if (type !== '$destroy' && !noEventListener) {
addEventListenerFn(element, type, handle);
}
}
Expand All @@ -868,6 +868,7 @@ forEach({
type = types[i];
if (MOUSE_EVENT_MAP[type]) {
addHandler(MOUSE_EVENT_MAP[type], specialMouseHandlerWrapper);
addHandler(type, undefined, true);
} else {
addHandler(type);
}
Expand Down
14 changes: 14 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,20 @@ describe('jqLite', function() {
expect(onMouseleave).toHaveBeenCalledOnce();
});

it('should call a `mouseenter/leave` listener when manually triggering the event', function() {
var aElem = jqLite(a);
var onMouseenter = jasmine.createSpy('mouseenter');
var onMouseleave = jasmine.createSpy('mouseleave');

aElem.on('mouseenter', onMouseenter);
aElem.on('mouseleave', onMouseleave);

aElem.triggerHandler('mouseenter');
expect(onMouseenter).toHaveBeenCalledOnce();

aElem.triggerHandler('mouseleave');
expect(onMouseleave).toHaveBeenCalledOnce();
});


it('should deregister specific listener within the listener and call subsequent listeners', function() {
Expand Down

0 comments on commit a16b7df

Please sign in to comment.