From bcf9b630bb5381333c4e51139bec9b9d3449f71b Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 29 Apr 2015 12:43:58 -0700 Subject: [PATCH] mouse interactive scrollbar. --- lib/widget.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/widget.js b/lib/widget.js index 0465e5e..4fbc9ed 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -4771,6 +4771,38 @@ function ScrollableBox(options) { } this.track.style = this.style.track; } + // Allow controlling of the scrollbar via the mouse: + this.on('mousedown', function(data) { + if (self._scrollingBar) { + // Do not allow dragging on the scrollbar: + delete self._drag; + return; + } + var x = data.x - self.aleft; + var y = data.y - self.atop; + if (x === self.width - self.iright - 1) { + // Do not allow dragging on the scrollbar: + delete self._drag; + var perc = (y - self.itop) / (self.height - self.iheight); + self.setScrollPerc(perc * 100 | 0); + self.screen.render(); + var smd, smu; + self._scrollingBar = true; + self.screen.on('mousedown', smd = function(data) { + var y = data.y - self.atop; + var perc = y / self.height; + self.setScrollPerc(perc * 100 | 0); + self.screen.render(); + }); + // If mouseup occurs out of the window, no mouseup event fires, and + // scrollbar will drag again on mousedown until another mouseup occurs. + self.screen.on('mouseup', smu = function(data) { + self._scrollingBar = false; + self.screen.removeListener('mousedown', smd); + self.screen.removeListener('mouseup', smu); + }); + } + }); } if (options.mouse) {