1 /* perfect-scrollbar v0.6.8 */
2 (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){
3 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
4 * Licensed under the MIT License
6 * Source: https://github.com/noraesae/perfect-scrollbar
10 var ps = require('../main')
11 , psInstances = require('../plugin/instances');
13 function mountJQuery(jQuery) {
14 jQuery.fn.perfectScrollbar = function (settingOrCommand) {
15 return this.each(function () {
16 if (typeof settingOrCommand === 'object' ||
17 typeof settingOrCommand === 'undefined') {
18 // If it's an object or none, initialize.
19 var settings = settingOrCommand;
21 if (!psInstances.get(this)) {
22 ps.initialize(this, settings);
25 // Unless, it may be a command.
26 var command = settingOrCommand;
28 if (command === 'update') {
30 } else if (command === 'destroy') {
40 if (typeof define === 'function' && define.amd) {
41 // AMD. Register as an anonymous module.
42 define(['jquery'], mountJQuery);
44 var jq = window.jQuery ? window.jQuery : window.$;
45 if (typeof jq !== 'undefined') {
50 module.exports = mountJQuery;
52 },{"../main":7,"../plugin/instances":18}],2:[function(require,module,exports){
53 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
54 * Licensed under the MIT License
58 function oldAdd(element, className) {
59 var classes = element.className.split(' ');
60 if (classes.indexOf(className) < 0) {
61 classes.push(className);
63 element.className = classes.join(' ');
66 function oldRemove(element, className) {
67 var classes = element.className.split(' ');
68 var idx = classes.indexOf(className);
70 classes.splice(idx, 1);
72 element.className = classes.join(' ');
75 exports.add = function (element, className) {
76 if (element.classList) {
77 element.classList.add(className);
79 oldAdd(element, className);
83 exports.remove = function (element, className) {
84 if (element.classList) {
85 element.classList.remove(className);
87 oldRemove(element, className);
91 exports.list = function (element) {
92 if (element.classList) {
93 return Array.prototype.slice.apply(element.classList);
95 return element.className.split(' ');
99 },{}],3:[function(require,module,exports){
100 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
101 * Licensed under the MIT License
107 DOM.e = function (tagName, className) {
108 var element = document.createElement(tagName);
109 element.className = className;
113 DOM.appendTo = function (child, parent) {
114 parent.appendChild(child);
118 function cssGet(element, styleName) {
119 return window.getComputedStyle(element)[styleName];
122 function cssSet(element, styleName, styleValue) {
123 if (typeof styleValue === 'number') {
124 styleValue = styleValue.toString() + 'px';
126 element.style[styleName] = styleValue;
130 function cssMultiSet(element, obj) {
131 for (var key in obj) {
133 if (typeof val === 'number') {
134 val = val.toString() + 'px';
136 element.style[key] = val;
141 DOM.css = function (element, styleNameOrObject, styleValue) {
142 if (typeof styleNameOrObject === 'object') {
143 // multiple set with object
144 return cssMultiSet(element, styleNameOrObject);
146 if (typeof styleValue === 'undefined') {
147 return cssGet(element, styleNameOrObject);
149 return cssSet(element, styleNameOrObject, styleValue);
154 DOM.matches = function (element, query) {
155 if (typeof element.matches !== 'undefined') {
156 return element.matches(query);
158 if (typeof element.matchesSelector !== 'undefined') {
159 return element.matchesSelector(query);
160 } else if (typeof element.webkitMatchesSelector !== 'undefined') {
161 return element.webkitMatchesSelector(query);
162 } else if (typeof element.mozMatchesSelector !== 'undefined') {
163 return element.mozMatchesSelector(query);
164 } else if (typeof element.msMatchesSelector !== 'undefined') {
165 return element.msMatchesSelector(query);
170 DOM.remove = function (element) {
171 if (typeof element.remove !== 'undefined') {
174 if (element.parentNode) {
175 element.parentNode.removeChild(element);
180 DOM.queryChildren = function (element, selector) {
181 return Array.prototype.filter.call(element.childNodes, function (child) {
182 return DOM.matches(child, selector);
186 module.exports = DOM;
188 },{}],4:[function(require,module,exports){
189 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
190 * Licensed under the MIT License
194 var EventElement = function (element) {
195 this.element = element;
199 EventElement.prototype.bind = function (eventName, handler) {
200 if (typeof this.events[eventName] === 'undefined') {
201 this.events[eventName] = [];
203 this.events[eventName].push(handler);
204 this.element.addEventListener(eventName, handler, false);
207 EventElement.prototype.unbind = function (eventName, handler) {
208 var isHandlerProvided = (typeof handler !== 'undefined');
209 this.events[eventName] = this.events[eventName].filter(function (hdlr) {
210 if (isHandlerProvided && hdlr !== handler) {
213 this.element.removeEventListener(eventName, hdlr, false);
218 EventElement.prototype.unbindAll = function () {
219 for (var name in this.events) {
224 var EventManager = function () {
225 this.eventElements = [];
228 EventManager.prototype.eventElement = function (element) {
229 var ee = this.eventElements.filter(function (eventElement) {
230 return eventElement.element === element;
232 if (typeof ee === 'undefined') {
233 ee = new EventElement(element);
234 this.eventElements.push(ee);
239 EventManager.prototype.bind = function (element, eventName, handler) {
240 this.eventElement(element).bind(eventName, handler);
243 EventManager.prototype.unbind = function (element, eventName, handler) {
244 this.eventElement(element).unbind(eventName, handler);
247 EventManager.prototype.unbindAll = function () {
248 for (var i = 0; i < this.eventElements.length; i++) {
249 this.eventElements[i].unbindAll();
253 EventManager.prototype.once = function (element, eventName, handler) {
254 var ee = this.eventElement(element);
255 var onceHandler = function (e) {
256 ee.unbind(eventName, onceHandler);
259 ee.bind(eventName, onceHandler);
262 module.exports = EventManager;
264 },{}],5:[function(require,module,exports){
265 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
266 * Licensed under the MIT License
270 module.exports = (function () {
272 return Math.floor((1 + Math.random()) * 0x10000)
277 return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
278 s4() + '-' + s4() + s4() + s4();
282 },{}],6:[function(require,module,exports){
283 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
284 * Licensed under the MIT License
288 var cls = require('./class')
289 , d = require('./dom');
291 exports.toInt = function (x) {
292 return parseInt(x, 10) || 0;
295 exports.clone = function (obj) {
298 } else if (typeof obj === 'object') {
300 for (var key in obj) {
301 result[key] = this.clone(obj[key]);
309 exports.extend = function (original, source) {
310 var result = this.clone(original);
311 for (var key in source) {
312 result[key] = this.clone(source[key]);
317 exports.isEditable = function (el) {
318 return d.matches(el, "input,[contenteditable]") ||
319 d.matches(el, "select,[contenteditable]") ||
320 d.matches(el, "textarea,[contenteditable]") ||
321 d.matches(el, "button,[contenteditable]");
324 exports.removePsClasses = function (element) {
325 var clsList = cls.list(element);
326 for (var i = 0; i < clsList.length; i++) {
327 var className = clsList[i];
328 if (className.indexOf('ps-') === 0) {
329 cls.remove(element, className);
334 exports.outerWidth = function (element) {
335 return this.toInt(d.css(element, 'width')) +
336 this.toInt(d.css(element, 'paddingLeft')) +
337 this.toInt(d.css(element, 'paddingRight')) +
338 this.toInt(d.css(element, 'borderLeftWidth')) +
339 this.toInt(d.css(element, 'borderRightWidth'));
342 exports.startScrolling = function (element, axis) {
343 cls.add(element, 'ps-in-scrolling');
344 if (typeof axis !== 'undefined') {
345 cls.add(element, 'ps-' + axis);
347 cls.add(element, 'ps-x');
348 cls.add(element, 'ps-y');
352 exports.stopScrolling = function (element, axis) {
353 cls.remove(element, 'ps-in-scrolling');
354 if (typeof axis !== 'undefined') {
355 cls.remove(element, 'ps-' + axis);
357 cls.remove(element, 'ps-x');
358 cls.remove(element, 'ps-y');
363 isWebKit: 'WebkitAppearance' in document.documentElement.style,
364 supportsTouch: (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch),
365 supportsIePointer: window.navigator.msMaxTouchPoints !== null
368 },{"./class":2,"./dom":3}],7:[function(require,module,exports){
369 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
370 * Licensed under the MIT License
374 var destroy = require('./plugin/destroy')
375 , initialize = require('./plugin/initialize')
376 , update = require('./plugin/update');
379 initialize: initialize,
384 },{"./plugin/destroy":9,"./plugin/initialize":17,"./plugin/update":21}],8:[function(require,module,exports){
385 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
386 * Licensed under the MIT License
391 maxScrollbarLength: null,
392 minScrollbarLength: null,
393 scrollXMarginOffset: 0,
394 scrollYMarginOffset: 0,
395 stopPropagationOnClick: true,
396 suppressScrollX: false,
397 suppressScrollY: false,
398 swipePropagation: true,
399 useBothWheelAxes: false,
401 useSelectionScroll: false,
402 wheelPropagation: false,
406 },{}],9:[function(require,module,exports){
407 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
408 * Licensed under the MIT License
412 var d = require('../lib/dom')
413 , h = require('../lib/helper')
414 , instances = require('./instances');
416 module.exports = function (element) {
417 var i = instances.get(element);
424 d.remove(i.scrollbarX);
425 d.remove(i.scrollbarY);
426 d.remove(i.scrollbarXRail);
427 d.remove(i.scrollbarYRail);
428 h.removePsClasses(element);
430 instances.remove(element);
433 },{"../lib/dom":3,"../lib/helper":6,"./instances":18}],10:[function(require,module,exports){
434 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
435 * Licensed under the MIT License
439 var h = require('../../lib/helper')
440 , instances = require('../instances')
441 , updateGeometry = require('../update-geometry')
442 , updateScroll = require('../update-scroll');
444 function bindClickRailHandler(element, i) {
445 function pageOffset(el) {
446 return el.getBoundingClientRect();
448 var stopPropagation = window.Event.prototype.stopPropagation.bind;
450 if (i.settings.stopPropagationOnClick) {
451 i.event.bind(i.scrollbarY, 'click', stopPropagation);
453 i.event.bind(i.scrollbarYRail, 'click', function (e) {
454 var halfOfScrollbarLength = h.toInt(i.scrollbarYHeight / 2);
455 var positionTop = i.railYRatio * (e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
456 var maxPositionTop = i.railYRatio * (i.railYHeight - i.scrollbarYHeight);
457 var positionRatio = positionTop / maxPositionTop;
459 if (positionRatio < 0) {
461 } else if (positionRatio > 1) {
465 updateScroll(element, 'top', (i.contentHeight - i.containerHeight) * positionRatio);
466 updateGeometry(element);
471 if (i.settings.stopPropagationOnClick) {
472 i.event.bind(i.scrollbarX, 'click', stopPropagation);
474 i.event.bind(i.scrollbarXRail, 'click', function (e) {
475 var halfOfScrollbarLength = h.toInt(i.scrollbarXWidth / 2);
476 var positionLeft = i.railXRatio * (e.pageX - window.pageXOffset - pageOffset(i.scrollbarXRail).left - halfOfScrollbarLength);
477 var maxPositionLeft = i.railXRatio * (i.railXWidth - i.scrollbarXWidth);
478 var positionRatio = positionLeft / maxPositionLeft;
480 if (positionRatio < 0) {
482 } else if (positionRatio > 1) {
486 updateScroll(element, 'left', ((i.contentWidth - i.containerWidth) * positionRatio) - i.negativeScrollAdjustment);
487 updateGeometry(element);
493 module.exports = function (element) {
494 var i = instances.get(element);
495 bindClickRailHandler(element, i);
498 },{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],11:[function(require,module,exports){
499 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
500 * Licensed under the MIT License
504 var d = require('../../lib/dom')
505 , h = require('../../lib/helper')
506 , instances = require('../instances')
507 , updateGeometry = require('../update-geometry')
508 , updateScroll = require('../update-scroll');
510 function bindMouseScrollXHandler(element, i) {
511 var currentLeft = null;
512 var currentPageX = null;
514 function updateScrollLeft(deltaX) {
515 var newLeft = currentLeft + (deltaX * i.railXRatio);
516 var maxLeft = Math.max(0, i.scrollbarXRail.getBoundingClientRect().left) + (i.railXRatio * (i.railXWidth - i.scrollbarXWidth));
519 i.scrollbarXLeft = 0;
520 } else if (newLeft > maxLeft) {
521 i.scrollbarXLeft = maxLeft;
523 i.scrollbarXLeft = newLeft;
526 var scrollLeft = h.toInt(i.scrollbarXLeft * (i.contentWidth - i.containerWidth) / (i.containerWidth - (i.railXRatio * i.scrollbarXWidth))) - i.negativeScrollAdjustment;
527 updateScroll(element, 'left', scrollLeft);
530 var mouseMoveHandler = function (e) {
531 updateScrollLeft(e.pageX - currentPageX);
532 updateGeometry(element);
537 var mouseUpHandler = function () {
538 h.stopScrolling(element, 'x');
539 i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
542 i.event.bind(i.scrollbarX, 'mousedown', function (e) {
543 currentPageX = e.pageX;
544 currentLeft = h.toInt(d.css(i.scrollbarX, 'left')) * i.railXRatio;
545 h.startScrolling(element, 'x');
547 i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
548 i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
555 function bindMouseScrollYHandler(element, i) {
556 var currentTop = null;
557 var currentPageY = null;
559 function updateScrollTop(deltaY) {
560 var newTop = currentTop + (deltaY * i.railYRatio);
561 var maxTop = Math.max(0, i.scrollbarYRail.getBoundingClientRect().top) + (i.railYRatio * (i.railYHeight - i.scrollbarYHeight));
565 } else if (newTop > maxTop) {
566 i.scrollbarYTop = maxTop;
568 i.scrollbarYTop = newTop;
571 var scrollTop = h.toInt(i.scrollbarYTop * (i.contentHeight - i.containerHeight) / (i.containerHeight - (i.railYRatio * i.scrollbarYHeight)));
572 updateScroll(element, 'top', scrollTop);
575 var mouseMoveHandler = function (e) {
576 updateScrollTop(e.pageY - currentPageY);
577 updateGeometry(element);
582 var mouseUpHandler = function () {
583 h.stopScrolling(element, 'y');
584 i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
587 i.event.bind(i.scrollbarY, 'mousedown', function (e) {
588 currentPageY = e.pageY;
589 currentTop = h.toInt(d.css(i.scrollbarY, 'top')) * i.railYRatio;
590 h.startScrolling(element, 'y');
592 i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
593 i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
600 module.exports = function (element) {
601 var i = instances.get(element);
602 bindMouseScrollXHandler(element, i);
603 bindMouseScrollYHandler(element, i);
606 },{"../../lib/dom":3,"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],12:[function(require,module,exports){
607 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
608 * Licensed under the MIT License
612 var h = require('../../lib/helper')
613 , instances = require('../instances')
614 , updateGeometry = require('../update-geometry')
615 , updateScroll = require('../update-scroll');
617 function bindKeyboardHandler(element, i) {
619 i.event.bind(element, 'mouseenter', function () {
622 i.event.bind(element, 'mouseleave', function () {
626 var shouldPrevent = false;
627 function shouldPreventDefault(deltaX, deltaY) {
628 var scrollTop = element.scrollTop;
630 if (!i.scrollbarYActive) {
633 if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
634 return !i.settings.wheelPropagation;
638 var scrollLeft = element.scrollLeft;
640 if (!i.scrollbarXActive) {
643 if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
644 return !i.settings.wheelPropagation;
650 i.event.bind(i.ownerDocument, 'keydown', function (e) {
651 if (e.isDefaultPrevented && e.isDefaultPrevented()) {
659 var activeElement = document.activeElement ? document.activeElement : i.ownerDocument.activeElement;
661 // go deeper if element is a webcomponent
662 while (activeElement.shadowRoot) {
663 activeElement = activeElement.shadowRoot.activeElement;
665 if (h.isEditable(activeElement)) {
689 case 32: // space bar
696 case 34: // page down
701 deltaY = -i.contentHeight;
703 deltaY = -i.containerHeight;
708 deltaY = element.scrollTop;
710 deltaY = i.containerHeight;
717 updateScroll(element, 'top', element.scrollTop - deltaY);
718 updateScroll(element, 'left', element.scrollLeft + deltaX);
719 updateGeometry(element);
721 shouldPrevent = shouldPreventDefault(deltaX, deltaY);
728 module.exports = function (element) {
729 var i = instances.get(element);
730 bindKeyboardHandler(element, i);
733 },{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],13:[function(require,module,exports){
734 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
735 * Licensed under the MIT License
739 var instances = require('../instances')
740 , updateGeometry = require('../update-geometry')
741 , updateScroll = require('../update-scroll');
743 function bindMouseWheelHandler(element, i) {
744 var shouldPrevent = false;
746 function shouldPreventDefault(deltaX, deltaY) {
747 var scrollTop = element.scrollTop;
749 if (!i.scrollbarYActive) {
752 if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
753 return !i.settings.wheelPropagation;
757 var scrollLeft = element.scrollLeft;
759 if (!i.scrollbarXActive) {
762 if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
763 return !i.settings.wheelPropagation;
769 function getDeltaFromEvent(e) {
770 var deltaX = e.deltaX;
771 var deltaY = -1 * e.deltaY;
773 if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
775 deltaX = -1 * e.wheelDeltaX / 6;
776 deltaY = e.wheelDeltaY / 6;
779 if (e.deltaMode && e.deltaMode === 1) {
780 // Firefox in deltaMode 1: Line scrolling
785 if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
786 // IE in some mouse drivers
788 deltaY = e.wheelDelta;
791 return [deltaX, deltaY];
794 function shouldBeConsumedByTextarea(deltaX, deltaY) {
795 var hoveredTextarea = element.querySelector('textarea:hover');
796 if (hoveredTextarea) {
797 var maxScrollTop = hoveredTextarea.scrollHeight - hoveredTextarea.clientHeight;
798 if (maxScrollTop > 0) {
799 if (!(hoveredTextarea.scrollTop === 0 && deltaY > 0) &&
800 !(hoveredTextarea.scrollTop === maxScrollTop && deltaY < 0)) {
804 var maxScrollLeft = hoveredTextarea.scrollLeft - hoveredTextarea.clientWidth;
805 if (maxScrollLeft > 0) {
806 if (!(hoveredTextarea.scrollLeft === 0 && deltaX < 0) &&
807 !(hoveredTextarea.scrollLeft === maxScrollLeft && deltaX > 0)) {
815 function mousewheelHandler(e) {
816 var delta = getDeltaFromEvent(e);
818 var deltaX = delta[0];
819 var deltaY = delta[1];
821 if (shouldBeConsumedByTextarea(deltaX, deltaY)) {
825 shouldPrevent = false;
826 if (!i.settings.useBothWheelAxes) {
827 // deltaX will only be used for horizontal scrolling and deltaY will
828 // only be used for vertical scrolling - this is the default
829 updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
830 updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
831 } else if (i.scrollbarYActive && !i.scrollbarXActive) {
832 // only vertical scrollbar is active and useBothWheelAxes option is
833 // active, so let's scroll vertical bar using both mouse wheel axes
835 updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
837 updateScroll(element, 'top', element.scrollTop + (deltaX * i.settings.wheelSpeed));
839 shouldPrevent = true;
840 } else if (i.scrollbarXActive && !i.scrollbarYActive) {
841 // useBothWheelAxes and only horizontal bar is active, so use both
842 // wheel axes for horizontal bar
844 updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
846 updateScroll(element, 'left', element.scrollLeft - (deltaY * i.settings.wheelSpeed));
848 shouldPrevent = true;
851 updateGeometry(element);
853 shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
860 if (typeof window.onwheel !== "undefined") {
861 i.event.bind(element, 'wheel', mousewheelHandler);
862 } else if (typeof window.onmousewheel !== "undefined") {
863 i.event.bind(element, 'mousewheel', mousewheelHandler);
867 module.exports = function (element) {
868 var i = instances.get(element);
869 bindMouseWheelHandler(element, i);
872 },{"../instances":18,"../update-geometry":19,"../update-scroll":20}],14:[function(require,module,exports){
873 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
874 * Licensed under the MIT License
878 var instances = require('../instances')
879 , updateGeometry = require('../update-geometry');
881 function bindNativeScrollHandler(element, i) {
882 i.event.bind(element, 'scroll', function () {
883 updateGeometry(element);
887 module.exports = function (element) {
888 var i = instances.get(element);
889 bindNativeScrollHandler(element, i);
892 },{"../instances":18,"../update-geometry":19}],15:[function(require,module,exports){
893 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
894 * Licensed under the MIT License
898 var h = require('../../lib/helper')
899 , instances = require('../instances')
900 , updateGeometry = require('../update-geometry')
901 , updateScroll = require('../update-scroll');
903 function bindSelectionHandler(element, i) {
904 function getRangeNode() {
905 var selection = window.getSelection ? window.getSelection() :
906 document.getSelection ? document.getSelection() : '';
907 if (selection.toString().length === 0) {
910 return selection.getRangeAt(0).commonAncestorContainer;
914 var scrollingLoop = null;
915 var scrollDiff = {top: 0, left: 0};
916 function startScrolling() {
917 if (!scrollingLoop) {
918 scrollingLoop = setInterval(function () {
919 if (!instances.get(element)) {
920 clearInterval(scrollingLoop);
924 updateScroll(element, 'top', element.scrollTop + scrollDiff.top);
925 updateScroll(element, 'left', element.scrollLeft + scrollDiff.left);
926 updateGeometry(element);
927 }, 50); // every .1 sec
930 function stopScrolling() {
932 clearInterval(scrollingLoop);
933 scrollingLoop = null;
935 h.stopScrolling(element);
938 var isSelected = false;
939 i.event.bind(i.ownerDocument, 'selectionchange', function () {
940 if (element.contains(getRangeNode())) {
947 i.event.bind(window, 'mouseup', function () {
954 i.event.bind(window, 'mousemove', function (e) {
956 var mousePosition = {x: e.pageX, y: e.pageY};
957 var containerGeometry = {
958 left: element.offsetLeft,
959 right: element.offsetLeft + element.offsetWidth,
960 top: element.offsetTop,
961 bottom: element.offsetTop + element.offsetHeight
964 if (mousePosition.x < containerGeometry.left + 3) {
965 scrollDiff.left = -5;
966 h.startScrolling(element, 'x');
967 } else if (mousePosition.x > containerGeometry.right - 3) {
969 h.startScrolling(element, 'x');
974 if (mousePosition.y < containerGeometry.top + 3) {
975 if (containerGeometry.top + 3 - mousePosition.y < 5) {
978 scrollDiff.top = -20;
980 h.startScrolling(element, 'y');
981 } else if (mousePosition.y > containerGeometry.bottom - 3) {
982 if (mousePosition.y - containerGeometry.bottom + 3 < 5) {
987 h.startScrolling(element, 'y');
992 if (scrollDiff.top === 0 && scrollDiff.left === 0) {
1001 module.exports = function (element) {
1002 var i = instances.get(element);
1003 bindSelectionHandler(element, i);
1006 },{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],16:[function(require,module,exports){
1007 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1008 * Licensed under the MIT License
1012 var instances = require('../instances')
1013 , updateGeometry = require('../update-geometry')
1014 , updateScroll = require('../update-scroll');
1016 function bindTouchHandler(element, i, supportsTouch, supportsIePointer) {
1017 function shouldPreventDefault(deltaX, deltaY) {
1018 var scrollTop = element.scrollTop;
1019 var scrollLeft = element.scrollLeft;
1020 var magnitudeX = Math.abs(deltaX);
1021 var magnitudeY = Math.abs(deltaY);
1023 if (magnitudeY > magnitudeX) {
1024 // user is perhaps trying to swipe up/down the page
1026 if (((deltaY < 0) && (scrollTop === i.contentHeight - i.containerHeight)) ||
1027 ((deltaY > 0) && (scrollTop === 0))) {
1028 return !i.settings.swipePropagation;
1030 } else if (magnitudeX > magnitudeY) {
1031 // user is perhaps trying to swipe left/right across the page
1033 if (((deltaX < 0) && (scrollLeft === i.contentWidth - i.containerWidth)) ||
1034 ((deltaX > 0) && (scrollLeft === 0))) {
1035 return !i.settings.swipePropagation;
1042 function applyTouchMove(differenceX, differenceY) {
1043 updateScroll(element, 'top', element.scrollTop - differenceY);
1044 updateScroll(element, 'left', element.scrollLeft - differenceX);
1046 updateGeometry(element);
1049 var startOffset = {};
1052 var easingLoop = null;
1053 var inGlobalTouch = false;
1054 var inLocalTouch = false;
1056 function globalTouchStart() {
1057 inGlobalTouch = true;
1059 function globalTouchEnd() {
1060 inGlobalTouch = false;
1063 function getTouch(e) {
1064 if (e.targetTouches) {
1065 return e.targetTouches[0];
1071 function shouldHandle(e) {
1072 if (e.targetTouches && e.targetTouches.length === 1) {
1075 if (e.pointerType && e.pointerType !== 'mouse' && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
1080 function touchStart(e) {
1081 if (shouldHandle(e)) {
1082 inLocalTouch = true;
1084 var touch = getTouch(e);
1086 startOffset.pageX = touch.pageX;
1087 startOffset.pageY = touch.pageY;
1089 startTime = (new Date()).getTime();
1091 if (easingLoop !== null) {
1092 clearInterval(easingLoop);
1095 e.stopPropagation();
1098 function touchMove(e) {
1099 if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
1100 var touch = getTouch(e);
1102 var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
1104 var differenceX = currentOffset.pageX - startOffset.pageX;
1105 var differenceY = currentOffset.pageY - startOffset.pageY;
1107 applyTouchMove(differenceX, differenceY);
1108 startOffset = currentOffset;
1110 var currentTime = (new Date()).getTime();
1112 var timeGap = currentTime - startTime;
1114 speed.x = differenceX / timeGap;
1115 speed.y = differenceY / timeGap;
1116 startTime = currentTime;
1119 if (shouldPreventDefault(differenceX, differenceY)) {
1120 e.stopPropagation();
1125 function touchEnd() {
1126 if (!inGlobalTouch && inLocalTouch) {
1127 inLocalTouch = false;
1129 clearInterval(easingLoop);
1130 easingLoop = setInterval(function () {
1131 if (!instances.get(element)) {
1132 clearInterval(easingLoop);
1136 if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
1137 clearInterval(easingLoop);
1141 applyTouchMove(speed.x * 30, speed.y * 30);
1149 if (supportsTouch) {
1150 i.event.bind(window, 'touchstart', globalTouchStart);
1151 i.event.bind(window, 'touchend', globalTouchEnd);
1152 i.event.bind(element, 'touchstart', touchStart);
1153 i.event.bind(element, 'touchmove', touchMove);
1154 i.event.bind(element, 'touchend', touchEnd);
1157 if (supportsIePointer) {
1158 if (window.PointerEvent) {
1159 i.event.bind(window, 'pointerdown', globalTouchStart);
1160 i.event.bind(window, 'pointerup', globalTouchEnd);
1161 i.event.bind(element, 'pointerdown', touchStart);
1162 i.event.bind(element, 'pointermove', touchMove);
1163 i.event.bind(element, 'pointerup', touchEnd);
1164 } else if (window.MSPointerEvent) {
1165 i.event.bind(window, 'MSPointerDown', globalTouchStart);
1166 i.event.bind(window, 'MSPointerUp', globalTouchEnd);
1167 i.event.bind(element, 'MSPointerDown', touchStart);
1168 i.event.bind(element, 'MSPointerMove', touchMove);
1169 i.event.bind(element, 'MSPointerUp', touchEnd);
1174 module.exports = function (element, supportsTouch, supportsIePointer) {
1175 var i = instances.get(element);
1176 bindTouchHandler(element, i, supportsTouch, supportsIePointer);
1179 },{"../instances":18,"../update-geometry":19,"../update-scroll":20}],17:[function(require,module,exports){
1180 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1181 * Licensed under the MIT License
1185 var cls = require('../lib/class')
1186 , h = require('../lib/helper')
1187 , instances = require('./instances')
1188 , updateGeometry = require('./update-geometry');
1191 var clickRailHandler = require('./handler/click-rail')
1192 , dragScrollbarHandler = require('./handler/drag-scrollbar')
1193 , keyboardHandler = require('./handler/keyboard')
1194 , mouseWheelHandler = require('./handler/mouse-wheel')
1195 , nativeScrollHandler = require('./handler/native-scroll')
1196 , selectionHandler = require('./handler/selection')
1197 , touchHandler = require('./handler/touch');
1199 module.exports = function (element, userSettings) {
1200 userSettings = typeof userSettings === 'object' ? userSettings : {};
1202 cls.add(element, 'ps-container');
1204 // Create a plugin instance.
1205 var i = instances.add(element);
1207 i.settings = h.extend(i.settings, userSettings);
1209 clickRailHandler(element);
1210 dragScrollbarHandler(element);
1211 mouseWheelHandler(element);
1212 nativeScrollHandler(element);
1214 if (i.settings.useSelectionScroll) {
1215 selectionHandler(element);
1218 if (h.env.supportsTouch || h.env.supportsIePointer) {
1219 touchHandler(element, h.env.supportsTouch, h.env.supportsIePointer);
1221 if (i.settings.useKeyboard) {
1222 keyboardHandler(element);
1225 updateGeometry(element);
1228 },{"../lib/class":2,"../lib/helper":6,"./handler/click-rail":10,"./handler/drag-scrollbar":11,"./handler/keyboard":12,"./handler/mouse-wheel":13,"./handler/native-scroll":14,"./handler/selection":15,"./handler/touch":16,"./instances":18,"./update-geometry":19}],18:[function(require,module,exports){
1229 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1230 * Licensed under the MIT License
1234 var d = require('../lib/dom')
1235 , defaultSettings = require('./default-setting')
1236 , EventManager = require('../lib/event-manager')
1237 , guid = require('../lib/guid')
1238 , h = require('../lib/helper');
1242 function Instance(element) {
1245 i.settings = h.clone(defaultSettings);
1246 i.containerWidth = null;
1247 i.containerHeight = null;
1248 i.contentWidth = null;
1249 i.contentHeight = null;
1251 i.isRtl = d.css(element, 'direction') === "rtl";
1252 i.isNegativeScroll = (function () {
1253 var originalScrollLeft = element.scrollLeft;
1255 element.scrollLeft = -1;
1256 result = element.scrollLeft < 0;
1257 element.scrollLeft = originalScrollLeft;
1260 i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
1261 i.event = new EventManager();
1262 i.ownerDocument = element.ownerDocument || document;
1264 i.scrollbarXRail = d.appendTo(d.e('div', 'ps-scrollbar-x-rail'), element);
1265 i.scrollbarX = d.appendTo(d.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
1266 i.scrollbarX.setAttribute('tabindex', 0);
1267 i.scrollbarXActive = null;
1268 i.scrollbarXWidth = null;
1269 i.scrollbarXLeft = null;
1270 i.scrollbarXBottom = h.toInt(d.css(i.scrollbarXRail, 'bottom'));
1271 i.isScrollbarXUsingBottom = i.scrollbarXBottom === i.scrollbarXBottom; // !isNaN
1272 i.scrollbarXTop = i.isScrollbarXUsingBottom ? null : h.toInt(d.css(i.scrollbarXRail, 'top'));
1273 i.railBorderXWidth = h.toInt(d.css(i.scrollbarXRail, 'borderLeftWidth')) + h.toInt(d.css(i.scrollbarXRail, 'borderRightWidth'));
1274 // Set rail to display:block to calculate margins
1275 d.css(i.scrollbarXRail, 'display', 'block');
1276 i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
1277 d.css(i.scrollbarXRail, 'display', '');
1278 i.railXWidth = null;
1279 i.railXRatio = null;
1281 i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
1282 i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
1283 i.scrollbarY.setAttribute('tabindex', 0);
1284 i.scrollbarYActive = null;
1285 i.scrollbarYHeight = null;
1286 i.scrollbarYTop = null;
1287 i.scrollbarYRight = h.toInt(d.css(i.scrollbarYRail, 'right'));
1288 i.isScrollbarYUsingRight = i.scrollbarYRight === i.scrollbarYRight; // !isNaN
1289 i.scrollbarYLeft = i.isScrollbarYUsingRight ? null : h.toInt(d.css(i.scrollbarYRail, 'left'));
1290 i.scrollbarYOuterWidth = i.isRtl ? h.outerWidth(i.scrollbarY) : null;
1291 i.railBorderYWidth = h.toInt(d.css(i.scrollbarYRail, 'borderTopWidth')) + h.toInt(d.css(i.scrollbarYRail, 'borderBottomWidth'));
1292 d.css(i.scrollbarYRail, 'display', 'block');
1293 i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
1294 d.css(i.scrollbarYRail, 'display', '');
1295 i.railYHeight = null;
1296 i.railYRatio = null;
1299 function getId(element) {
1300 if (typeof element.dataset === 'undefined') {
1301 return element.getAttribute('data-ps-id');
1303 return element.dataset.psId;
1307 function setId(element, id) {
1308 if (typeof element.dataset === 'undefined') {
1309 element.setAttribute('data-ps-id', id);
1311 element.dataset.psId = id;
1315 function removeId(element) {
1316 if (typeof element.dataset === 'undefined') {
1317 element.removeAttribute('data-ps-id');
1319 delete element.dataset.psId;
1323 exports.add = function (element) {
1325 setId(element, newId);
1326 instances[newId] = new Instance(element);
1327 return instances[newId];
1330 exports.remove = function (element) {
1331 delete instances[getId(element)];
1335 exports.get = function (element) {
1336 return instances[getId(element)];
1339 },{"../lib/dom":3,"../lib/event-manager":4,"../lib/guid":5,"../lib/helper":6,"./default-setting":8}],19:[function(require,module,exports){
1340 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1341 * Licensed under the MIT License
1345 var cls = require('../lib/class')
1346 , d = require('../lib/dom')
1347 , h = require('../lib/helper')
1348 , instances = require('./instances')
1349 , updateScroll = require('./update-scroll');
1351 function getThumbSize(i, thumbSize) {
1352 if (i.settings.minScrollbarLength) {
1353 thumbSize = Math.max(thumbSize, i.settings.minScrollbarLength);
1355 if (i.settings.maxScrollbarLength) {
1356 thumbSize = Math.min(thumbSize, i.settings.maxScrollbarLength);
1361 function updateCss(element, i) {
1362 var xRailOffset = {width: i.railXWidth};
1364 xRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth - i.contentWidth;
1366 xRailOffset.left = element.scrollLeft;
1368 if (i.isScrollbarXUsingBottom) {
1369 xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
1371 xRailOffset.top = i.scrollbarXTop + element.scrollTop;
1373 d.css(i.scrollbarXRail, xRailOffset);
1375 var yRailOffset = {top: element.scrollTop, height: i.railYHeight};
1376 if (i.isScrollbarYUsingRight) {
1378 yRailOffset.right = i.contentWidth - (i.negativeScrollAdjustment + element.scrollLeft) - i.scrollbarYRight - i.scrollbarYOuterWidth;
1380 yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
1384 yRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth * 2 - i.contentWidth - i.scrollbarYLeft - i.scrollbarYOuterWidth;
1386 yRailOffset.left = i.scrollbarYLeft + element.scrollLeft;
1389 d.css(i.scrollbarYRail, yRailOffset);
1391 d.css(i.scrollbarX, {left: i.scrollbarXLeft, width: i.scrollbarXWidth - i.railBorderXWidth});
1392 d.css(i.scrollbarY, {top: i.scrollbarYTop, height: i.scrollbarYHeight - i.railBorderYWidth});
1395 module.exports = function (element) {
1396 var i = instances.get(element);
1398 i.containerWidth = element.clientWidth;
1399 i.containerHeight = element.clientHeight;
1400 i.contentWidth = element.scrollWidth;
1401 i.contentHeight = element.scrollHeight;
1404 if (!element.contains(i.scrollbarXRail)) {
1405 existingRails = d.queryChildren(element, '.ps-scrollbar-x-rail');
1406 if (existingRails.length > 0) {
1407 existingRails.forEach(function (rail) {
1411 d.appendTo(i.scrollbarXRail, element);
1413 if (!element.contains(i.scrollbarYRail)) {
1414 existingRails = d.queryChildren(element, '.ps-scrollbar-y-rail');
1415 if (existingRails.length > 0) {
1416 existingRails.forEach(function (rail) {
1420 d.appendTo(i.scrollbarYRail, element);
1423 if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
1424 i.scrollbarXActive = true;
1425 i.railXWidth = i.containerWidth - i.railXMarginWidth;
1426 i.railXRatio = i.containerWidth / i.railXWidth;
1427 i.scrollbarXWidth = getThumbSize(i, h.toInt(i.railXWidth * i.containerWidth / i.contentWidth));
1428 i.scrollbarXLeft = h.toInt((i.negativeScrollAdjustment + element.scrollLeft) * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
1430 i.scrollbarXActive = false;
1433 if (!i.settings.suppressScrollY && i.containerHeight + i.settings.scrollYMarginOffset < i.contentHeight) {
1434 i.scrollbarYActive = true;
1435 i.railYHeight = i.containerHeight - i.railYMarginHeight;
1436 i.railYRatio = i.containerHeight / i.railYHeight;
1437 i.scrollbarYHeight = getThumbSize(i, h.toInt(i.railYHeight * i.containerHeight / i.contentHeight));
1438 i.scrollbarYTop = h.toInt(element.scrollTop * (i.railYHeight - i.scrollbarYHeight) / (i.contentHeight - i.containerHeight));
1440 i.scrollbarYActive = false;
1443 if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
1444 i.scrollbarXLeft = i.railXWidth - i.scrollbarXWidth;
1446 if (i.scrollbarYTop >= i.railYHeight - i.scrollbarYHeight) {
1447 i.scrollbarYTop = i.railYHeight - i.scrollbarYHeight;
1450 updateCss(element, i);
1452 if (i.scrollbarXActive) {
1453 cls.add(element, 'ps-active-x');
1455 cls.remove(element, 'ps-active-x');
1456 i.scrollbarXWidth = 0;
1457 i.scrollbarXLeft = 0;
1458 updateScroll(element, 'left', 0);
1460 if (i.scrollbarYActive) {
1461 cls.add(element, 'ps-active-y');
1463 cls.remove(element, 'ps-active-y');
1464 i.scrollbarYHeight = 0;
1465 i.scrollbarYTop = 0;
1466 updateScroll(element, 'top', 0);
1470 },{"../lib/class":2,"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-scroll":20}],20:[function(require,module,exports){
1471 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1472 * Licensed under the MIT License
1476 var instances = require('./instances');
1478 var upEvent = document.createEvent('Event')
1479 , downEvent = document.createEvent('Event')
1480 , leftEvent = document.createEvent('Event')
1481 , rightEvent = document.createEvent('Event')
1482 , yEvent = document.createEvent('Event')
1483 , xEvent = document.createEvent('Event')
1484 , xStartEvent = document.createEvent('Event')
1485 , xEndEvent = document.createEvent('Event')
1486 , yStartEvent = document.createEvent('Event')
1487 , yEndEvent = document.createEvent('Event')
1491 upEvent.initEvent('ps-scroll-up', true, true);
1492 downEvent.initEvent('ps-scroll-down', true, true);
1493 leftEvent.initEvent('ps-scroll-left', true, true);
1494 rightEvent.initEvent('ps-scroll-right', true, true);
1495 yEvent.initEvent('ps-scroll-y', true, true);
1496 xEvent.initEvent('ps-scroll-x', true, true);
1497 xStartEvent.initEvent('ps-x-reach-start', true, true);
1498 xEndEvent.initEvent('ps-x-reach-end', true, true);
1499 yStartEvent.initEvent('ps-y-reach-start', true, true);
1500 yEndEvent.initEvent('ps-y-reach-end', true, true);
1502 module.exports = function (element, axis, value) {
1503 if (typeof element === 'undefined') {
1504 throw 'You must provide an element to the update-scroll function';
1507 if (typeof axis === 'undefined') {
1508 throw 'You must provide an axis to the update-scroll function';
1511 if (typeof value === 'undefined') {
1512 throw 'You must provide a value to the update-scroll function';
1515 if (axis === 'top' && value <= 0) {
1516 element.scrollTop = 0;
1517 element.dispatchEvent(yStartEvent);
1518 return; // don't allow negative scroll
1521 if (axis === 'left' && value <= 0) {
1522 element.scrollLeft = 0;
1523 element.dispatchEvent(xStartEvent);
1524 return; // don't allow negative scroll
1527 var i = instances.get(element);
1529 if (axis === 'top' && value >= i.contentHeight - i.containerHeight) {
1530 element.scrollTop = i.contentHeight - i.containerHeight;
1531 element.dispatchEvent(yEndEvent);
1532 return; // don't allow scroll past container
1535 if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
1536 element.scrollLeft = i.contentWidth - i.containerWidth;
1537 element.dispatchEvent(xEndEvent);
1538 return; // don't allow scroll past container
1542 lastTop = element.scrollTop;
1546 lastLeft = element.scrollLeft;
1549 if (axis === 'top' && value < lastTop) {
1550 element.dispatchEvent(upEvent);
1553 if (axis === 'top' && value > lastTop) {
1554 element.dispatchEvent(downEvent);
1557 if (axis === 'left' && value < lastLeft) {
1558 element.dispatchEvent(leftEvent);
1561 if (axis === 'left' && value > lastLeft) {
1562 element.dispatchEvent(rightEvent);
1565 if (axis === 'top') {
1566 element.scrollTop = lastTop = value;
1567 element.dispatchEvent(yEvent);
1570 if (axis === 'left') {
1571 element.scrollLeft = lastLeft = value;
1572 element.dispatchEvent(xEvent);
1577 },{"./instances":18}],21:[function(require,module,exports){
1578 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1579 * Licensed under the MIT License
1583 var d = require('../lib/dom')
1584 , h = require('../lib/helper')
1585 , instances = require('./instances')
1586 , updateGeometry = require('./update-geometry')
1587 , updateScroll = require('./update-scroll');
1589 module.exports = function (element) {
1590 var i = instances.get(element);
1596 // Recalcuate negative scrollLeft adjustment
1597 i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
1599 // Recalculate rail margins
1600 d.css(i.scrollbarXRail, 'display', 'block');
1601 d.css(i.scrollbarYRail, 'display', 'block');
1602 i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
1603 i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
1605 // Hide scrollbars not to affect scrollWidth and scrollHeight
1606 d.css(i.scrollbarXRail, 'display', 'none');
1607 d.css(i.scrollbarYRail, 'display', 'none');
1609 updateGeometry(element);
1611 // Update top/left scroll to trigger events
1612 updateScroll(element, 'top', element.scrollTop);
1613 updateScroll(element, 'left', element.scrollLeft);
1615 d.css(i.scrollbarXRail, 'display', '');
1616 d.css(i.scrollbarYRail, 'display', '');
1619 },{"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-geometry":19,"./update-scroll":20}]},{},[1]);