Skip to content

Commit 13f617c

Browse files
author
unknown
committed
0.6.8
1 parent 4e24bb4 commit 13f617c

File tree

8 files changed

+34
-26
lines changed

8 files changed

+34
-26
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "perfect-scrollbar",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "Minimalistic but perfect custom scrollbar plugin",
55
"author": "Hyunje Alex Jun <[email protected]>",
66
"contributors": [
@@ -43,7 +43,8 @@
4343
},
4444
"scripts": {
4545
"test": "gulp",
46-
"before-deploy": "gulp && gulp compress"
46+
"before-deploy": "gulp && gulp compress",
47+
"release": "rm -rf dist && gulp && npm publish"
4748
},
4849
"license": "MIT"
4950
}

src/js/plugin/handler/click-rail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function bindClickRailHandler(element, i) {
1919
}
2020
i.event.bind(i.scrollbarYRail, 'click', function (e) {
2121
var halfOfScrollbarLength = h.toInt(i.scrollbarYHeight / 2);
22-
var positionTop = i.railYRatio * (e.pageY - window.scrollY - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
22+
var positionTop = i.railYRatio * (e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
2323
var maxPositionTop = i.railYRatio * (i.railYHeight - i.scrollbarYHeight);
2424
var positionRatio = positionTop / maxPositionTop;
2525

@@ -40,7 +40,7 @@ function bindClickRailHandler(element, i) {
4040
}
4141
i.event.bind(i.scrollbarXRail, 'click', function (e) {
4242
var halfOfScrollbarLength = h.toInt(i.scrollbarXWidth / 2);
43-
var positionLeft = i.railXRatio * (e.pageX - window.scrollX - pageOffset(i.scrollbarXRail).left - halfOfScrollbarLength);
43+
var positionLeft = i.railXRatio * (e.pageX - window.pageXOffset - pageOffset(i.scrollbarXRail).left - halfOfScrollbarLength);
4444
var maxPositionLeft = i.railXRatio * (i.railXWidth - i.scrollbarXWidth);
4545
var positionRatio = positionLeft / maxPositionLeft;
4646

src/js/plugin/handler/drag-scrollbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function bindMouseScrollXHandler(element, i) {
1515

1616
function updateScrollLeft(deltaX) {
1717
var newLeft = currentLeft + (deltaX * i.railXRatio);
18-
var maxLeft = i.scrollbarXRail.getBoundingClientRect().left + (i.railXRatio * (i.railXWidth - i.scrollbarXWidth));
18+
var maxLeft = Math.max(0, i.scrollbarXRail.getBoundingClientRect().left) + (i.railXRatio * (i.railXWidth - i.scrollbarXWidth));
1919

2020
if (newLeft < 0) {
2121
i.scrollbarXLeft = 0;
@@ -60,7 +60,7 @@ function bindMouseScrollYHandler(element, i) {
6060

6161
function updateScrollTop(deltaY) {
6262
var newTop = currentTop + (deltaY * i.railYRatio);
63-
var maxTop = i.scrollbarYRail.getBoundingClientRect().top + (i.railYRatio * (i.railYHeight - i.scrollbarYHeight));
63+
var maxTop = Math.max(0, i.scrollbarYRail.getBoundingClientRect().top) + (i.railYRatio * (i.railYHeight - i.scrollbarYHeight));
6464

6565
if (newTop < 0) {
6666
i.scrollbarYTop = 0;

src/js/plugin/handler/mouse-wheel.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*/
44
'use strict';
55

6-
var h = require('../../lib/helper')
7-
, instances = require('../instances')
6+
var instances = require('../instances')
87
, updateGeometry = require('../update-geometry')
98
, updateScroll = require('../update-scroll');
109

@@ -81,13 +80,6 @@ function bindMouseWheelHandler(element, i) {
8180
}
8281

8382
function mousewheelHandler(e) {
84-
// FIXME: this is a quick fix for the select problem in FF and IE.
85-
// If there comes an effective way to deal with the problem,
86-
// this lines should be removed.
87-
if (!h.env.isWebKit && element.querySelector('select:focus')) {
88-
return;
89-
}
90-
9183
var delta = getDeltaFromEvent(e);
9284

9385
var deltaX = delta[0];

src/js/plugin/instances.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function Instance(element) {
3535

3636
i.scrollbarXRail = d.appendTo(d.e('div', 'ps-scrollbar-x-rail'), element);
3737
i.scrollbarX = d.appendTo(d.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
38+
i.scrollbarX.setAttribute('tabindex', 0);
3839
i.scrollbarXActive = null;
3940
i.scrollbarXWidth = null;
4041
i.scrollbarXLeft = null;
@@ -51,6 +52,7 @@ function Instance(element) {
5152

5253
i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
5354
i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
55+
i.scrollbarY.setAttribute('tabindex', 0);
5456
i.scrollbarYActive = null;
5557
i.scrollbarYHeight = null;
5658
i.scrollbarYTop = null;

src/js/plugin/update-geometry.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ module.exports = function (element) {
8989
i.scrollbarXLeft = h.toInt((i.negativeScrollAdjustment + element.scrollLeft) * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
9090
} else {
9191
i.scrollbarXActive = false;
92-
i.scrollbarXWidth = 0;
93-
i.scrollbarXLeft = 0;
94-
element.scrollLeft = 0;
9592
}
9693

9794
if (!i.settings.suppressScrollY && i.containerHeight + i.settings.scrollYMarginOffset < i.contentHeight) {
@@ -102,9 +99,6 @@ module.exports = function (element) {
10299
i.scrollbarYTop = h.toInt(element.scrollTop * (i.railYHeight - i.scrollbarYHeight) / (i.contentHeight - i.containerHeight));
103100
} else {
104101
i.scrollbarYActive = false;
105-
i.scrollbarYHeight = 0;
106-
i.scrollbarYTop = 0;
107-
updateScroll(element, 'top', 0);
108102
}
109103

110104
if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
@@ -116,6 +110,20 @@ module.exports = function (element) {
116110

117111
updateCss(element, i);
118112

119-
cls[i.scrollbarXActive ? 'add' : 'remove'](element, 'ps-active-x');
120-
cls[i.scrollbarYActive ? 'add' : 'remove'](element, 'ps-active-y');
113+
if (i.scrollbarXActive) {
114+
cls.add(element, 'ps-active-x');
115+
} else {
116+
cls.remove(element, 'ps-active-x');
117+
i.scrollbarXWidth = 0;
118+
i.scrollbarXLeft = 0;
119+
updateScroll(element, 'left', 0);
120+
}
121+
if (i.scrollbarYActive) {
122+
cls.add(element, 'ps-active-y');
123+
} else {
124+
cls.remove(element, 'ps-active-y');
125+
i.scrollbarYHeight = 0;
126+
i.scrollbarYTop = 0;
127+
updateScroll(element, 'top', 0);
128+
}
121129
};

src/js/plugin/update-scroll.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ module.exports = function (element, axis, value) {
5656

5757
var i = instances.get(element);
5858

59-
if (axis === 'top' && value > i.contentHeight - i.containerHeight) {
59+
if (axis === 'top' && value >= i.contentHeight - i.containerHeight) {
6060
element.scrollTop = i.contentHeight - i.containerHeight;
6161
element.dispatchEvent(yEndEvent);
6262
return; // don't allow scroll past container
6363
}
6464

65-
if (axis === 'left' && value > i.contentWidth - i.containerWidth) {
65+
if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
6666
element.scrollLeft = i.contentWidth - i.containerWidth;
6767
element.dispatchEvent(xEndEvent);
6868
return; // don't allow scroll past container

src/js/plugin/update.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
var d = require('../lib/dom')
77
, h = require('../lib/helper')
88
, instances = require('./instances')
9-
, updateGeometry = require('./update-geometry');
9+
, updateGeometry = require('./update-geometry')
10+
, updateScroll = require('./update-scroll');
1011

1112
module.exports = function (element) {
1213
var i = instances.get(element);
@@ -30,6 +31,10 @@ module.exports = function (element) {
3031

3132
updateGeometry(element);
3233

34+
// Update top/left scroll to trigger events
35+
updateScroll(element, 'top', element.scrollTop);
36+
updateScroll(element, 'left', element.scrollLeft);
37+
3338
d.css(i.scrollbarXRail, 'display', '');
3439
d.css(i.scrollbarYRail, 'display', '');
3540
};

0 commit comments

Comments
 (0)