From 38f234aa91a772d3c4ed0ede7456dc6a08a4656f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 20 Aug 2013 13:34:18 -0500 Subject: [PATCH] add getScrollHeight. fixes #16. --- README.md | 9 +++++++-- lib/widget.js | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9af9f46..35ce92e 100644 --- a/README.md +++ b/README.md @@ -477,12 +477,17 @@ A box with scrollable content. - inherits all from Box. - **scroll** - received when the element is scrolled. -- **resetScroll** - reset scroll offset to zero. ##### Methods: -- **scroll(offset)** - scroll the content by an offset. +- **scroll(offset)** - scroll the content by a relative offset. - **scrollTo(index)** - scroll the content to an absolute index. +- **setScroll(index)** - same as `scrollTo`. +- **setScrollPerc(perc)** - set the current scroll index in percentage (0-100). +- **getScroll()** - get the current scroll index in lines. +- **getScrollHeight()** - get the actual height of the scrolling area. +- **getScrollPerc()** - get the current scroll index in percentage. +- **resetScroll()** - reset the scroll index to its initial state. #### ScrollableText (from ScrollableBox) diff --git a/lib/widget.js b/lib/widget.js index 6ace8e9..e391877 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -3856,12 +3856,16 @@ ScrollableBox.prototype.resetScroll = function() { return this.emit('scroll'); }; +ScrollableBox.prototype.getScrollHeight = function(s) { + return Math.max(this._clines.length, this._scrollBottom()); +}; + ScrollableBox.prototype.getScrollPerc = function(s) { var pos = this.lpos || this._getCoords(); if (!pos) return s ? -1 : 0; var height = (pos.yl - pos.yi) - this.iheight - , i = Math.max(this._clines.length, this._scrollBottom()) + , i = this.getScrollHeight() , p; if (height < i) {