From 62ebd04231bcb105385495977b1ec0381488dfe7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 21 Jul 2013 02:12:16 -0500 Subject: [PATCH] move el.focus code elsewhere. --- lib/widget.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index fe19fe3..be3150a 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1150,6 +1150,7 @@ Screen.prototype.focusPush = function(el) { this.history.shift(); } this.history.push(el); + el._focus(); }; Screen.prototype.focusLast = @@ -1612,8 +1613,11 @@ Element.prototype.toggle = function() { }; Element.prototype.focus = function() { - var old = this.screen.focused; this.screen.focused = this; +}; + +Element.prototype._focus = function() { + var old = this.screen.history[this.screen.history.length-2]; // Find a scrollable ancestor if we have one. var el = this; @@ -1640,7 +1644,7 @@ Element.prototype.focus = function() { } } - old.emit('blur', this); + if (old) old.emit('blur', this); this.emit('focus', old); this.screen.emit('element blur', old, this); this.screen.emit('element focus', old, this);