Changed wrapper and events to allow other EventListeners.

This commit is contained in:
Severin Opel 2021-01-26 08:01:51 +01:00
parent fa0256d782
commit ca5a39d661
2 changed files with 21 additions and 13 deletions

View File

@ -54,7 +54,7 @@ export default class CardWrapper extends Object {
isClickable(node) { isClickable(node) {
if (node == null) return false if (node == null) return false
// console.log("isClickable", node, this.isClickPrevented(node)) // console.log("isClickable", node, this.isClickPrevented(node))
if (this.isClickPrevented(node)) { if (this.isClickPrevented(node)) {
return false return false
} }
@ -101,8 +101,8 @@ export default class CardWrapper extends Object {
let clickRects = activeNodes.map(link => { let clickRects = activeNodes.map(link => {
let rect = link.getBoundingClientRect() let rect = link.getBoundingClientRect()
// Since the getBoundingClientRect is untransformed we cannot rely on it's size // Since the getBoundingClientRect is untransformed we cannot rely on it's size
// We need a transformed bottom right to calculate local width and height // We need a transformed bottom right to calculate local width and height
let bottomRight = Points.fromPageToNode(element, { let bottomRight = Points.fromPageToNode(element, {
x: rect.x + rect.width, x: rect.x + rect.width,
y: rect.y + rect.height y: rect.y + rect.height
@ -146,14 +146,19 @@ export default class CardWrapper extends Object {
/* https://stackoverflow.com/questions/49564905/is-it-possible-to-use-click-function-on-svg-tags-i-tried-element-click-on-a /* https://stackoverflow.com/questions/49564905/is-it-possible-to-use-click-function-on-svg-tags-i-tried-element-click-on-a
proposes the dispatchEvent solution. But this leads to problems in flippable.html hiding the back page. proposes the dispatchEvent solution. But this leads to problems in flippable.html hiding the back page.
Therefore we use the original click event (see constructor). */ Therefore we use the original click event (see constructor). */
if (this.isSVGNode(node)) { // if (this.isSVGNode(node)) {
if (this.triggerSVGClicks) { // if (this.triggerSVGClicks) {
let click = new Event('click') // let click = new Event('click')
node.dispatchEvent(click) // node.dispatchEvent(click)
} // }
return // return
} // }
node.click() // node.click()
let click = new Event('click')
click.clientX = event.clientX
click.clientY = event.clientY
node.dispatchEvent(click)
} }
nodeTapped(node, event) { nodeTapped(node, event) {
@ -200,4 +205,4 @@ export default class CardWrapper extends Object {
this.tapNodes.set(objOrSelector, handler) this.tapNodes.set(objOrSelector, handler)
} }
} }
} }

View File

@ -1,7 +1,10 @@
export default class Events { export default class Events {
static stop(event) { static stop(event) {
event.preventDefault() event.preventDefault()
event.stopPropagation() // I removed this, as it destroys all the Hammer.js events.
// And also the click event.
// It seems to have no (apparent) negative impact. -SO
// event.stopPropagation()
} }
static extractPoint(event) { static extractPoint(event) {