Skip to content

Commit 82f8940

Browse files
author
Jihye Hong
authored
Merge pull request w3c#79 from jihyerish/polyfill-fix-getDistance-bug
Fix the bug in getDistance function
2 parents b7c5002 + 8611e35 commit 82f8940

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

polyfill/spatnav-heuristic.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ function focusNavigationHeuristics(spatnavPolyfillOptions) {
4444
e.preventDefault();
4545
navigate(dir);
4646
}
47+
startingPosition = null;
4748
});
4849

4950
/*
50-
* mouseclick EventListener :
51-
* If the mouse click a point in the page, the point will be the starting point.
52-
*/
51+
* mouseclick EventListener :
52+
* If the mouse click a point in the page, the point will be the starting point.
53+
*/
5354
document.addEventListener('click', function(e) {
5455
startingPosition = {xPosition: e.clientX, yPosition: e.clientY};
5556
});
@@ -124,7 +125,7 @@ function focusNavigationHeuristics(spatnavPolyfillOptions) {
124125

125126
if (Array.isArray(candidates) && candidates.length > 0) {
126127
// 9
127-
const bestCandidate = selectBestCandidate(eventTarget, candidates, dir, container);
128+
const bestCandidate = selectBestCandidate(eventTarget, candidates, dir);
128129
if (bestCandidate) {
129130
// 10 & 11
130131
focusingController(bestCandidate, dir);
@@ -261,7 +262,7 @@ function focusNavigationHeuristics(spatnavPolyfillOptions) {
261262
if((isContainer(this) || this.nodeName === 'BODY') && !(this.nodeName === 'INPUT'))
262263
bestCandidate = selectBestCandidateFromEdge(this, candidates_, dir);
263264
else
264-
bestCandidate = selectBestCandidate(this, candidates_, dir, container_);
265+
bestCandidate = selectBestCandidate(this, candidates_, dir);
265266
}
266267

267268
return bestCandidate;
@@ -854,8 +855,8 @@ function focusNavigationHeuristics(spatnavPolyfillOptions) {
854855
* @param {SpatialNavigationDirection} direction
855856
* @returns {distance} euclidian distance between two elements
856857
*/
857-
function getEntryAndExitPoints(rect1, rect2, dir) {
858-
const points = {entryPoint:[0,0], exitPoint:[0,0]};
858+
function getEntryAndExitPoints(dir = 'down', rect1, rect2) {
859+
let points = {entryPoint:[0,0], exitPoint:[0,0]};
859860

860861
// Set direction
861862
switch (dir) {

0 commit comments

Comments
 (0)