From c2d18731657ea76ca6909aeb3af7c73a70f1859b Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Sun, 10 Mar 2013 14:02:37 +0100 Subject: [PATCH] fix(jqLite): mouseenter/-leave should not trigger on child elements Mouseenter and mouseleave events were triggered on children of the element they were bound to. Change this to the expected behaviour, to only be triggered when leaving/entering the actual element, not its children. Closes #2131 --- src/jqLite.js | 10 +++++----- test/jqLiteSpec.js | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/jqLite.js mode change 100644 => 100755 test/jqLiteSpec.js diff --git a/src/jqLite.js b/src/jqLite.js old mode 100644 new mode 100755 index 2c209ecde516..e86920ebfe54 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -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'); } }); diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js old mode 100644 new mode 100755 index b1fa6b058207..f15b063c37d9 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -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();