mouse interactive scrollbar.

This commit is contained in:
Christopher Jeffrey 2015-04-29 12:43:58 -07:00
parent b7cf7d08f6
commit bcf9b630bb

View File

@ -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) {