From 71bf642860f2cc34c7120435ed635b893d92e5c5 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 30 Jan 2019 20:17:34 -0500 Subject: [PATCH] Properly remove event listeners from container element (fixes #710). For three event listeners added to the container elements weren't being removed properly, since `removeEventListener` was mistakenly being called on `uiContainer` instead. This was preventing garbage collection. --- src/js/pannellum.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/js/pannellum.js b/src/js/pannellum.js index 4df169b..fa7f947 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -3050,36 +3050,23 @@ function fireEvent(type) { */ this.destroy = function() { if (renderer) - renderer.destroy() + renderer.destroy(); if (listenersAdded) { - dragFix.removeEventListener('mousedown', onDocumentMouseDown, false); - dragFix.removeEventListener('dblclick', onDocumentDoubleClick, false); document.removeEventListener('mousemove', onDocumentMouseMove, false); document.removeEventListener('mouseup', onDocumentMouseUp, false); - uiContainer.removeEventListener('mousewheel', onDocumentMouseWheel, false); - uiContainer.removeEventListener('DOMMouseScroll', onDocumentMouseWheel, false); container.removeEventListener('mozfullscreenchange', onFullScreenChange, false); container.removeEventListener('webkitfullscreenchange', onFullScreenChange, false); container.removeEventListener('msfullscreenchange', onFullScreenChange, false); container.removeEventListener('fullscreenchange', onFullScreenChange, false); window.removeEventListener('resize', onDocumentResize, false); window.removeEventListener('orientationchange', onDocumentResize, false); - uiContainer.removeEventListener('keydown', onDocumentKeyPress, false); - uiContainer.removeEventListener('keyup', onDocumentKeyUp, false); - uiContainer.removeEventListener('blur', clearKeys, false); + container.removeEventListener('keydown', onDocumentKeyPress, false); + container.removeEventListener('keyup', onDocumentKeyUp, false); + container.removeEventListener('blur', clearKeys, false); document.removeEventListener('mouseleave', onDocumentMouseUp, false); - dragFix.removeEventListener('touchstart', onDocumentTouchStart, false); - dragFix.removeEventListener('touchmove', onDocumentTouchMove, false); - dragFix.removeEventListener('touchend', onDocumentTouchEnd, false); - dragFix.removeEventListener('pointerdown', onDocumentPointerDown, false); - dragFix.removeEventListener('pointermove', onDocumentPointerMove, false); - dragFix.removeEventListener('pointerup', onDocumentPointerUp, false); - dragFix.removeEventListener('pointerleave', onDocumentPointerUp, false); } container.innerHTML = ''; container.classList.remove('pnlm-container'); - uiContainer.classList.remove('pnlm-grab'); - uiContainer.classList.remove('pnlm-grabbing'); } }