Skip to content

Commit 5b19579

Browse files
committed
fixes #1653
1 parent 4110f00 commit 5b19579

File tree

5 files changed

+38
-43
lines changed

5 files changed

+38
-43
lines changed

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/solution.view/index.html

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@
2020
<div id="tooltip" hidden>Tooltip</div>
2121

2222
<script>
23-
// for the demo
24-
setTimeout(function() {
25-
new HoverIntent({
26-
elem,
27-
over() {
28-
tooltip.style.left = elem.getBoundingClientRect().left + 5 + 'px';
29-
tooltip.style.top = elem.getBoundingClientRect().bottom + 5 + 'px';
30-
tooltip.hidden = false;
31-
},
32-
out() {
33-
tooltip.hidden = true;
34-
}
35-
});
36-
}, 2000);
23+
new HoverIntent({
24+
elem,
25+
over() {
26+
tooltip.style.left = elem.getBoundingClientRect().left + 5 + 'px';
27+
tooltip.style.top = elem.getBoundingClientRect().bottom + 5 + 'px';
28+
tooltip.hidden = false;
29+
},
30+
out() {
31+
tooltip.hidden = true;
32+
}
33+
});
3734
</script>
3835

3936
</body>

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/solution.view/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ describe("hoverIntent", function() {
4949
}
5050
})
5151

52-
it("mouseover -> immediately no tooltip", function() {
52+
it("mouseover -> when the pointer just arrived, no tooltip", function() {
5353
mouse('mouseover', 10, 10);
5454
assert.isFalse(isOver);
5555
});
5656

57-
it("mouseover -> pause shows tooltip", function() {
57+
it("mouseover -> after a delay, the tooltip shows up", function() {
5858
mouse('mouseover', 10, 10);
5959
this.clock.tick(100);
6060
assert.isTrue(isOver);
6161
});
6262

63-
it("mouseover -> fast mouseout no tooltip", function() {
63+
it("mouseover -> followed by fast mouseout leads doesn't show tooltip", function() {
6464
mouse('mouseover', 10, 10);
6565
setTimeout(
6666
() => mouse('mouseout', 300, 300, { relatedTarget: document.body}),

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/source.view/hoverIntent.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class HoverIntent {
4545

4646
destroy() {
4747
/* your code to "disable" the functionality, remove all handlers */
48+
/* it's needed for the tests to work */
4849
}
4950

5051
}

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/source.view/index.html

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@
2020
<div id="tooltip" hidden>Tooltip</div>
2121

2222
<script>
23-
// for the demo
24-
setTimeout(function() {
25-
new HoverIntent({
26-
elem,
27-
over() {
28-
tooltip.style.left = elem.getBoundingClientRect().left + 5 + 'px';
29-
tooltip.style.top = elem.getBoundingClientRect().bottom + 5 + 'px';
30-
tooltip.hidden = false;
31-
},
32-
out() {
33-
tooltip.hidden = true;
34-
}
35-
});
36-
}, 2000);
23+
new HoverIntent({
24+
elem,
25+
over() {
26+
tooltip.style.left = elem.getBoundingClientRect().left + 5 + 'px';
27+
tooltip.style.top = elem.getBoundingClientRect().bottom + 5 + 'px';
28+
tooltip.hidden = false;
29+
},
30+
out() {
31+
tooltip.hidden = true;
32+
}
33+
});
3734
</script>
3835

3936
</body>

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/source.view/test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
describe("hoverIntent", function() {
44

55
function mouse(eventType, x, y, options) {
6-
let eventOptions = Object.assign({
6+
let eventOptions = Object.assign({
77
bubbles: true,
88
clientX: x,
99
clientY: y,
1010
pageX: x,
1111
pageY: y,
1212
target: elem
1313
}, options || {});
14-
14+
1515
elem.dispatchEvent(new MouseEvent(eventType, eventOptions));
1616
}
1717

1818

1919
let isOver;
2020
let hoverIntent;
21-
22-
21+
22+
2323
before(function() {
2424
this.clock = sinon.useFakeTimers();
2525
});
2626

2727
after(function() {
2828
this.clock.restore();
2929
});
30-
31-
30+
31+
3232
beforeEach(function() {
3333
isOver = false;
34-
34+
3535
hoverIntent = new HoverIntent({
3636
elem: elem,
3737
over: function() {
@@ -49,18 +49,18 @@ describe("hoverIntent", function() {
4949
}
5050
})
5151

52-
it("mouseover -> immediately no tooltip", function() {
52+
it("mouseover -> when the pointer just arrived, no tooltip", function() {
5353
mouse('mouseover', 10, 10);
5454
assert.isFalse(isOver);
5555
});
56-
57-
it("mouseover -> pause shows tooltip", function() {
56+
57+
it("mouseover -> after a delay, the tooltip shows up", function() {
5858
mouse('mouseover', 10, 10);
5959
this.clock.tick(100);
6060
assert.isTrue(isOver);
6161
});
6262

63-
it("mouseover -> fast mouseout no tooltip", function() {
63+
it("mouseover -> followed by fast mouseout leads doesn't show tooltip", function() {
6464
mouse('mouseover', 10, 10);
6565
setTimeout(
6666
() => mouse('mouseout', 300, 300, { relatedTarget: document.body}),
@@ -94,5 +94,5 @@ describe("hoverIntent", function() {
9494
this.clock.tick(200);
9595
assert.isFalse(isOver);
9696
});
97-
97+
9898
});

0 commit comments

Comments
 (0)