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

fix(jqLite): mouseenter/-leave should not trigger on child elements #2134

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/jqLite.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,20 @@ forEach({

if (!eventFns) {
if (type == 'mouseenter' || type == 'mouseleave') {
var counter = 0;
var entered = false;

events.mouseenter = [];
events.mouseleave = [];

bindFn(element, 'mouseover', function(event) {
counter++;
if (counter == 1) {
if (!entered) {
entered = true;
handle(event, 'mouseenter');
}
});
bindFn(element, 'mouseout', function(event) {
counter --;
if (counter == 0) {
if (entered && indexOf(element.getElementsByTagName('*'), (event.toElement || event.relatedTarget)) === -1) {
entered = false;
handle(event, 'mouseleave');
}
});
Expand Down
2 changes: 0 additions & 2 deletions test/jqLiteSpec.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,6 @@ describe('jqLite', function() {
child.mouseover();
expect(log).toEqual('parentEnter;childEnter;');

child.mouseout();
expect(log).toEqual('parentEnter;childEnter;');
child.mouseout();
expect(log).toEqual('parentEnter;childEnter;childLeave;');
parent.mouseout();
Expand Down