diff --git a/lib/events.js b/lib/events.js index 429db52..7c04ce3 100644 --- a/lib/events.js +++ b/lib/events.js @@ -79,6 +79,10 @@ EventEmitter.prototype._emit = function(type, args) { var handler = this._events[type] , ret; + // if (type !== 'event') { + // this._emit('event', [type.replace(/^element /, '')].concat(args)); + // } + if (!handler) { if (type === 'error') { throw new args[0]; @@ -101,8 +105,11 @@ EventEmitter.prototype._emit = function(type, args) { EventEmitter.prototype.emit = function(type) { var args = slice.call(arguments, 1) + , params = slice.call(arguments) , el = this; + this._emit('event', params); + if (this.type === 'screen') { return this._emit(type, args); } @@ -113,8 +120,13 @@ EventEmitter.prototype.emit = function(type) { type = 'element ' + type; args.unshift(this); + // `element` prefix + // params = [type].concat(args); + // no `element` prefix + // params.splice(1, 0, this); do { + // el._emit('event', params); if (!el._events[type]) continue; if (el._emit(type, args) === false) { return false; diff --git a/lib/widgets/screen.js b/lib/widgets/screen.js index c79ebff..9d76e58 100644 --- a/lib/widgets/screen.js +++ b/lib/widgets/screen.js @@ -443,9 +443,6 @@ Screen.prototype.destroy = function() { }; Screen.prototype.log = function() { - if (this.debugLog) { - this.debugLog.log.apply(this.debugLog, arguments); - } return this.program.log.apply(this.program, arguments); }; diff --git a/test/widget.js b/test/widget.js index 7244931..d1196c7 100644 --- a/test/widget.js +++ b/test/widget.js @@ -30,6 +30,11 @@ screen.debugLog.on('show', function() { screen.render(); }); +screen.on('event', function(event, el) { + var type = (el && el.type) || Object.prototype.toString.call(el).slice(8, -1); + screen.program.log('emit("%s", {%s})', event, type); +}); + screen.append(blessed.text({ top: 0, left: 2,