Added click handler to avoid double calls of click event handler.

This commit is contained in:
2019-07-05 15:03:22 +02:00
parent 6392e4b13a
commit 84ea33f029
3 changed files with 62 additions and 29 deletions
+20 -9
View File
@@ -1142,6 +1142,17 @@ export class DOMScatter extends AbstractScatter {
})
this.resizeButton = button
}
if (clickOnTap) {
/* Since the tap triggers a synthetic click event
we must prevent the original trusted click event which
is also dispatched by the system.
*/
element.addEventListener('click', event => {
if (event.isTrusted) {
Events.stop(event)
}
}, true)
}
container.add(this)
}
@@ -1302,23 +1313,24 @@ export class DOMScatter extends AbstractScatter {
}
onTap(event, interaction, point) {
if (this.clickOnTap) {
let directNode = document.elementFromPoint(event.clientX, event.clientY)
console.log("onTap", directNode, this.isClickable(directNode))
console.log("onTap", event)
if (this.isClickable(directNode)) {
directNode.click()
}
else {
let nearestNode = this.nearestClickable(event)
if (this.isClickable(nearestNode)) {
if (nearestNode.tagName == 'svg') {
let handler = this.tapNodes.get(nearestNode)
console.log("Clicking beneath SVG: to be done", handler)
Events.stop(event)
return
let handler = this.tapNodes.get(nearestNode)
console.log("Clicking beneath SVG: to be done", handler)
Events.stop(event)
return
}
console.log("nearestNode clicked")
nearestNode.click()
}
}
@@ -1352,7 +1364,7 @@ export class DOMScatter extends AbstractScatter {
return true
if (node.hasAttribute("onclick"))
return true
if (this.tapNodes.has(node))
if (this.tapNodes.has(node))
return true
return false
}
@@ -1396,7 +1408,6 @@ export class DOMScatter extends AbstractScatter {
let closestClickIndex = distances.indexOf(Math.min(...distances))
let closestClickable = clickables[closestClickIndex]
if (distances[closestClickIndex] < this.allowClickDistance) {
console.log("found closest clickables", closestClickable)
return closestClickable
}
return null