From 7d64e4b756caff7cb6682080b4ec018ed8519f58 Mon Sep 17 00:00:00 2001 From: David Haz Date: Sat, 12 Jul 2025 10:41:29 +0300 Subject: [PATCH] Refactor event listeners to use container for touch and wheel events --- .../CircularGallery/CircularGallery.vue | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/content/Components/CircularGallery/CircularGallery.vue b/src/content/Components/CircularGallery/CircularGallery.vue index 5822ffa..66be81e 100644 --- a/src/content/Components/CircularGallery/CircularGallery.vue +++ b/src/content/Components/CircularGallery/CircularGallery.vue @@ -639,28 +639,32 @@ class App { this.boundOnTouchDown = this.onTouchDown.bind(this) this.boundOnTouchMove = this.onTouchMove.bind(this) this.boundOnTouchUp = this.onTouchUp.bind(this) + window.addEventListener('resize', this.boundOnResize) - window.addEventListener('mousewheel', this.boundOnWheel) - window.addEventListener('wheel', this.boundOnWheel) - window.addEventListener('mousedown', this.boundOnTouchDown) + + this.container.addEventListener('wheel', this.boundOnWheel) + this.container.addEventListener('mousedown', this.boundOnTouchDown) + this.container.addEventListener('touchstart', this.boundOnTouchDown) + window.addEventListener('mousemove', this.boundOnTouchMove) window.addEventListener('mouseup', this.boundOnTouchUp) - window.addEventListener('touchstart', this.boundOnTouchDown) window.addEventListener('touchmove', this.boundOnTouchMove) window.addEventListener('touchend', this.boundOnTouchUp) } destroy() { window.cancelAnimationFrame(this.raf) + window.removeEventListener('resize', this.boundOnResize) - window.removeEventListener('mousewheel', this.boundOnWheel) - window.removeEventListener('wheel', this.boundOnWheel) - window.removeEventListener('mousedown', this.boundOnTouchDown) window.removeEventListener('mousemove', this.boundOnTouchMove) window.removeEventListener('mouseup', this.boundOnTouchUp) - window.removeEventListener('touchstart', this.boundOnTouchDown) window.removeEventListener('touchmove', this.boundOnTouchMove) window.removeEventListener('touchend', this.boundOnTouchUp) + + this.container.removeEventListener('wheel', this.boundOnWheel) + this.container.removeEventListener('mousedown', this.boundOnTouchDown) + this.container.removeEventListener('touchstart', this.boundOnTouchDown) + if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) { this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas as HTMLCanvasElement) }