Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 56 additions & 30 deletions dist/perfect-scrollbar.common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* perfect-scrollbar v1.4.0
* (c) 2018 Hyunje Jun
* (c) 2019 Hyunje Jun
* @license MIT
*/
'use strict';
Expand Down Expand Up @@ -58,6 +58,7 @@ function queryChildren(element, selector) {

var cls = {
main: 'ps',
rtl: 'ps__rtl',
element: {
thumb: function (x) { return ("ps__thumb-" + x); },
rail: function (x) { return ("ps__rail-" + x); },
Expand Down Expand Up @@ -310,6 +311,8 @@ var env = {
supportsTouch:
typeof window !== 'undefined' &&
('ontouchstart' in window ||
('maxTouchPoints' in window.navigator &&
window.navigator.maxTouchPoints > 0) ||
(window.DocumentTouch && document instanceof window.DocumentTouch)),
supportsIePointer:
typeof navigator !== 'undefined' && navigator.msMaxTouchPoints,
Expand All @@ -323,10 +326,11 @@ var updateGeometry = function(i) {
var roundedScrollTop = Math.floor(element.scrollTop);
var rect = element.getBoundingClientRect();

var fixedHeaderFooterHeight = i.settings.getTopOffset() + i.settings.getBottomOffset();
i.containerWidth = Math.ceil(rect.width);
i.containerHeight = Math.ceil(rect.height);
i.containerHeight = Math.ceil(rect.height) - fixedHeaderFooterHeight;
i.contentWidth = element.scrollWidth;
i.contentHeight = element.scrollHeight;
i.contentHeight = element.scrollHeight - fixedHeaderFooterHeight;

if (!element.contains(i.scrollbarXRail)) {
// clean up and append
Expand Down Expand Up @@ -396,7 +400,7 @@ var updateGeometry = function(i) {
element.classList.remove(cls.state.active('x'));
i.scrollbarXWidth = 0;
i.scrollbarXLeft = 0;
element.scrollLeft = 0;
element.scrollLeft = i.isRtl === true ? i.contentWidth : 0;
}
if (i.scrollbarYActive) {
element.classList.add(cls.state.active('y'));
Expand Down Expand Up @@ -438,14 +442,15 @@ function updateCss(element, i) {
}
set(i.scrollbarXRail, xRailOffset);

var yRailOffset = { top: roundedScrollTop, height: i.railYHeight };
var yRailOffset = { top: roundedScrollTop + i.settings.getTopOffset(), height: i.railYHeight };
if (i.isScrollbarYUsingRight) {
if (i.isRtl) {
yRailOffset.right =
i.contentWidth -
(i.negativeScrollAdjustment + element.scrollLeft) -
i.scrollbarYRight -
i.scrollbarYOuterWidth;
i.scrollbarYOuterWidth -
9;
} else {
yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
}
Expand Down Expand Up @@ -548,6 +553,9 @@ function bindMouseScrollHandler(
var scrollBy = null;

function mouseMoveHandler(e) {
if (e.touches && e.touches[0]) {
e[pageY] = e.touches[0].pageY;
}
element[scrollTop] =
startingScrollTop + scrollBy * (e[pageY] - startingMousePageY);
addScrollingClass(i, y);
Expand All @@ -563,20 +571,33 @@ function bindMouseScrollHandler(
i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
}

i.event.bind(i[scrollbarY], 'mousedown', function (e) {
function bindMoves(e, touchMode) {
startingScrollTop = element[scrollTop];
if (touchMode && e.touches) {
e[pageY] = e.touches[0].pageY;
}
startingMousePageY = e[pageY];
scrollBy =
(i[contentHeight] - i[containerHeight]) /
(i[railYHeight] - i[scrollbarYHeight]);

i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
if (!touchMode) {
i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
e.preventDefault();
} else {
i.event.bind(i.ownerDocument, 'touchmove', mouseMoveHandler);
}

i[scrollbarYRail].classList.add(cls.state.clicking);

e.stopPropagation();
e.preventDefault();
}

i.event.bind(i[scrollbarY], 'mousedown', function (e) {
bindMoves(e);
});
i.event.bind(i[scrollbarY], 'touchstart', function (e) {
bindMoves(e, true);
});
}

Expand Down Expand Up @@ -795,26 +816,26 @@ var wheel = function(i) {
}

var style = get(cursor);
var overflow = [style.overflow, style.overflowX, style.overflowY].join(
''
);

// if scrollable
if (overflow.match(/(scroll|auto)/)) {
// if deltaY && vertical scrollable
if (deltaY && style.overflowY.match(/(scroll|auto)/)) {
var maxScrollTop = cursor.scrollHeight - cursor.clientHeight;
if (maxScrollTop > 0) {
if (
!(cursor.scrollTop === 0 && deltaY > 0) &&
!(cursor.scrollTop === maxScrollTop && deltaY < 0)
(cursor.scrollTop > 0 && deltaY < 0) ||
(cursor.scrollTop < maxScrollTop && deltaY > 0)
) {
return true;
}
}
}
// if deltaX && horizontal scrollable
if (deltaX && style.overflowX.match(/(scroll|auto)/)) {
var maxScrollLeft = cursor.scrollWidth - cursor.clientWidth;
if (maxScrollLeft > 0) {
if (
!(cursor.scrollLeft === 0 && deltaX < 0) &&
!(cursor.scrollLeft === maxScrollLeft && deltaX > 0)
(cursor.scrollLeft > 0 && deltaX < 0) ||
(cursor.scrollLeft < maxScrollLeft && deltaX > 0)
) {
return true;
}
Expand Down Expand Up @@ -983,26 +1004,26 @@ var touch = function(i) {
}

var style = get(cursor);
var overflow = [style.overflow, style.overflowX, style.overflowY].join(
''
);

// if scrollable
if (overflow.match(/(scroll|auto)/)) {
// if deltaY && vertical scrollable
if (deltaY && style.overflowY.match(/(scroll|auto)/)) {
var maxScrollTop = cursor.scrollHeight - cursor.clientHeight;
if (maxScrollTop > 0) {
if (
!(cursor.scrollTop === 0 && deltaY > 0) &&
!(cursor.scrollTop === maxScrollTop && deltaY < 0)
(cursor.scrollTop > 0 && deltaY < 0) ||
(cursor.scrollTop < maxScrollTop && deltaY > 0)
) {
return true;
}
}
var maxScrollLeft = cursor.scrollLeft - cursor.clientWidth;
}
// if deltaX && horizontal scrollable
if (deltaX && style.overflowX.match(/(scroll|auto)/)) {
var maxScrollLeft = cursor.scrollWidth - cursor.clientWidth;
if (maxScrollLeft > 0) {
if (
!(cursor.scrollLeft === 0 && deltaX < 0) &&
!(cursor.scrollLeft === maxScrollLeft && deltaX > 0)
(cursor.scrollLeft > 0 && deltaX < 0) ||
(cursor.scrollLeft < maxScrollLeft && deltaX > 0)
) {
return true;
}
Expand Down Expand Up @@ -1102,6 +1123,8 @@ var defaultSettings = function () { return ({
useBothWheelAxes: false,
wheelPropagation: true,
wheelSpeed: 1,
getTopOffset: function () { return 0; },
getBottomOffset: function () { return 0; },
}); };

var handlers = {
Expand Down Expand Up @@ -1142,6 +1165,9 @@ var PerfectScrollbar = function PerfectScrollbar(element, userSettings) {
var blur = function () { return element.classList.remove(cls.state.focus); };

this.isRtl = get(element).direction === 'rtl';
if (this.isRtl === true) {
element.classList.add(cls.rtl);
}
this.isNegativeScroll = (function () {
var originalScrollLeft = element.scrollLeft;
var result = null;
Expand Down
Loading