add getScroll method.

This commit is contained in:
Christopher Jeffrey 2013-08-04 20:25:10 -05:00
parent 16bbb5ea24
commit 45f8f0e5bb
1 changed files with 31 additions and 1 deletions

View File

@ -3108,7 +3108,7 @@ Element.prototype.render = function() {
if (this.alwaysScroll) {
y = this.childBase / (i - (yl - yi));
} else {
y = (this.childBase + this.childOffset) / i;
y = (this.childBase + this.childOffset) / (i - 1);
}
y = yi + ((yl - yi) * y | 0);
if (y >= yl) y = yl - 1;
@ -3635,10 +3635,15 @@ ScrollableBox.prototype._scrollBottom = function() {
return bottom;
};
ScrollableBox.prototype.setScroll =
ScrollableBox.prototype.scrollTo = function(offset) {
return this.scroll(offset - (this.childBase + this.childOffset));
};
ScrollableBox.prototype.getScroll = function() {
return this.childBase + this.childOffset;
};
ScrollableBox.prototype.scroll = function(offset, always) {
if (!this.scrollable) return;
@ -3755,6 +3760,31 @@ ScrollableBox.prototype.resetScroll = function() {
return this.emit('scroll');
};
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())
, p;
if (height < i) {
if (this.alwaysScroll) {
p = this.childBase / (i - height);
} else {
p = (this.childBase + this.childOffset) / (i - 1);
}
return p * 100;
}
return s ? -1 : 0;
};
ScrollableBox.prototype.setScrollPerc = function(i) {
var m = Math.max(this._clines.length, this._scrollBottom());
return this.scrollTo((i / 100) * m | 0);
};
/**
* ScrollableText
*/