2012-11-06 21:00:37 +08:00
|
|
|
/* Copyright (c) 2012 HyeonJe Jun (http://github.com/noraesae)
|
|
|
|
* Licensed under the MIT License
|
|
|
|
*/
|
2013-08-31 01:24:43 +08:00
|
|
|
'use strict';
|
2013-09-20 17:04:29 +08:00
|
|
|
(function (factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define(['jquery'], factory);
|
|
|
|
} else {
|
|
|
|
// Browser globals
|
|
|
|
factory(jQuery);
|
|
|
|
}
|
|
|
|
}(function ($) {
|
2013-05-18 11:41:15 +08:00
|
|
|
|
|
|
|
// The default settings for the plugin
|
|
|
|
var defaultSettings = {
|
|
|
|
wheelSpeed: 10,
|
2013-07-18 00:53:02 +08:00
|
|
|
wheelPropagation: false,
|
|
|
|
minScrollbarLength: null
|
2013-05-18 11:41:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.perfectScrollbar = function (suppliedSettings, option) {
|
|
|
|
|
2013-06-14 20:38:33 +08:00
|
|
|
return this.each(function () {
|
2013-05-22 17:48:51 +08:00
|
|
|
// Use the default settings
|
2013-08-05 22:59:17 +08:00
|
|
|
var settings = $.extend(true, {}, defaultSettings),
|
|
|
|
$this = $(this);
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (typeof suppliedSettings === "object") {
|
|
|
|
// But over-ride any supplied
|
|
|
|
$.extend(true, settings, suppliedSettings);
|
|
|
|
} else {
|
|
|
|
// If no settings were supplied, then the first param must be the option
|
|
|
|
option = suppliedSettings;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 22:59:17 +08:00
|
|
|
// Catch options
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (option === 'update') {
|
2013-08-05 22:59:17 +08:00
|
|
|
if ($this.data('perfect-scrollbar-update')) {
|
|
|
|
$this.data('perfect-scrollbar-update')();
|
2013-05-22 17:48:51 +08:00
|
|
|
}
|
2013-08-05 22:59:17 +08:00
|
|
|
return $this;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
else if (option === 'destroy') {
|
2013-08-05 22:59:17 +08:00
|
|
|
if ($this.data('perfect-scrollbar-destroy')) {
|
|
|
|
$this.data('perfect-scrollbar-destroy')();
|
2013-05-22 17:48:51 +08:00
|
|
|
}
|
2013-08-05 22:59:17 +08:00
|
|
|
return $this;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 22:59:17 +08:00
|
|
|
if ($this.data('perfect-scrollbar')) {
|
2013-05-22 17:48:51 +08:00
|
|
|
// if there's already perfect-scrollbar
|
2013-08-05 22:59:17 +08:00
|
|
|
return $this.data('perfect-scrollbar');
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 22:59:17 +08:00
|
|
|
|
|
|
|
// Or generate new perfectScrollbar
|
|
|
|
|
|
|
|
// Set class to the container
|
|
|
|
$this.addClass('ps-container');
|
|
|
|
|
|
|
|
var $scrollbarX = $("<div class='ps-scrollbar-x'></div>").appendTo($this),
|
2013-05-22 17:48:51 +08:00
|
|
|
$scrollbarY = $("<div class='ps-scrollbar-y'></div>").appendTo($this),
|
|
|
|
containerWidth,
|
|
|
|
containerHeight,
|
|
|
|
contentWidth,
|
|
|
|
contentHeight,
|
|
|
|
scrollbarXWidth,
|
|
|
|
scrollbarXLeft,
|
|
|
|
scrollbarXBottom = parseInt($scrollbarX.css('bottom'), 10),
|
|
|
|
scrollbarYHeight,
|
|
|
|
scrollbarYTop,
|
|
|
|
scrollbarYRight = parseInt($scrollbarY.css('right'), 10);
|
|
|
|
|
|
|
|
var updateContentScrollTop = function () {
|
2013-07-31 23:59:23 +08:00
|
|
|
var scrollTop = parseInt(scrollbarYTop * (contentHeight - containerHeight) / (containerHeight - scrollbarYHeight), 10);
|
2013-05-22 17:48:51 +08:00
|
|
|
$this.scrollTop(scrollTop);
|
|
|
|
$scrollbarX.css({bottom: scrollbarXBottom - scrollTop});
|
|
|
|
};
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
var updateContentScrollLeft = function () {
|
2013-07-31 23:59:23 +08:00
|
|
|
var scrollLeft = parseInt(scrollbarXLeft * (contentWidth - containerWidth) / (containerWidth - scrollbarXWidth), 10);
|
2013-05-22 17:48:51 +08:00
|
|
|
$this.scrollLeft(scrollLeft);
|
|
|
|
$scrollbarY.css({right: scrollbarYRight - scrollLeft});
|
|
|
|
};
|
|
|
|
|
2013-07-18 00:53:02 +08:00
|
|
|
var getSettingsAdjustedThumbSize = function (thumbSize) {
|
|
|
|
if (settings.minScrollbarLength) {
|
|
|
|
thumbSize = Math.max(thumbSize, settings.minScrollbarLength);
|
|
|
|
}
|
|
|
|
return thumbSize;
|
|
|
|
};
|
|
|
|
|
2013-06-16 16:45:37 +08:00
|
|
|
var updateScrollbarCss = function () {
|
|
|
|
$scrollbarX.css({left: scrollbarXLeft + $this.scrollLeft(), bottom: scrollbarXBottom - $this.scrollTop(), width: scrollbarXWidth});
|
|
|
|
$scrollbarY.css({top: scrollbarYTop + $this.scrollTop(), right: scrollbarYRight - $this.scrollLeft(), height: scrollbarYHeight});
|
|
|
|
};
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
var updateBarSizeAndPosition = function () {
|
|
|
|
containerWidth = $this.width();
|
|
|
|
containerHeight = $this.height();
|
2013-06-14 00:08:22 +08:00
|
|
|
contentWidth = $this.prop('scrollWidth');
|
|
|
|
contentHeight = $this.prop('scrollHeight');
|
2013-08-05 22:59:17 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (containerWidth < contentWidth) {
|
2013-07-18 00:53:02 +08:00
|
|
|
scrollbarXWidth = getSettingsAdjustedThumbSize(parseInt(containerWidth * containerWidth / contentWidth, 10));
|
2013-07-31 23:59:23 +08:00
|
|
|
scrollbarXLeft = parseInt($this.scrollLeft() * (containerWidth - scrollbarXWidth) / (contentWidth - containerWidth), 10);
|
2013-05-22 17:48:51 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
scrollbarXWidth = 0;
|
|
|
|
scrollbarXLeft = 0;
|
|
|
|
$this.scrollLeft(0);
|
|
|
|
}
|
2013-08-05 22:59:17 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (containerHeight < contentHeight) {
|
2013-07-18 00:53:02 +08:00
|
|
|
scrollbarYHeight = getSettingsAdjustedThumbSize(parseInt(containerHeight * containerHeight / contentHeight, 10));
|
2013-07-31 23:59:23 +08:00
|
|
|
scrollbarYTop = parseInt($this.scrollTop() * (containerHeight - scrollbarYHeight) / (contentHeight - containerHeight), 10);
|
2013-05-22 17:48:51 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
scrollbarYHeight = 0;
|
|
|
|
scrollbarYTop = 0;
|
|
|
|
$this.scrollTop(0);
|
2013-02-26 09:32:19 +08:00
|
|
|
}
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (scrollbarYTop >= containerHeight - scrollbarYHeight) {
|
|
|
|
scrollbarYTop = containerHeight - scrollbarYHeight;
|
2012-11-10 02:07:47 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
if (scrollbarXLeft >= containerWidth - scrollbarXWidth) {
|
|
|
|
scrollbarXLeft = containerWidth - scrollbarXWidth;
|
2012-11-10 02:07:47 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 16:45:37 +08:00
|
|
|
updateScrollbarCss();
|
2013-05-22 17:48:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var moveBarX = function (currentLeft, deltaX) {
|
|
|
|
var newLeft = currentLeft + deltaX,
|
|
|
|
maxLeft = containerWidth - scrollbarXWidth;
|
|
|
|
|
|
|
|
if (newLeft < 0) {
|
|
|
|
scrollbarXLeft = 0;
|
2012-11-10 02:07:47 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
else if (newLeft > maxLeft) {
|
|
|
|
scrollbarXLeft = maxLeft;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
else {
|
|
|
|
scrollbarXLeft = newLeft;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
$scrollbarX.css({left: scrollbarXLeft + $this.scrollLeft()});
|
|
|
|
};
|
|
|
|
|
|
|
|
var moveBarY = function (currentTop, deltaY) {
|
|
|
|
var newTop = currentTop + deltaY,
|
|
|
|
maxTop = containerHeight - scrollbarYHeight;
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
if (newTop < 0) {
|
|
|
|
scrollbarYTop = 0;
|
|
|
|
}
|
|
|
|
else if (newTop > maxTop) {
|
|
|
|
scrollbarYTop = maxTop;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
else {
|
|
|
|
scrollbarYTop = newTop;
|
2013-05-18 11:41:15 +08:00
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
$scrollbarY.css({top: scrollbarYTop + $this.scrollTop()});
|
2013-05-18 11:41:15 +08:00
|
|
|
};
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
var bindMouseScrollXHandler = function () {
|
|
|
|
var currentLeft,
|
|
|
|
currentPageX;
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
$scrollbarX.bind('mousedown.perfect-scroll', function (e) {
|
|
|
|
currentPageX = e.pageX;
|
|
|
|
currentLeft = $scrollbarX.position().left;
|
|
|
|
$scrollbarX.addClass('in-scrolling');
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('mousemove.perfect-scroll', function (e) {
|
|
|
|
if ($scrollbarX.hasClass('in-scrolling')) {
|
|
|
|
updateContentScrollLeft();
|
2013-06-12 23:57:43 +08:00
|
|
|
moveBarX(currentLeft, e.pageX - currentPageX);
|
2013-05-22 17:48:51 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('mouseup.perfect-scroll', function (e) {
|
|
|
|
if ($scrollbarX.hasClass('in-scrolling')) {
|
|
|
|
$scrollbarX.removeClass('in-scrolling');
|
|
|
|
}
|
|
|
|
});
|
2013-08-05 22:59:17 +08:00
|
|
|
|
|
|
|
currentLeft =
|
|
|
|
currentPageX = null;
|
2013-05-22 17:48:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var bindMouseScrollYHandler = function () {
|
|
|
|
var currentTop,
|
|
|
|
currentPageY;
|
2012-11-10 02:07:47 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
$scrollbarY.bind('mousedown.perfect-scroll', function (e) {
|
|
|
|
currentPageY = e.pageY;
|
|
|
|
currentTop = $scrollbarY.position().top;
|
|
|
|
$scrollbarY.addClass('in-scrolling');
|
|
|
|
e.stopPropagation();
|
2013-05-18 11:41:15 +08:00
|
|
|
e.preventDefault();
|
2013-05-22 17:48:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('mousemove.perfect-scroll', function (e) {
|
|
|
|
if ($scrollbarY.hasClass('in-scrolling')) {
|
|
|
|
updateContentScrollTop();
|
2013-06-12 23:57:43 +08:00
|
|
|
moveBarY(currentTop, e.pageY - currentPageY);
|
2013-05-22 17:48:51 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
$(document).bind('mouseup.perfect-scroll', function (e) {
|
|
|
|
if ($scrollbarY.hasClass('in-scrolling')) {
|
|
|
|
$scrollbarY.removeClass('in-scrolling');
|
|
|
|
}
|
|
|
|
});
|
2013-08-05 22:59:17 +08:00
|
|
|
|
|
|
|
currentTop =
|
|
|
|
currentPageY = null;
|
2013-05-22 17:48:51 +08:00
|
|
|
};
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
// bind handlers
|
|
|
|
var bindMouseWheelHandler = function () {
|
|
|
|
var shouldPreventDefault = function (deltaX, deltaY) {
|
|
|
|
var scrollTop = $this.scrollTop();
|
|
|
|
if (scrollTop === 0 && deltaY > 0 && deltaX === 0) {
|
|
|
|
return !settings.wheelPropagation;
|
|
|
|
}
|
|
|
|
else if (scrollTop >= contentHeight - containerHeight && deltaY < 0 && deltaX === 0) {
|
|
|
|
return !settings.wheelPropagation;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scrollLeft = $this.scrollLeft();
|
|
|
|
if (scrollLeft === 0 && deltaX < 0 && deltaY === 0) {
|
|
|
|
return !settings.wheelPropagation;
|
|
|
|
}
|
|
|
|
else if (scrollLeft >= contentWidth - containerWidth && deltaX > 0 && deltaY === 0) {
|
|
|
|
return !settings.wheelPropagation;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2013-08-06 14:14:55 +08:00
|
|
|
var shouldPrevent = false;
|
2013-06-01 22:09:18 +08:00
|
|
|
$this.bind('mousewheel.perfect-scroll', function (e, delta, deltaX, deltaY) {
|
2013-05-22 17:48:51 +08:00
|
|
|
$this.scrollTop($this.scrollTop() - (deltaY * settings.wheelSpeed));
|
|
|
|
$this.scrollLeft($this.scrollLeft() + (deltaX * settings.wheelSpeed));
|
|
|
|
|
|
|
|
// update bar position
|
|
|
|
updateBarSizeAndPosition();
|
|
|
|
|
2013-08-06 14:14:55 +08:00
|
|
|
shouldPrevent = shouldPreventDefault(deltaX, deltaY);
|
|
|
|
if (shouldPrevent) {
|
2013-05-22 17:48:51 +08:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2013-08-01 01:01:42 +08:00
|
|
|
|
|
|
|
// fix Firefox scroll problem
|
2013-08-06 14:14:55 +08:00
|
|
|
$this.bind('MozMousePixelScroll.perfect-scroll', function (e) {
|
|
|
|
if (shouldPrevent) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2013-05-18 11:41:15 +08:00
|
|
|
};
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
// bind mobile touch handler
|
|
|
|
var bindMobileTouchHandler = function () {
|
|
|
|
var applyTouchMove = function (differenceX, differenceY) {
|
|
|
|
$this.scrollTop($this.scrollTop() - differenceY);
|
|
|
|
$this.scrollLeft($this.scrollLeft() - differenceX);
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
// update bar position
|
|
|
|
updateBarSizeAndPosition();
|
|
|
|
};
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
var startCoords = {},
|
|
|
|
startTime = 0,
|
|
|
|
speed = {},
|
2013-06-14 20:57:24 +08:00
|
|
|
breakingProcess = null,
|
|
|
|
inGlobalTouch = false;
|
|
|
|
|
|
|
|
$(window).bind("touchstart.perfect-scroll", function (e) {
|
|
|
|
inGlobalTouch = true;
|
|
|
|
});
|
|
|
|
$(window).bind("touchend.perfect-scroll", function (e) {
|
|
|
|
inGlobalTouch = false;
|
|
|
|
});
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
$this.bind("touchstart.perfect-scroll", function (e) {
|
|
|
|
var touch = e.originalEvent.targetTouches[0];
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
startCoords.pageX = touch.pageX;
|
|
|
|
startCoords.pageY = touch.pageY;
|
|
|
|
|
|
|
|
startTime = (new Date()).getTime();
|
|
|
|
|
|
|
|
if (breakingProcess !== null) {
|
2013-05-18 11:41:15 +08:00
|
|
|
clearInterval(breakingProcess);
|
|
|
|
}
|
2013-06-14 20:57:24 +08:00
|
|
|
|
|
|
|
e.stopPropagation();
|
2013-05-22 17:48:51 +08:00
|
|
|
});
|
|
|
|
$this.bind("touchmove.perfect-scroll", function (e) {
|
2013-06-14 20:57:24 +08:00
|
|
|
if (!inGlobalTouch && e.originalEvent.targetTouches.length === 1) {
|
|
|
|
var touch = e.originalEvent.targetTouches[0];
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-06-14 20:57:24 +08:00
|
|
|
var currentCoords = {};
|
|
|
|
currentCoords.pageX = touch.pageX;
|
|
|
|
currentCoords.pageY = touch.pageY;
|
2013-05-22 17:48:51 +08:00
|
|
|
|
2013-06-14 20:57:24 +08:00
|
|
|
var differenceX = currentCoords.pageX - startCoords.pageX,
|
|
|
|
differenceY = currentCoords.pageY - startCoords.pageY;
|
2013-05-22 17:48:51 +08:00
|
|
|
|
2013-06-14 20:57:24 +08:00
|
|
|
applyTouchMove(differenceX, differenceY);
|
|
|
|
startCoords = currentCoords;
|
2013-05-22 17:48:51 +08:00
|
|
|
|
2013-06-14 20:57:24 +08:00
|
|
|
var currentTime = (new Date()).getTime();
|
|
|
|
speed.x = differenceX / (currentTime - startTime);
|
|
|
|
speed.y = differenceY / (currentTime - startTime);
|
|
|
|
startTime = currentTime;
|
2013-05-22 17:48:51 +08:00
|
|
|
|
2013-06-14 20:57:24 +08:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-05-22 17:48:51 +08:00
|
|
|
});
|
|
|
|
$this.bind("touchend.perfect-scroll", function (e) {
|
2013-08-05 22:59:17 +08:00
|
|
|
clearInterval(breakingProcess);
|
2013-05-22 17:48:51 +08:00
|
|
|
breakingProcess = setInterval(function () {
|
|
|
|
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
|
|
|
|
clearInterval(breakingProcess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyTouchMove(speed.x * 30, speed.y * 30);
|
|
|
|
|
|
|
|
speed.x *= 0.8;
|
|
|
|
speed.y *= 0.8;
|
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var destroy = function () {
|
2013-06-01 22:09:18 +08:00
|
|
|
$this.unbind('.perfect-scroll');
|
|
|
|
$(window).unbind('.perfect-scroll');
|
2013-09-09 09:12:35 +08:00
|
|
|
$(document).unbind('.perfect-scroll');
|
2013-05-22 17:48:51 +08:00
|
|
|
$this.data('perfect-scrollbar', null);
|
|
|
|
$this.data('perfect-scrollbar-update', null);
|
|
|
|
$this.data('perfect-scrollbar-destroy', null);
|
2013-08-05 22:59:17 +08:00
|
|
|
$scrollbarX.remove();
|
|
|
|
$scrollbarY.remove();
|
|
|
|
|
|
|
|
// clean all variables
|
|
|
|
$scrollbarX =
|
|
|
|
$scrollbarY =
|
|
|
|
containerWidth =
|
|
|
|
containerHeight =
|
|
|
|
contentWidth =
|
|
|
|
contentHeight =
|
|
|
|
scrollbarXWidth =
|
|
|
|
scrollbarXLeft =
|
|
|
|
scrollbarXBottom =
|
|
|
|
scrollbarYHeight =
|
|
|
|
scrollbarYTop =
|
|
|
|
scrollbarYRight = null;
|
2013-05-22 17:48:51 +08:00
|
|
|
};
|
|
|
|
|
2013-06-11 23:44:36 +08:00
|
|
|
var ieSupport = function (version) {
|
|
|
|
$this.addClass('ie').addClass('ie' + version);
|
2013-06-11 23:44:36 +08:00
|
|
|
|
|
|
|
var bindHoverHandlers = function () {
|
|
|
|
var mouseenter = function () {
|
|
|
|
$(this).addClass('hover');
|
|
|
|
};
|
|
|
|
var mouseleave = function () {
|
|
|
|
$(this).removeClass('hover');
|
|
|
|
};
|
|
|
|
$this.bind('mouseenter.perfect-scroll', mouseenter).bind('mouseleave.perfect-scroll', mouseleave);
|
|
|
|
$scrollbarX.bind('mouseenter.perfect-scroll', mouseenter).bind('mouseleave.perfect-scroll', mouseleave);
|
|
|
|
$scrollbarY.bind('mouseenter.perfect-scroll', mouseenter).bind('mouseleave.perfect-scroll', mouseleave);
|
|
|
|
};
|
|
|
|
|
2013-06-16 16:56:40 +08:00
|
|
|
var fixIe6ScrollbarPosition = function () {
|
|
|
|
updateScrollbarCss = function () {
|
|
|
|
$scrollbarX.css({left: scrollbarXLeft + $this.scrollLeft(), bottom: scrollbarXBottom, width: scrollbarXWidth});
|
|
|
|
$scrollbarY.css({top: scrollbarYTop + $this.scrollTop(), right: scrollbarYRight, height: scrollbarYHeight});
|
|
|
|
$scrollbarX.hide().show();
|
|
|
|
$scrollbarY.hide().show();
|
|
|
|
};
|
|
|
|
updateContentScrollTop = function () {
|
|
|
|
var scrollTop = parseInt(scrollbarYTop * contentHeight / containerHeight, 10);
|
|
|
|
$this.scrollTop(scrollTop);
|
|
|
|
$scrollbarX.css({bottom: scrollbarXBottom});
|
|
|
|
$scrollbarX.hide().show();
|
|
|
|
};
|
|
|
|
updateContentScrollLeft = function () {
|
|
|
|
var scrollLeft = parseInt(scrollbarXLeft * contentWidth / containerWidth, 10);
|
|
|
|
$this.scrollLeft(scrollLeft);
|
|
|
|
$scrollbarY.hide().show();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-11 23:44:36 +08:00
|
|
|
if (version === 6) {
|
|
|
|
bindHoverHandlers();
|
2013-06-16 16:56:40 +08:00
|
|
|
fixIe6ScrollbarPosition();
|
2013-06-11 23:44:36 +08:00
|
|
|
}
|
2013-06-11 23:44:36 +08:00
|
|
|
};
|
|
|
|
|
2013-06-29 01:14:40 +08:00
|
|
|
var supportsTouch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);
|
2013-05-22 17:48:51 +08:00
|
|
|
|
|
|
|
var initialize = function () {
|
2013-06-11 23:44:36 +08:00
|
|
|
var ieMatch = navigator.userAgent.toLowerCase().match(/(msie) ([\w.]+)/);
|
|
|
|
if (ieMatch && ieMatch[1] === 'msie') {
|
|
|
|
// must be executed at first, because 'ieSupport' may addClass to the container
|
|
|
|
ieSupport(parseInt(ieMatch[2], 10));
|
|
|
|
}
|
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
updateBarSizeAndPosition();
|
|
|
|
bindMouseScrollXHandler();
|
|
|
|
bindMouseScrollYHandler();
|
2013-06-29 01:14:40 +08:00
|
|
|
if (supportsTouch) {
|
2013-05-22 17:48:51 +08:00
|
|
|
bindMobileTouchHandler();
|
|
|
|
}
|
|
|
|
if ($this.mousewheel) {
|
|
|
|
bindMouseWheelHandler();
|
|
|
|
}
|
|
|
|
$this.data('perfect-scrollbar', $this);
|
|
|
|
$this.data('perfect-scrollbar-update', updateBarSizeAndPosition);
|
|
|
|
$this.data('perfect-scrollbar-destroy', destroy);
|
|
|
|
};
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
// initialize
|
|
|
|
initialize();
|
2013-05-18 11:41:15 +08:00
|
|
|
|
2013-05-22 17:48:51 +08:00
|
|
|
return $this;
|
|
|
|
});
|
2013-05-18 11:41:15 +08:00
|
|
|
};
|
2013-09-20 17:04:29 +08:00
|
|
|
}));
|