Fixed bug in nearestActive.
This commit is contained in:
+3
-31
@@ -94,42 +94,14 @@ export default class CardWrapper extends Object {
|
||||
}
|
||||
|
||||
nearestActive(event) {
|
||||
let element = this.domNode
|
||||
let activeNodes = this.activeNodes()
|
||||
let globalClick = event.center ? event.center : { x: event.x, y: event.y }
|
||||
let localClick = Points.fromPageToNode(element, globalClick)
|
||||
|
||||
let clickRects = activeNodes.map((link) => {
|
||||
let rect = link.getBoundingClientRect()
|
||||
// Since the getBoundingClientRect is untransformed we cannot rely on it's size
|
||||
// We need a transformed bottom right to calculate local width and height
|
||||
let bottomRight = Points.fromPageToNode(element, {
|
||||
x: rect.x + rect.width,
|
||||
y: rect.y + rect.height,
|
||||
})
|
||||
let topLeft = Points.fromPageToNode(element, rect)
|
||||
let width = Math.abs(bottomRight.x - topLeft.x)
|
||||
let height = Math.abs(bottomRight.y - topLeft.y)
|
||||
let center = Points.fromPageToNode(element, {
|
||||
x: rect.x + width / 2,
|
||||
y: rect.y + height / 2,
|
||||
})
|
||||
return {
|
||||
x: topLeft.x,
|
||||
y: topLeft.y,
|
||||
width,
|
||||
height,
|
||||
center,
|
||||
link,
|
||||
}
|
||||
})
|
||||
|
||||
let distances = []
|
||||
clickRects.forEach((rect) => {
|
||||
let distance = Points.distanceToRect(localClick, rect)
|
||||
activeNodes.forEach((link) => {
|
||||
let rect = link.getBoundingClientRect()
|
||||
let distance = Points.distanceToRect(globalClick, rect)
|
||||
distances.push(parseInt(distance))
|
||||
})
|
||||
|
||||
let closestClickIndex = distances.indexOf(Math.min(...distances))
|
||||
let closestClickable = activeNodes[closestClickIndex]
|
||||
if (distances[closestClickIndex] < this.allowClickDistance) {
|
||||
|
||||
Reference in New Issue
Block a user