vendor/assets/javascripts/perfect-scrollbar.js in perfect-scrollbar-rails-0.6.12 vs vendor/assets/javascripts/perfect-scrollbar.js in perfect-scrollbar-rails-0.6.13
- old
+ new
@@ -1,6 +1,6 @@
-/* perfect-scrollbar v0.6.12 */
+/* perfect-scrollbar v0.6.13 */
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var ps = require('../main');
var psInstances = require('../plugin/instances');
@@ -269,11 +269,11 @@
var toInt = exports.toInt = function (x) {
return parseInt(x, 10) || 0;
};
var clone = exports.clone = function (obj) {
- if (obj === null) {
+ if (!obj) {
return null;
} else if (obj.constructor === Array) {
return obj.map(clone);
} else if (typeof obj === 'object') {
var result = {};
@@ -365,11 +365,10 @@
handlers: ['click-rail', 'drag-scrollbar', 'keyboard', 'wheel', 'touch'],
maxScrollbarLength: null,
minScrollbarLength: null,
scrollXMarginOffset: 0,
scrollYMarginOffset: 0,
- stopPropagationOnClick: true,
suppressScrollX: false,
suppressScrollY: false,
swipePropagation: true,
useBothWheelAxes: false,
wheelPropagation: false,
@@ -402,58 +401,37 @@
};
},{"../lib/dom":3,"../lib/helper":6,"./instances":18}],10:[function(require,module,exports){
'use strict';
-var _ = require('../../lib/helper');
var instances = require('../instances');
var updateGeometry = require('../update-geometry');
var updateScroll = require('../update-scroll');
function bindClickRailHandler(element, i) {
function pageOffset(el) {
return el.getBoundingClientRect();
}
var stopPropagation = function (e) { e.stopPropagation(); };
- if (i.settings.stopPropagationOnClick) {
- i.event.bind(i.scrollbarY, 'click', stopPropagation);
- }
+ i.event.bind(i.scrollbarY, 'click', stopPropagation);
i.event.bind(i.scrollbarYRail, 'click', function (e) {
- var halfOfScrollbarLength = _.toInt(i.scrollbarYHeight / 2);
- 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;
+ var positionTop = e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top;
+ var direction = positionTop > i.scrollbarYTop ? 1 : -1;
- if (positionRatio < 0) {
- positionRatio = 0;
- } else if (positionRatio > 1) {
- positionRatio = 1;
- }
-
- updateScroll(element, 'top', (i.contentHeight - i.containerHeight) * positionRatio);
+ updateScroll(element, 'top', element.scrollTop + direction * i.containerHeight);
updateGeometry(element);
e.stopPropagation();
});
- if (i.settings.stopPropagationOnClick) {
- i.event.bind(i.scrollbarX, 'click', stopPropagation);
- }
+ i.event.bind(i.scrollbarX, 'click', stopPropagation);
i.event.bind(i.scrollbarXRail, 'click', function (e) {
- var halfOfScrollbarLength = _.toInt(i.scrollbarXWidth / 2);
- 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;
+ var positionLeft = e.pageX - window.pageXOffset - pageOffset(i.scrollbarXRail).left;
+ var direction = positionLeft > i.scrollbarXLeft ? 1 : -1;
- if (positionRatio < 0) {
- positionRatio = 0;
- } else if (positionRatio > 1) {
- positionRatio = 1;
- }
-
- updateScroll(element, 'left', ((i.contentWidth - i.containerWidth) * positionRatio) - i.negativeScrollAdjustment);
+ updateScroll(element, 'left', element.scrollLeft + direction * i.containerWidth);
updateGeometry(element);
e.stopPropagation();
});
}
@@ -461,11 +439,11 @@
module.exports = function (element) {
var i = instances.get(element);
bindClickRailHandler(element, i);
};
-},{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],11:[function(require,module,exports){
+},{"../instances":18,"../update-geometry":19,"../update-scroll":20}],11:[function(require,module,exports){
'use strict';
var _ = require('../../lib/helper');
var dom = require('../../lib/dom');
var instances = require('../instances');
@@ -640,20 +618,44 @@
var deltaX = 0;
var deltaY = 0;
switch (e.which) {
case 37: // left
- deltaX = -30;
+ if (e.metaKey) {
+ deltaX = -i.contentWidth;
+ } else if (e.altKey) {
+ deltaX = -i.containerWidth;
+ } else {
+ deltaX = -30;
+ }
break;
case 38: // up
- deltaY = 30;
+ if (e.metaKey) {
+ deltaY = i.contentHeight;
+ } else if (e.altKey) {
+ deltaY = i.containerHeight;
+ } else {
+ deltaY = 30;
+ }
break;
case 39: // right
- deltaX = 30;
+ if (e.metaKey) {
+ deltaX = i.contentWidth;
+ } else if (e.altKey) {
+ deltaX = i.containerWidth;
+ } else {
+ deltaX = 30;
+ }
break;
case 40: // down
- deltaY = -30;
+ if (e.metaKey) {
+ deltaY = -i.contentHeight;
+ } else if (e.altKey) {
+ deltaY = -i.containerHeight;
+ } else {
+ deltaY = -30;
+ }
break;
case 33: // page up
deltaY = 90;
break;
case 32: // space bar
@@ -753,17 +755,22 @@
// IE in some mouse drivers
deltaX = 0;
deltaY = e.wheelDelta;
}
+ if (e.shiftKey) {
+ // reverse axis with shift key
+ return [-deltaY, -deltaX];
+ }
return [deltaX, deltaY];
}
function shouldBeConsumedByChild(deltaX, deltaY) {
var child = element.querySelector('textarea:hover, select[multiple]:hover, .ps-child:hover');
if (child) {
- if (child.tagName !== 'TEXTAREA' && !window.getComputedStyle(child).overflow.match(/(scroll|auto)/)) {
+ if (!window.getComputedStyle(child).overflow.match(/(scroll|auto)/)) {
+ // if not scrollable
return false;
}
var maxScrollTop = child.scrollHeight - child.clientHeight;
if (maxScrollTop > 0) {
@@ -911,10 +918,16 @@
if (isSelected) {
isSelected = false;
stopScrolling();
}
});
+ i.event.bind(window, 'keyup', function () {
+ if (isSelected) {
+ isSelected = false;
+ stopScrolling();
+ }
+ });
i.event.bind(window, 'mousemove', function (e) {
if (isSelected) {
var mousePosition = {x: e.pageX, y: e.pageY};
var containerGeometry = {
@@ -1095,10 +1108,15 @@
if (!instances.get(element)) {
clearInterval(easingLoop);
return;
}
+ if (!speed.x && !speed.y) {
+ clearInterval(easingLoop);
+ return;
+ }
+
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
clearInterval(easingLoop);
return;
}
@@ -1423,33 +1441,18 @@
},{"../lib/class":2,"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-scroll":20}],20:[function(require,module,exports){
'use strict';
var instances = require('./instances');
-var upEvent = document.createEvent('Event');
-var downEvent = document.createEvent('Event');
-var leftEvent = document.createEvent('Event');
-var rightEvent = document.createEvent('Event');
-var yEvent = document.createEvent('Event');
-var xEvent = document.createEvent('Event');
-var xStartEvent = document.createEvent('Event');
-var xEndEvent = document.createEvent('Event');
-var yStartEvent = document.createEvent('Event');
-var yEndEvent = document.createEvent('Event');
var lastTop;
var lastLeft;
-upEvent.initEvent('ps-scroll-up', true, true);
-downEvent.initEvent('ps-scroll-down', true, true);
-leftEvent.initEvent('ps-scroll-left', true, true);
-rightEvent.initEvent('ps-scroll-right', true, true);
-yEvent.initEvent('ps-scroll-y', true, true);
-xEvent.initEvent('ps-scroll-x', true, true);
-xStartEvent.initEvent('ps-x-reach-start', true, true);
-xEndEvent.initEvent('ps-x-reach-end', true, true);
-yStartEvent.initEvent('ps-y-reach-start', true, true);
-yEndEvent.initEvent('ps-y-reach-end', true, true);
+var createDOMEvent = function (name) {
+ var event = document.createEvent("Event");
+ event.initEvent(name, true, true);
+ return event;
+};
module.exports = function (element, axis, value) {
if (typeof element === 'undefined') {
throw 'You must provide an element to the update-scroll function';
}
@@ -1462,16 +1465,16 @@
throw 'You must provide a value to the update-scroll function';
}
if (axis === 'top' && value <= 0) {
element.scrollTop = value = 0; // don't allow negative scroll
- element.dispatchEvent(yStartEvent);
+ element.dispatchEvent(createDOMEvent('ps-y-reach-start'));
}
if (axis === 'left' && value <= 0) {
element.scrollLeft = value = 0; // don't allow negative scroll
- element.dispatchEvent(xStartEvent);
+ element.dispatchEvent(createDOMEvent('ps-x-reach-start'));
}
var i = instances.get(element);
if (axis === 'top' && value >= i.contentHeight - i.containerHeight) {
@@ -1481,11 +1484,11 @@
// mitigates rounding errors on non-subpixel scroll values
value = element.scrollTop;
} else {
element.scrollTop = value;
}
- element.dispatchEvent(yEndEvent);
+ element.dispatchEvent(createDOMEvent('ps-y-reach-end'));
}
if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
// don't allow scroll past container
value = i.contentWidth - i.containerWidth;
@@ -1493,11 +1496,11 @@
// mitigates rounding errors on non-subpixel scroll values
value = element.scrollLeft;
} else {
element.scrollLeft = value;
}
- element.dispatchEvent(xEndEvent);
+ element.dispatchEvent(createDOMEvent('ps-x-reach-end'));
}
if (!lastTop) {
lastTop = element.scrollTop;
}
@@ -1505,32 +1508,32 @@
if (!lastLeft) {
lastLeft = element.scrollLeft;
}
if (axis === 'top' && value < lastTop) {
- element.dispatchEvent(upEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-up'));
}
if (axis === 'top' && value > lastTop) {
- element.dispatchEvent(downEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-down'));
}
if (axis === 'left' && value < lastLeft) {
- element.dispatchEvent(leftEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-left'));
}
if (axis === 'left' && value > lastLeft) {
- element.dispatchEvent(rightEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-right'));
}
if (axis === 'top') {
element.scrollTop = lastTop = value;
- element.dispatchEvent(yEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-y'));
}
if (axis === 'left') {
element.scrollLeft = lastLeft = value;
- element.dispatchEvent(xEvent);
+ element.dispatchEvent(createDOMEvent('ps-scroll-x'));
}
};
},{"./instances":18}],21:[function(require,module,exports){