Skip to content

Commit

Permalink
0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Kazakov committed Sep 29, 2014
1 parent a51dec2 commit 1a1c5eb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngTinyScrollbar",
"version": "0.6.1",
"version": "0.6.2",
"homepage": "https://github.com/yads/ngTinyScrollbar",
"authors": [
"Vadim Kazakov <[email protected]>"
Expand Down
76 changes: 43 additions & 33 deletions dist/ng-tiny-scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,45 +90,53 @@ angular.module('ngTinyScrollbar', ['ngAnimate'])
};

this.update = function(scrollTo) {
this.viewportSize = $viewport[0]['offset'+ sizeLabelCap];
this.contentSize = $overview[0]['scroll'+ sizeLabelCap];
this.contentRatio = this.viewportSize / this.contentSize;
this.trackSize = this.options.trackSize || this.viewportSize;
this.thumbSize = Math.min(this.trackSize, Math.max(0, (this.options.thumbSize || (this.trackSize * this.contentRatio))));
this.trackRatio = this.options.thumbSize ? (this.contentSize - this.viewportSize) / (this.trackSize - this.thumbSize) : (this.contentSize / this.trackSize);
mousePosition = $scrollbar[0].offsetTop;

$scrollbar.toggleClass('disable', this.contentRatio >= 1);

switch (scrollTo) {
case 'bottom':
this.contentPosition = this.contentSize - this.viewportSize;
break;
case 'relative':
this.contentPosition = Math.min(this.contentSize - this.viewportSize, Math.max(0, this.contentPosition));
break;
default:
this.contentPosition = parseInt(scrollTo, 10) || 0;
}

if (this.contentRatio > 1) {
$overview.css(posiLabel, -self.contentPosition + 'px');
return this;
}

if (!this.options.alwaysVisible && this.viewportSize > 0) {
this.viewportSize = $viewport.prop('offset'+ sizeLabelCap);
this.contentSize = $overview.prop('scroll'+ sizeLabelCap);
this.contentRatio = this.viewportSize / this.contentSize;
this.trackSize = this.options.trackSize || this.viewportSize;
this.thumbSize = Math.min(this.trackSize, Math.max(0, (this.options.thumbSize || (this.trackSize * this.contentRatio))));
this.trackRatio = this.options.thumbSize ? (this.contentSize - this.viewportSize) / (this.trackSize - this.thumbSize) : (this.contentSize / this.trackSize);
mousePosition = $scrollbar.prop('offsetTop');

$scrollbar.toggleClass('disable', this.contentRatio >= 1);

if (!this.options.alwaysVisible && this.contentRatio < 1 && this.viewportSize > 0) {
//flash the scrollbar when update happens
$animate.addClass($scrollbar[0], 'visible').then(function() {
$animate.removeClass($scrollbar[0], 'visible');
$scope.$digest();
});
}
$thumb.css(posiLabel, self.contentPosition / self.trackRatio + 'px');
$scrollbar.css(sizeLabel, self.trackSize + 'px');
$thumb.css(sizeLabel, self.thumbSize + 'px');
$overview.css(posiLabel, -self.contentPosition + 'px');
}

switch (scrollTo) {
case 'bottom':
this.contentPosition = this.contentSize - this.viewportSize;
break;
case 'relative':
this.contentPosition = Math.min(this.contentSize - this.viewportSize, Math.max(0, this.contentPosition));
break;
default:
this.contentPosition = parseInt(scrollTo, 10) || 0;
}

ensureContentPosition();
$thumb.css(posiLabel, self.contentPosition / self.trackRatio + 'px');
$scrollbar.css(sizeLabel, self.trackSize + 'px');
$thumb.css(sizeLabel, self.thumbSize + 'px');
$overview.css(posiLabel, -self.contentPosition + 'px');

return this;
};

return this;
function ensureContentPosition() {
// if scrollbar is on, ensure the bottom of the content does not go above the bottom of the viewport
if (self.contentRatio <= 1 && self.contentPosition > self.contentSize - self.viewportSize) {
self.contentPosition = self.contentSize - self.viewportSize;
}
// if scrollbar is off, ensure the top of the content does not go below the top of the viewport
else if (self.contentRatio > 1 && self.contentPosition > 0) {
self.contentPosition = 0;
}
}

function setEvents() {
Expand Down Expand Up @@ -224,6 +232,7 @@ angular.module('ngTinyScrollbar', ['ngAnimate'])

$element[0].dispatchEvent(moveEvent);

ensureContentPosition();
$thumb.css(posiLabel, self.contentPosition / self.trackRatio + 'px');
$overview.css(posiLabel, -self.contentPosition + 'px');

Expand Down Expand Up @@ -256,6 +265,7 @@ angular.module('ngTinyScrollbar', ['ngAnimate'])

$element[0].dispatchEvent(moveEvent);

ensureContentPosition();
$thumb.css(posiLabel, thumbPositionNew + 'px');
$overview.css(posiLabel, -self.contentPosition + 'px');
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-tiny-scrollbar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngTinyScrollbar",
"version": "0.6.1",
"version": "0.6.2",
"description": "An angular directive port of the TinyScrollbar",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1a1c5eb

Please sign in to comment.