From afd4003835dc5cc8bb97ac9824d530a690e9eccc Mon Sep 17 00:00:00 2001 From: Fabian Irsara Date: Tue, 1 Dec 2015 22:36:31 +0100 Subject: [PATCH] destroy window events when calling destroy correctly --- src/dat/gui/GUI.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dat/gui/GUI.js b/src/dat/gui/GUI.js index b0f61d3..024eaa0 100644 --- a/src/dat/gui/GUI.js +++ b/src/dat/gui/GUI.js @@ -425,10 +425,14 @@ define([ } - dom.bind(window, 'resize', function() { _this.onResize() }); - dom.bind(this.__ul, 'webkitTransitionEnd', function() { _this.onResize(); }); - dom.bind(this.__ul, 'transitionend', function() { _this.onResize() }); - dom.bind(this.__ul, 'oTransitionEnd', function() { _this.onResize() }); + var _resizeHandler = function () { + _this.onResize(); + }; + + dom.bind(window, 'resize', _resizeHandler); + dom.bind(this.__ul, 'webkitTransitionEnd', _resizeHandler); + dom.bind(this.__ul, 'transitionend', _resizeHandler); + dom.bind(this.__ul, 'oTransitionEnd', _resizeHandler); this.onResize(); @@ -482,14 +486,14 @@ define([ GUI.TEXT_CLOSED = 'Close Controls'; GUI.TEXT_OPEN = 'Open Controls'; - dom.bind(window, 'keydown', function(e) { - + var _keydownHandler = function(e) { if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode == HIDE_KEY_CODE)) { GUI.toggleHide(); } + }; - }, false); + dom.bind(window, 'keydown', _keydownHandler, false); common.extend( @@ -558,6 +562,10 @@ define([ auto_place_container.removeChild(this.domElement); } + dom.unbind(window, 'keydown', _keydownHandler, false); + dom.unbind(window, 'unload', saveToLocalStorage); + dom.unbind(window, 'resize', _resizeHandler); + }, /**