Added flag to enable tap clicks for SVG in tested circumstances.

This commit is contained in:
2019-07-05 16:29:50 +02:00
parent f68d8b53a3
commit d0c89a78c2
4 changed files with 39 additions and 21 deletions
+6 -3
View File
@@ -80,9 +80,6 @@ for(let key of ['women', 'king']) {
app.run()
animatePolygons()
</script>
<h1>
Interactive Content
</h1>
@@ -102,6 +99,11 @@ can be configured by allowClickDistance. The default value is 44px.
<img draggable="false" style="position: absolute;" src="examples/women.jpeg" />
<a style="position:absolute; top: 10px; right: 10px; color:white;" href="javascript:alert('test link')">A Link</a>
<div onclick="alert('div clicked')" style="position:absolute; top: 30px; right: 10px; color:white;">A Div with click handler</div>
<svg onclick="alert('svg clicked')" style="position: absolute; right: 0px; bottom: 0px; width: 32px; height: 32px;" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<circle cx="50" cy="50" r="44" stroke="white" stroke-width="8" fill="gray" />
<circle cx="50" cy="32" r="7" fill="white" />
<line x1="50" y1="46" x2="50" y2="78" stroke="white" stroke-width="12" />
</svg>
</div>
</div>
@@ -115,6 +117,7 @@ can be configured by allowClickDistance. The default value is 44px.
height: 184,
clickOnTap: true,
throwVisibility: 88,
triggerSVGClicks: true,
minScale: 0.5,
maxScale: 1.5})
+8 -3
View File
@@ -1044,6 +1044,7 @@ export class DOMScatter extends AbstractScatter {
height = null, // required
resizable = false,
clickOnTap = false,
triggerSVGClicks = false,
allowClickDistance = 44,
verbose = true,
onResize = null,
@@ -1096,6 +1097,7 @@ export class DOMScatter extends AbstractScatter {
this.throwVisibility = Math.min(width, height, throwVisibility)
this.container = container
this.clickOnTap = clickOnTap
this.triggerSVGClicks = triggerSVGClicks
this.scale = startScale
this.rotationDegrees = this.startRotationDegrees
this.transformOrigin = transformOrigin
@@ -1152,9 +1154,11 @@ export class DOMScatter extends AbstractScatter {
Therefore we make an exception and let the original click event through.
*/
if (event.target.ownerSVGElement) {
return
if (this.triggerSVGClicks) {
return
}
}
if (event.isTrusted) {
else if (event.isTrusted) {
Events.stop(event)
}
}, true)
@@ -1336,7 +1340,8 @@ export class DOMScatter extends AbstractScatter {
if (nearestNode.tagName == 'svg') {
let handler = this.tapNodes.get(nearestNode)
console.log("Clicking beneath SVG: to be done", handler)
// nearestNode.dispatchEvent(new Event('click'))
if (this.triggerSVGClicks)
nearestNode.dispatchEvent(new Event('click'))
return
}
console.log("nearestNode clicked")