save/restore focus.

This commit is contained in:
Christopher Jeffrey 2013-06-20 13:03:31 -05:00
parent 5265275d0d
commit e094f843db
2 changed files with 13 additions and 0 deletions

View File

@ -197,6 +197,8 @@ The screen on which every other node renders.
- **focusNext()** - focus next element in the index.
- **focusPush(element)** - push element on the focus stack (equivalent to `screen.focused = el`).
- **focusPop()/focusLast()** - pop element off the focus stack.
- **saveFocus()** - save the focused element.
- **restoreFocus()** - restore the saved focused element.
#### Element (from Node)

View File

@ -675,6 +675,17 @@ Screen.prototype.focusPop = function() {
return this.history.pop();
};
Screen.prototype.saveFocus = function() {
return this._savedFocus = this.focused;
};
Screen.prototype.restoreFocus = function() {
if (!this._savedFocus) return;
this._savedFocus.focus();
delete this._savedFocus;
return this.focused;
};
Screen.prototype.__defineGetter__('focused', function() {
return this.history[this.history.length-1];
});