Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit a77b710

Browse files
committed
use common modal methods for visibility
1 parent fd58bc1 commit a77b710

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

lib/dashboard.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ Dashboard.prototype._configureKeys = function () {
7272
this._showLayout(target);
7373
}.bind(this), THROTTLE_TIMEOUT));
7474

75-
var helpNode = this.helpView.node;
7675
this.container.key(["?", "h", "S-h"], function () {
77-
helpNode.toggle();
76+
this.gotoTimeView.hide();
77+
this.helpView.toggle();
7878
this.screen.render();
7979
}.bind(this));
8080

8181
this.container.key(["g", "S-g"], function () {
82-
helpNode.hide();
82+
this.helpView.hide();
8383
this.gotoTimeView.toggle();
8484
this.screen.render();
8585
}.bind(this));
8686

8787
this.container.key("escape", function () {
88-
if (helpNode.visible || this.gotoTimeView.isVisible()) {
89-
helpNode.hide();
88+
if (this.helpView.isVisible() || this.gotoTimeView.isVisible()) {
89+
this.helpView.hide();
9090
this.gotoTimeView.hide();
9191
this.screen.render();
9292
} else {

lib/views/help.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,45 @@ var HelpView = function HelpView(options) {
4343
hidden: true
4444
});
4545

46+
this.node.on("show", function () {
47+
options.parent.screen.saveFocus();
48+
this.node.setFront();
49+
}.bind(this));
50+
51+
this.node.on("hide", function () {
52+
options.parent.screen.restoreFocus();
53+
});
54+
4655
options.parent.append(this.node);
4756
};
4857

58+
/**
59+
* Toggle the visibility of the view.
60+
*
61+
* @returns {void}
62+
*/
63+
HelpView.prototype.toggle = function () {
64+
this.node.toggle();
65+
};
66+
67+
/**
68+
* Hide the view.
69+
*
70+
* @returns {void}
71+
*/
72+
HelpView.prototype.hide = function () {
73+
this.node.hide();
74+
};
75+
76+
/**
77+
* Check to see if the view is visible.
78+
*
79+
* @returns {Boolean}
80+
* Truthy if the view is visible, falsey otherwise.
81+
*/
82+
HelpView.prototype.isVisible = function () {
83+
return this.node.visible;
84+
};
85+
86+
4987
module.exports = HelpView;

0 commit comments

Comments
 (0)