Skip to content

Commit

Permalink
Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
asafdav committed Apr 2, 2014
1 parent a65d8df commit 53a2b3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-scrollbar",
"version": "0.0.3",
"version": "0.0.4",
"dependencies": {
},
"devDependencies": {
Expand Down
35 changes: 21 additions & 14 deletions dist/ng-scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ angular.module('ngScrollbar', []).directive('ngScrollbar', [
replace: true,
transclude: true,
link: function (scope, element, attrs) {
var win, mainElm, transculdedContainer, tools, thumb, thumbLine, track;
// Elements
var mainElm, transculdedContainer, tools, thumb, thumbLine, track;
var win = angular.element($window);
var dragger = { top: 0 }, page = { top: 0 };
// Styles
var scrollboxStyle, draggerStyle, draggerLineStyle, pageStyle;
var calcStyles = function () {
scrollboxStyle = {
Expand Down Expand Up @@ -70,39 +69,31 @@ angular.module('ngScrollbar', []).directive('ngScrollbar', [
var dragHandler = function (event) {
var newOffsetY = event.pageY - thumb[0].scrollTop - lastOffsetY;
var newOffsetX = 0;
// TBD
thumbDrag(event, newOffsetX, newOffsetY);
redraw();
};
var buildScrollbar = function () {
win = angular.element($window);
mainElm = angular.element(element.children()[0]);
transculdedContainer = angular.element(mainElm.children()[0]);
tools = angular.element(mainElm.children()[1]);
thumb = angular.element(angular.element(tools.children()[0]).children()[0]);
thumbLine = angular.element(thumb.children()[0]);
track = angular.element(angular.element(tools.children()[0]).children()[1]);
// Check if scroll bar is needed
page.height = element[0].offsetHeight;
page.scrollHeight = transculdedContainer[0].scrollHeight;
if (page.height < page.scrollHeight) {
scope.showYScrollbar = true;
// Calculate the dragger height
dragger.height = Math.round(page.height / page.scrollHeight * page.height);
dragger.trackHeight = page.height;
// update the transcluded content style and clear the parent's
calcStyles();
element.css({ overflow: 'hidden' });
mainElm.css(scrollboxStyle);
transculdedContainer.css(pageStyle);
thumb.css(draggerStyle);
thumbLine.css(draggerLineStyle);
// Bind scroll bar events
track.bind('click', trackClick);
// Handl mousewheel
var wheelEvent = win[0].onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll';
transculdedContainer[0].addEventListener(wheelEvent, wheelHandler, false);
// Drag the scroller
thumb.bind('mousedown', function (event) {
lastOffsetY = event.pageY - thumb[0].offsetTop;
win.bind('mouseup', function () {
Expand All @@ -116,13 +107,29 @@ angular.module('ngScrollbar', []).directive('ngScrollbar', [
scope.showYScrollbar = false;
}
};
var rebuildTimer;
var rebuild = function (e, data) {
if (rebuildTimer != null) {
clearTimeout(rebuildTimer);
}
var rollToBottom = !!data && !!data.rollToBottom;
rebuildTimer = setTimeout(function () {
page.height = null;
buildScrollbar(rollToBottom);
if (!scope.$$phase) {
scope.$digest();
}
}, 72);
};
buildScrollbar();
if (!!attrs.rebuildOn) {
scope.$on(attrs.rebuildOn, function () {
page.height = null;
buildScrollbar();
attrs.rebuildOn.split(' ').forEach(function (eventName) {
scope.$on(eventName, rebuild);
});
}
if (attrs.hasOwnProperty('rebuildOnResize')) {
win.on('resize', rebuild);
}
},
template: '<div>' + '<div class="ngsb-wrap">' + '<div class="ngsb-container" ng-transclude></div>' + '<div class="ngsb-scrollbar" style="position: absolute; display: block;" ng-show="showYScrollbar">' + '<div class="ngsb-thumb-container">' + '<div class="ngsb-thumb-pos" oncontextmenu="return false;">' + '<div class="ngsb-thumb" ></div>' + '</div>' + '<div class="ngsb-track"></div>' + '</div>' + '</div>' + '</div>' + '</div>'
};
Expand Down
4 changes: 2 additions & 2 deletions dist/ng-scrollbar.min.js

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

0 comments on commit 53a2b3e

Please sign in to comment.