fix onScreenEvent listeners.

This commit is contained in:
Christopher Jeffrey 2015-05-01 22:03:25 -07:00
parent 245b3f44b1
commit 3205dd289d
1 changed files with 7 additions and 9 deletions

View File

@ -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() {