hterm: io: add a hideOverlay helper
Sometimes we want to show the overlay for an event with an unknown end
time. Currently the only way to hide the overlay is to use the show
overlay function with a short timeout (1 msec) which makes the API a
bit hacky. Split the existing hiding logic out and into a dedicated
function for people to call.
Change-Id: Ib79bd40d47a974bce2313aede8966b8437848e59
Reviewed-on: https://chromium-review.googlesource.com/671646
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Brandon Gilmore <varz@google.com>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index b7967ad..843b2c1 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -2805,23 +2805,31 @@
this.overlayNode_.style.left = (divSize.width - overlaySize.width -
this.scrollPort_.currentScrollbarWidthPx) / 2 + 'px';
- var self = this;
-
if (this.overlayTimeout_)
clearTimeout(this.overlayTimeout_);
if (opt_timeout === null)
return;
- this.overlayTimeout_ = setTimeout(function() {
- self.overlayNode_.style.opacity = '0';
- self.overlayTimeout_ = setTimeout(function() {
- if (self.overlayNode_.parentNode)
- self.overlayNode_.parentNode.removeChild(self.overlayNode_);
- self.overlayTimeout_ = null;
- self.overlayNode_.style.opacity = '0.75';
- }, 200);
- }, opt_timeout || 1500);
+ this.overlayTimeout_ = setTimeout(() => {
+ this.overlayNode_.style.opacity = '0';
+ this.overlayTimeout_ = setTimeout(() => this.hideOverlay(), 200);
+ }, opt_timeout || 1500);
+};
+
+/**
+ * Hide the terminal overlay immediately.
+ *
+ * Useful when we show an overlay for an event with an unknown end time.
+ */
+hterm.Terminal.prototype.hideOverlay = function() {
+ if (this.overlayTimeout_)
+ clearTimeout(this.overlayTimeout_);
+ this.overlayTimeout_ = null;
+
+ if (this.overlayNode_.parentNode)
+ this.overlayNode_.parentNode.removeChild(this.overlayNode_);
+ this.overlayNode_.style.opacity = '0.75';
};
/**