Skip to content

Commit

Permalink
0.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Mar 24, 2022
1 parent 4e24bb4 commit 13f617c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "perfect-scrollbar",
"version": "0.6.7",
"version": "0.6.8",
"description": "Minimalistic but perfect custom scrollbar plugin",
"author": "Hyunje Alex Jun <me@noraesae.net>",
"contributors": [
Expand Down Expand Up @@ -43,7 +43,8 @@
},
"scripts": {
"test": "gulp",
"before-deploy": "gulp && gulp compress"
"before-deploy": "gulp && gulp compress",
"release": "rm -rf dist && gulp && npm publish"
},
"license": "MIT"
}
4 changes: 2 additions & 2 deletions src/js/plugin/handler/click-rail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function bindClickRailHandler(element, i) {
}
i.event.bind(i.scrollbarYRail, 'click', function (e) {
var halfOfScrollbarLength = h.toInt(i.scrollbarYHeight / 2);
var positionTop = i.railYRatio * (e.pageY - window.scrollY - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
var positionTop = i.railYRatio * (e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
var maxPositionTop = i.railYRatio * (i.railYHeight - i.scrollbarYHeight);
var positionRatio = positionTop / maxPositionTop;

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

Expand Down
4 changes: 2 additions & 2 deletions src/js/plugin/handler/drag-scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function bindMouseScrollXHandler(element, i) {

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

if (newLeft < 0) {
i.scrollbarXLeft = 0;
Expand Down Expand Up @@ -60,7 +60,7 @@ function bindMouseScrollYHandler(element, i) {

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

if (newTop < 0) {
i.scrollbarYTop = 0;
Expand Down
10 changes: 1 addition & 9 deletions src/js/plugin/handler/mouse-wheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
'use strict';

var h = require('../../lib/helper')
, instances = require('../instances')
var instances = require('../instances')
, updateGeometry = require('../update-geometry')
, updateScroll = require('../update-scroll');

Expand Down Expand Up @@ -81,13 +80,6 @@ function bindMouseWheelHandler(element, i) {
}

function mousewheelHandler(e) {
// FIXME: this is a quick fix for the select problem in FF and IE.
// If there comes an effective way to deal with the problem,
// this lines should be removed.
if (!h.env.isWebKit && element.querySelector('select:focus')) {
return;
}

var delta = getDeltaFromEvent(e);

var deltaX = delta[0];
Expand Down
2 changes: 2 additions & 0 deletions src/js/plugin/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function Instance(element) {

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

i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
i.scrollbarY.setAttribute('tabindex', 0);
i.scrollbarYActive = null;
i.scrollbarYHeight = null;
i.scrollbarYTop = null;
Expand Down
24 changes: 16 additions & 8 deletions src/js/plugin/update-geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ module.exports = function (element) {
i.scrollbarXLeft = h.toInt((i.negativeScrollAdjustment + element.scrollLeft) * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
} else {
i.scrollbarXActive = false;
i.scrollbarXWidth = 0;
i.scrollbarXLeft = 0;
element.scrollLeft = 0;
}

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

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

updateCss(element, i);

cls[i.scrollbarXActive ? 'add' : 'remove'](element, 'ps-active-x');
cls[i.scrollbarYActive ? 'add' : 'remove'](element, 'ps-active-y');
if (i.scrollbarXActive) {
cls.add(element, 'ps-active-x');
} else {
cls.remove(element, 'ps-active-x');
i.scrollbarXWidth = 0;
i.scrollbarXLeft = 0;
updateScroll(element, 'left', 0);
}
if (i.scrollbarYActive) {
cls.add(element, 'ps-active-y');
} else {
cls.remove(element, 'ps-active-y');
i.scrollbarYHeight = 0;
i.scrollbarYTop = 0;
updateScroll(element, 'top', 0);
}
};
4 changes: 2 additions & 2 deletions src/js/plugin/update-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ module.exports = function (element, axis, value) {

var i = instances.get(element);

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

if (axis === 'left' && value > i.contentWidth - i.containerWidth) {
if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
element.scrollLeft = i.contentWidth - i.containerWidth;
element.dispatchEvent(xEndEvent);
return; // don't allow scroll past container
Expand Down
7 changes: 6 additions & 1 deletion src/js/plugin/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
var d = require('../lib/dom')
, h = require('../lib/helper')
, instances = require('./instances')
, updateGeometry = require('./update-geometry');
, updateGeometry = require('./update-geometry')
, updateScroll = require('./update-scroll');

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

updateGeometry(element);

// Update top/left scroll to trigger events
updateScroll(element, 'top', element.scrollTop);
updateScroll(element, 'left', element.scrollLeft);

d.css(i.scrollbarXRail, 'display', '');
d.css(i.scrollbarYRail, 'display', '');
};

0 comments on commit 13f617c

Please sign in to comment.