stop hooking addListener.

This commit is contained in:
Christopher Jeffrey 2013-06-11 09:27:50 -05:00
parent 8f4e23130e
commit a7f2823df2

View File

@ -164,19 +164,20 @@ function Screen(options) {
self.program.showCursor();
self.program.normalBuffer();
});
this.on('newListener', function fn(type) {
if (type === 'keypress' || type === 'mouse') {
self.removeListener('newListener', fn);
if (type === 'keypress') self._listenKeys();
if (type === 'mouse') self._listenMouse();
}
});
}
Screen._default = null;
Screen.prototype.__proto__ = Node.prototype;
Screen._addListener = Screen.prototype.addListener;
Screen.prototype.on =
Screen.prototype.addListener = function(type, listener) {
if (type === 'keypress') this._listenKeys();
return Screen._addListener.apply(this, arguments);
};
// TODO: Bubble events.
Screen.prototype._listenMouse = function(el, hover) {
var self = this;
@ -509,6 +510,8 @@ Screen.prototype.fillRegion = function(attr, ch, xi, xl, yi, yl) {
*/
function Element(options) {
var self = this;
Node.call(this, options);
this.position = {
@ -560,31 +563,28 @@ function Element(options) {
top: this.border ? 0 : -1
}));
}
// TODO: Possibly move this to Node for screen.on('mouse', ...).
this.on('newListener', function fn(type) {
if (type === 'mouse'
|| type === 'click'
|| type === 'hover'
|| type === 'mousedown'
|| type === 'mouseup'
|| type === 'mousewheel'
|| type === 'wheeldown'
|| type === 'wheelup'
|| type === 'mousemove'
|| type === 'movement') {
self.screen._listenMouse(self);
} else if (type === 'keypress') {
self.screen._listenKeys(self);
}
});
}
Element.prototype.__proto__ = Node.prototype;
// TODO: Possibly move this to Node for screen.on('mouse', ...).
Element._addListener = Element.prototype.addListener;
Element.prototype.on =
Element.prototype.addListener = function(type, listener) {
if (type === 'mouse'
|| type === 'click'
|| type === 'hover'
|| type === 'mousedown'
|| type === 'mouseup'
|| type === 'mousewheel'
|| type === 'wheeldown'
|| type === 'wheelup'
|| type === 'mousemove'
|| type === 'movement') {
this.screen._listenMouse(this);
} else if (type === 'keypress') {
this.screen._listenKeys(this);
}
return Element._addListener.apply(this, arguments);
};
/*
Element._emit = Element.prototype.emit;
Element.prototype.emit = function(type) {