diff --git a/lib/widget.js b/lib/widget.js index f4f9b5c..8b2a114 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2521,21 +2521,19 @@ Element.prototype.sattr = function(style, fg, bg) { Element.prototype.onScreenEvent = function(type, handler) { this.screen.on(type, handler); - this._elisteners = this._elisteners || {}; - this._elisteners[this.uid] = this._elisteners[this.uid] || []; - this._elisteners[this.uid].push({ type: type, handler: handler }); + var listeners = this._slisteners = this._slisteners || []; + listeners.push({ type: type, handler: handler }); }; Element.prototype.removeScreenEvent = function(type, handler) { this.screen.removeListener(type, handler); - this._elisteners = this._elisteners || {}; - var listeners = this.screen._elisteners[this.uid] || []; + var listeners = this._slisteners = this._slisteners || []; for (var i = 0; i < listeners.length; i++) { var listener = listeners[i]; if (listener.type === type && listener.handler === handler) { listeners.splice(i, 1); - if (this.screen._elisteners[this.uid].length === 0) { - delete this.screen._elisteners[this.uid]; + if (this._slisteners.length === 0) { + delete this._slisteners; } return; } @@ -2543,12 +2541,12 @@ Element.prototype.removeScreenEvent = function(type, handler) { }; Element.prototype.free = function() { - this._elisteners = this._elisteners || {}; - var listeners = this.screen._elisteners[this.uid] || []; + var listeners = this._slisteners = this._slisteners || []; for (var i = 0; i < listeners.length; i++) { var listener = listeners[i]; this.screen.removeListener(listener.type, listener.handler); } + delete this._slisteners; }; Element.prototype.destroy = function() {