]> git.mxchange.org Git - friendica.git/blob - library/perfect-scrollbar/perfect-scrollbar.jquery.js
2bc3b2f939e7016f1634e39dc67b6d7c13b61257
[friendica.git] / library / perfect-scrollbar / perfect-scrollbar.jquery.js
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
5  * 
6  * Source: https://github.com/noraesae/perfect-scrollbar
7  */
8 'use strict';
9
10 var ps = require('../main')
11   , psInstances = require('../plugin/instances');
12
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;
20
21         if (!psInstances.get(this)) {
22           ps.initialize(this, settings);
23         }
24       } else {
25         // Unless, it may be a command.
26         var command = settingOrCommand;
27
28         if (command === 'update') {
29           ps.update(this);
30         } else if (command === 'destroy') {
31           ps.destroy(this);
32         }
33       }
34
35       return jQuery(this);
36     });
37   };
38 }
39
40 if (typeof define === 'function' && define.amd) {
41   // AMD. Register as an anonymous module.
42   define(['jquery'], mountJQuery);
43 } else {
44   var jq = window.jQuery ? window.jQuery : window.$;
45   if (typeof jq !== 'undefined') {
46     mountJQuery(jq);
47   }
48 }
49
50 module.exports = mountJQuery;
51
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
55  */
56 'use strict';
57
58 function oldAdd(element, className) {
59   var classes = element.className.split(' ');
60   if (classes.indexOf(className) < 0) {
61     classes.push(className);
62   }
63   element.className = classes.join(' ');
64 }
65
66 function oldRemove(element, className) {
67   var classes = element.className.split(' ');
68   var idx = classes.indexOf(className);
69   if (idx >= 0) {
70     classes.splice(idx, 1);
71   }
72   element.className = classes.join(' ');
73 }
74
75 exports.add = function (element, className) {
76   if (element.classList) {
77     element.classList.add(className);
78   } else {
79     oldAdd(element, className);
80   }
81 };
82
83 exports.remove = function (element, className) {
84   if (element.classList) {
85     element.classList.remove(className);
86   } else {
87     oldRemove(element, className);
88   }
89 };
90
91 exports.list = function (element) {
92   if (element.classList) {
93     return Array.prototype.slice.apply(element.classList);
94   } else {
95     return element.className.split(' ');
96   }
97 };
98
99 },{}],3:[function(require,module,exports){
100 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
101  * Licensed under the MIT License
102  */
103 'use strict';
104
105 var DOM = {};
106
107 DOM.e = function (tagName, className) {
108   var element = document.createElement(tagName);
109   element.className = className;
110   return element;
111 };
112
113 DOM.appendTo = function (child, parent) {
114   parent.appendChild(child);
115   return child;
116 };
117
118 function cssGet(element, styleName) {
119   return window.getComputedStyle(element)[styleName];
120 }
121
122 function cssSet(element, styleName, styleValue) {
123   if (typeof styleValue === 'number') {
124     styleValue = styleValue.toString() + 'px';
125   }
126   element.style[styleName] = styleValue;
127   return element;
128 }
129
130 function cssMultiSet(element, obj) {
131   for (var key in obj) {
132     var val = obj[key];
133     if (typeof val === 'number') {
134       val = val.toString() + 'px';
135     }
136     element.style[key] = val;
137   }
138   return element;
139 }
140
141 DOM.css = function (element, styleNameOrObject, styleValue) {
142   if (typeof styleNameOrObject === 'object') {
143     // multiple set with object
144     return cssMultiSet(element, styleNameOrObject);
145   } else {
146     if (typeof styleValue === 'undefined') {
147       return cssGet(element, styleNameOrObject);
148     } else {
149       return cssSet(element, styleNameOrObject, styleValue);
150     }
151   }
152 };
153
154 DOM.matches = function (element, query) {
155   if (typeof element.matches !== 'undefined') {
156     return element.matches(query);
157   } else {
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);
166     }
167   }
168 };
169
170 DOM.remove = function (element) {
171   if (typeof element.remove !== 'undefined') {
172     element.remove();
173   } else {
174     if (element.parentNode) {
175       element.parentNode.removeChild(element);
176     }
177   }
178 };
179
180 DOM.queryChildren = function (element, selector) {
181   return Array.prototype.filter.call(element.childNodes, function (child) {
182     return DOM.matches(child, selector);
183   });
184 };
185
186 module.exports = DOM;
187
188 },{}],4:[function(require,module,exports){
189 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
190  * Licensed under the MIT License
191  */
192 'use strict';
193
194 var EventElement = function (element) {
195   this.element = element;
196   this.events = {};
197 };
198
199 EventElement.prototype.bind = function (eventName, handler) {
200   if (typeof this.events[eventName] === 'undefined') {
201     this.events[eventName] = [];
202   }
203   this.events[eventName].push(handler);
204   this.element.addEventListener(eventName, handler, false);
205 };
206
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) {
211       return true;
212     }
213     this.element.removeEventListener(eventName, hdlr, false);
214     return false;
215   }, this);
216 };
217
218 EventElement.prototype.unbindAll = function () {
219   for (var name in this.events) {
220     this.unbind(name);
221   }
222 };
223
224 var EventManager = function () {
225   this.eventElements = [];
226 };
227
228 EventManager.prototype.eventElement = function (element) {
229   var ee = this.eventElements.filter(function (eventElement) {
230     return eventElement.element === element;
231   })[0];
232   if (typeof ee === 'undefined') {
233     ee = new EventElement(element);
234     this.eventElements.push(ee);
235   }
236   return ee;
237 };
238
239 EventManager.prototype.bind = function (element, eventName, handler) {
240   this.eventElement(element).bind(eventName, handler);
241 };
242
243 EventManager.prototype.unbind = function (element, eventName, handler) {
244   this.eventElement(element).unbind(eventName, handler);
245 };
246
247 EventManager.prototype.unbindAll = function () {
248   for (var i = 0; i < this.eventElements.length; i++) {
249     this.eventElements[i].unbindAll();
250   }
251 };
252
253 EventManager.prototype.once = function (element, eventName, handler) {
254   var ee = this.eventElement(element);
255   var onceHandler = function (e) {
256     ee.unbind(eventName, onceHandler);
257     handler(e);
258   };
259   ee.bind(eventName, onceHandler);
260 };
261
262 module.exports = EventManager;
263
264 },{}],5:[function(require,module,exports){
265 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
266  * Licensed under the MIT License
267  */
268 'use strict';
269
270 module.exports = (function () {
271   function s4() {
272     return Math.floor((1 + Math.random()) * 0x10000)
273                .toString(16)
274                .substring(1);
275   }
276   return function () {
277     return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
278            s4() + '-' + s4() + s4() + s4();
279   };
280 })();
281
282 },{}],6:[function(require,module,exports){
283 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
284  * Licensed under the MIT License
285  */
286 'use strict';
287
288 var cls = require('./class')
289   , d = require('./dom');
290
291 exports.toInt = function (x) {
292   return parseInt(x, 10) || 0;
293 };
294
295 exports.clone = function (obj) {
296   if (obj === null) {
297     return null;
298   } else if (typeof obj === 'object') {
299     var result = {};
300     for (var key in obj) {
301       result[key] = this.clone(obj[key]);
302     }
303     return result;
304   } else {
305     return obj;
306   }
307 };
308
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]);
313   }
314   return result;
315 };
316
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]");
322 };
323
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);
330     }
331   }
332 };
333
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'));
340 };
341
342 exports.startScrolling = function (element, axis) {
343   cls.add(element, 'ps-in-scrolling');
344   if (typeof axis !== 'undefined') {
345     cls.add(element, 'ps-' + axis);
346   } else {
347     cls.add(element, 'ps-x');
348     cls.add(element, 'ps-y');
349   }
350 };
351
352 exports.stopScrolling = function (element, axis) {
353   cls.remove(element, 'ps-in-scrolling');
354   if (typeof axis !== 'undefined') {
355     cls.remove(element, 'ps-' + axis);
356   } else {
357     cls.remove(element, 'ps-x');
358     cls.remove(element, 'ps-y');
359   }
360 };
361
362 exports.env = {
363   isWebKit: 'WebkitAppearance' in document.documentElement.style,
364   supportsTouch: (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch),
365   supportsIePointer: window.navigator.msMaxTouchPoints !== null
366 };
367
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
371  */
372 'use strict';
373
374 var destroy = require('./plugin/destroy')
375   , initialize = require('./plugin/initialize')
376   , update = require('./plugin/update');
377
378 module.exports = {
379   initialize: initialize,
380   update: update,
381   destroy: destroy
382 };
383
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
387  */
388 'use strict';
389
390 module.exports = {
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,
400   useKeyboard: true,
401   useSelectionScroll: false,
402   wheelPropagation: false,
403   wheelSpeed: 1
404 };
405
406 },{}],9:[function(require,module,exports){
407 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
408  * Licensed under the MIT License
409  */
410 'use strict';
411
412 var d = require('../lib/dom')
413   , h = require('../lib/helper')
414   , instances = require('./instances');
415
416 module.exports = function (element) {
417   var i = instances.get(element);
418
419   if (!i) {
420     return;
421   }
422
423   i.event.unbindAll();
424   d.remove(i.scrollbarX);
425   d.remove(i.scrollbarY);
426   d.remove(i.scrollbarXRail);
427   d.remove(i.scrollbarYRail);
428   h.removePsClasses(element);
429
430   instances.remove(element);
431 };
432
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
436  */
437 'use strict';
438
439 var h = require('../../lib/helper')
440   , instances = require('../instances')
441   , updateGeometry = require('../update-geometry')
442   , updateScroll = require('../update-scroll');
443
444 function bindClickRailHandler(element, i) {
445   function pageOffset(el) {
446     return el.getBoundingClientRect();
447   }
448   var stopPropagation = window.Event.prototype.stopPropagation.bind;
449
450   if (i.settings.stopPropagationOnClick) {
451     i.event.bind(i.scrollbarY, 'click', stopPropagation);
452   }
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;
458
459     if (positionRatio < 0) {
460       positionRatio = 0;
461     } else if (positionRatio > 1) {
462       positionRatio = 1;
463     }
464
465     updateScroll(element, 'top', (i.contentHeight - i.containerHeight) * positionRatio);
466     updateGeometry(element);
467
468     e.stopPropagation();
469   });
470
471   if (i.settings.stopPropagationOnClick) {
472     i.event.bind(i.scrollbarX, 'click', stopPropagation);
473   }
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;
479
480     if (positionRatio < 0) {
481       positionRatio = 0;
482     } else if (positionRatio > 1) {
483       positionRatio = 1;
484     }
485
486     updateScroll(element, 'left', ((i.contentWidth - i.containerWidth) * positionRatio) - i.negativeScrollAdjustment);
487     updateGeometry(element);
488
489     e.stopPropagation();
490   });
491 }
492
493 module.exports = function (element) {
494   var i = instances.get(element);
495   bindClickRailHandler(element, i);
496 };
497
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
501  */
502 'use strict';
503
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');
509
510 function bindMouseScrollXHandler(element, i) {
511   var currentLeft = null;
512   var currentPageX = null;
513
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));
517
518     if (newLeft < 0) {
519       i.scrollbarXLeft = 0;
520     } else if (newLeft > maxLeft) {
521       i.scrollbarXLeft = maxLeft;
522     } else {
523       i.scrollbarXLeft = newLeft;
524     }
525
526     var scrollLeft = h.toInt(i.scrollbarXLeft * (i.contentWidth - i.containerWidth) / (i.containerWidth - (i.railXRatio * i.scrollbarXWidth))) - i.negativeScrollAdjustment;
527     updateScroll(element, 'left', scrollLeft);
528   }
529
530   var mouseMoveHandler = function (e) {
531     updateScrollLeft(e.pageX - currentPageX);
532     updateGeometry(element);
533     e.stopPropagation();
534     e.preventDefault();
535   };
536
537   var mouseUpHandler = function () {
538     h.stopScrolling(element, 'x');
539     i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
540   };
541
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');
546
547     i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
548     i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
549
550     e.stopPropagation();
551     e.preventDefault();
552   });
553 }
554
555 function bindMouseScrollYHandler(element, i) {
556   var currentTop = null;
557   var currentPageY = null;
558
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));
562
563     if (newTop < 0) {
564       i.scrollbarYTop = 0;
565     } else if (newTop > maxTop) {
566       i.scrollbarYTop = maxTop;
567     } else {
568       i.scrollbarYTop = newTop;
569     }
570
571     var scrollTop = h.toInt(i.scrollbarYTop * (i.contentHeight - i.containerHeight) / (i.containerHeight - (i.railYRatio * i.scrollbarYHeight)));
572     updateScroll(element, 'top', scrollTop);
573   }
574
575   var mouseMoveHandler = function (e) {
576     updateScrollTop(e.pageY - currentPageY);
577     updateGeometry(element);
578     e.stopPropagation();
579     e.preventDefault();
580   };
581
582   var mouseUpHandler = function () {
583     h.stopScrolling(element, 'y');
584     i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
585   };
586
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');
591
592     i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
593     i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
594
595     e.stopPropagation();
596     e.preventDefault();
597   });
598 }
599
600 module.exports = function (element) {
601   var i = instances.get(element);
602   bindMouseScrollXHandler(element, i);
603   bindMouseScrollYHandler(element, i);
604 };
605
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
609  */
610 'use strict';
611
612 var h = require('../../lib/helper')
613   , instances = require('../instances')
614   , updateGeometry = require('../update-geometry')
615   , updateScroll = require('../update-scroll');
616
617 function bindKeyboardHandler(element, i) {
618   var hovered = false;
619   i.event.bind(element, 'mouseenter', function () {
620     hovered = true;
621   });
622   i.event.bind(element, 'mouseleave', function () {
623     hovered = false;
624   });
625
626   var shouldPrevent = false;
627   function shouldPreventDefault(deltaX, deltaY) {
628     var scrollTop = element.scrollTop;
629     if (deltaX === 0) {
630       if (!i.scrollbarYActive) {
631         return false;
632       }
633       if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
634         return !i.settings.wheelPropagation;
635       }
636     }
637
638     var scrollLeft = element.scrollLeft;
639     if (deltaY === 0) {
640       if (!i.scrollbarXActive) {
641         return false;
642       }
643       if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
644         return !i.settings.wheelPropagation;
645       }
646     }
647     return true;
648   }
649
650   i.event.bind(i.ownerDocument, 'keydown', function (e) {
651     if (e.isDefaultPrevented && e.isDefaultPrevented()) {
652       return;
653     }
654
655     if (!hovered) {
656       return;
657     }
658
659     var activeElement = document.activeElement ? document.activeElement : i.ownerDocument.activeElement;
660     if (activeElement) {
661       // go deeper if element is a webcomponent
662       while (activeElement.shadowRoot) {
663         activeElement = activeElement.shadowRoot.activeElement;
664       }
665       if (h.isEditable(activeElement)) {
666         return;
667       }
668     }
669
670     var deltaX = 0;
671     var deltaY = 0;
672
673     switch (e.which) {
674     case 37: // left
675       deltaX = -30;
676       break;
677     case 38: // up
678       deltaY = 30;
679       break;
680     case 39: // right
681       deltaX = 30;
682       break;
683     case 40: // down
684       deltaY = -30;
685       break;
686     case 33: // page up
687       deltaY = 90;
688       break;
689     case 32: // space bar
690       if (e.shiftKey) {
691         deltaY = 90;
692       } else {
693         deltaY = -90;
694       }
695       break;
696     case 34: // page down
697       deltaY = -90;
698       break;
699     case 35: // end
700       if (e.ctrlKey) {
701         deltaY = -i.contentHeight;
702       } else {
703         deltaY = -i.containerHeight;
704       }
705       break;
706     case 36: // home
707       if (e.ctrlKey) {
708         deltaY = element.scrollTop;
709       } else {
710         deltaY = i.containerHeight;
711       }
712       break;
713     default:
714       return;
715     }
716
717     updateScroll(element, 'top', element.scrollTop - deltaY);
718     updateScroll(element, 'left', element.scrollLeft + deltaX);
719     updateGeometry(element);
720
721     shouldPrevent = shouldPreventDefault(deltaX, deltaY);
722     if (shouldPrevent) {
723       e.preventDefault();
724     }
725   });
726 }
727
728 module.exports = function (element) {
729   var i = instances.get(element);
730   bindKeyboardHandler(element, i);
731 };
732
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
736  */
737 'use strict';
738
739 var instances = require('../instances')
740   , updateGeometry = require('../update-geometry')
741   , updateScroll = require('../update-scroll');
742
743 function bindMouseWheelHandler(element, i) {
744   var shouldPrevent = false;
745
746   function shouldPreventDefault(deltaX, deltaY) {
747     var scrollTop = element.scrollTop;
748     if (deltaX === 0) {
749       if (!i.scrollbarYActive) {
750         return false;
751       }
752       if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
753         return !i.settings.wheelPropagation;
754       }
755     }
756
757     var scrollLeft = element.scrollLeft;
758     if (deltaY === 0) {
759       if (!i.scrollbarXActive) {
760         return false;
761       }
762       if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
763         return !i.settings.wheelPropagation;
764       }
765     }
766     return true;
767   }
768
769   function getDeltaFromEvent(e) {
770     var deltaX = e.deltaX;
771     var deltaY = -1 * e.deltaY;
772
773     if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
774       // OS X Safari
775       deltaX = -1 * e.wheelDeltaX / 6;
776       deltaY = e.wheelDeltaY / 6;
777     }
778
779     if (e.deltaMode && e.deltaMode === 1) {
780       // Firefox in deltaMode 1: Line scrolling
781       deltaX *= 10;
782       deltaY *= 10;
783     }
784
785     if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
786       // IE in some mouse drivers
787       deltaX = 0;
788       deltaY = e.wheelDelta;
789     }
790
791     return [deltaX, deltaY];
792   }
793
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)) {
801           return true;
802         }
803       }
804       var maxScrollLeft = hoveredTextarea.scrollLeft - hoveredTextarea.clientWidth;
805       if (maxScrollLeft > 0) {
806         if (!(hoveredTextarea.scrollLeft === 0 && deltaX < 0) &&
807             !(hoveredTextarea.scrollLeft === maxScrollLeft && deltaX > 0)) {
808           return true;
809         }
810       }
811     }
812     return false;
813   }
814
815   function mousewheelHandler(e) {
816     var delta = getDeltaFromEvent(e);
817
818     var deltaX = delta[0];
819     var deltaY = delta[1];
820
821     if (shouldBeConsumedByTextarea(deltaX, deltaY)) {
822       return;
823     }
824
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
834       if (deltaY) {
835         updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
836       } else {
837         updateScroll(element, 'top', element.scrollTop + (deltaX * i.settings.wheelSpeed));
838       }
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
843       if (deltaX) {
844         updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
845       } else {
846         updateScroll(element, 'left', element.scrollLeft - (deltaY * i.settings.wheelSpeed));
847       }
848       shouldPrevent = true;
849     }
850
851     updateGeometry(element);
852
853     shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
854     if (shouldPrevent) {
855       e.stopPropagation();
856       e.preventDefault();
857     }
858   }
859
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);
864   }
865 }
866
867 module.exports = function (element) {
868   var i = instances.get(element);
869   bindMouseWheelHandler(element, i);
870 };
871
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
875  */
876 'use strict';
877
878 var instances = require('../instances')
879   , updateGeometry = require('../update-geometry');
880
881 function bindNativeScrollHandler(element, i) {
882   i.event.bind(element, 'scroll', function () {
883     updateGeometry(element);
884   });
885 }
886
887 module.exports = function (element) {
888   var i = instances.get(element);
889   bindNativeScrollHandler(element, i);
890 };
891
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
895  */
896 'use strict';
897
898 var h = require('../../lib/helper')
899   , instances = require('../instances')
900   , updateGeometry = require('../update-geometry')
901   , updateScroll = require('../update-scroll');
902
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) {
908       return null;
909     } else {
910       return selection.getRangeAt(0).commonAncestorContainer;
911     }
912   }
913
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);
921           return;
922         }
923
924         updateScroll(element, 'top', element.scrollTop + scrollDiff.top);
925         updateScroll(element, 'left', element.scrollLeft + scrollDiff.left);
926         updateGeometry(element);
927       }, 50); // every .1 sec
928     }
929   }
930   function stopScrolling() {
931     if (scrollingLoop) {
932       clearInterval(scrollingLoop);
933       scrollingLoop = null;
934     }
935     h.stopScrolling(element);
936   }
937
938   var isSelected = false;
939   i.event.bind(i.ownerDocument, 'selectionchange', function () {
940     if (element.contains(getRangeNode())) {
941       isSelected = true;
942     } else {
943       isSelected = false;
944       stopScrolling();
945     }
946   });
947   i.event.bind(window, 'mouseup', function () {
948     if (isSelected) {
949       isSelected = false;
950       stopScrolling();
951     }
952   });
953
954   i.event.bind(window, 'mousemove', function (e) {
955     if (isSelected) {
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
962       };
963
964       if (mousePosition.x < containerGeometry.left + 3) {
965         scrollDiff.left = -5;
966         h.startScrolling(element, 'x');
967       } else if (mousePosition.x > containerGeometry.right - 3) {
968         scrollDiff.left = 5;
969         h.startScrolling(element, 'x');
970       } else {
971         scrollDiff.left = 0;
972       }
973
974       if (mousePosition.y < containerGeometry.top + 3) {
975         if (containerGeometry.top + 3 - mousePosition.y < 5) {
976           scrollDiff.top = -5;
977         } else {
978           scrollDiff.top = -20;
979         }
980         h.startScrolling(element, 'y');
981       } else if (mousePosition.y > containerGeometry.bottom - 3) {
982         if (mousePosition.y - containerGeometry.bottom + 3 < 5) {
983           scrollDiff.top = 5;
984         } else {
985           scrollDiff.top = 20;
986         }
987         h.startScrolling(element, 'y');
988       } else {
989         scrollDiff.top = 0;
990       }
991
992       if (scrollDiff.top === 0 && scrollDiff.left === 0) {
993         stopScrolling();
994       } else {
995         startScrolling();
996       }
997     }
998   });
999 }
1000
1001 module.exports = function (element) {
1002   var i = instances.get(element);
1003   bindSelectionHandler(element, i);
1004 };
1005
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
1009  */
1010 'use strict';
1011
1012 var instances = require('../instances')
1013   , updateGeometry = require('../update-geometry')
1014   , updateScroll = require('../update-scroll');
1015
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);
1022
1023     if (magnitudeY > magnitudeX) {
1024       // user is perhaps trying to swipe up/down the page
1025
1026       if (((deltaY < 0) && (scrollTop === i.contentHeight - i.containerHeight)) ||
1027           ((deltaY > 0) && (scrollTop === 0))) {
1028         return !i.settings.swipePropagation;
1029       }
1030     } else if (magnitudeX > magnitudeY) {
1031       // user is perhaps trying to swipe left/right across the page
1032
1033       if (((deltaX < 0) && (scrollLeft === i.contentWidth - i.containerWidth)) ||
1034           ((deltaX > 0) && (scrollLeft === 0))) {
1035         return !i.settings.swipePropagation;
1036       }
1037     }
1038
1039     return true;
1040   }
1041
1042   function applyTouchMove(differenceX, differenceY) {
1043     updateScroll(element, 'top', element.scrollTop - differenceY);
1044     updateScroll(element, 'left', element.scrollLeft - differenceX);
1045
1046     updateGeometry(element);
1047   }
1048
1049   var startOffset = {};
1050   var startTime = 0;
1051   var speed = {};
1052   var easingLoop = null;
1053   var inGlobalTouch = false;
1054   var inLocalTouch = false;
1055
1056   function globalTouchStart() {
1057     inGlobalTouch = true;
1058   }
1059   function globalTouchEnd() {
1060     inGlobalTouch = false;
1061   }
1062
1063   function getTouch(e) {
1064     if (e.targetTouches) {
1065       return e.targetTouches[0];
1066     } else {
1067       // Maybe IE pointer
1068       return e;
1069     }
1070   }
1071   function shouldHandle(e) {
1072     if (e.targetTouches && e.targetTouches.length === 1) {
1073       return true;
1074     }
1075     if (e.pointerType && e.pointerType !== 'mouse' && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
1076       return true;
1077     }
1078     return false;
1079   }
1080   function touchStart(e) {
1081     if (shouldHandle(e)) {
1082       inLocalTouch = true;
1083
1084       var touch = getTouch(e);
1085
1086       startOffset.pageX = touch.pageX;
1087       startOffset.pageY = touch.pageY;
1088
1089       startTime = (new Date()).getTime();
1090
1091       if (easingLoop !== null) {
1092         clearInterval(easingLoop);
1093       }
1094
1095       e.stopPropagation();
1096     }
1097   }
1098   function touchMove(e) {
1099     if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
1100       var touch = getTouch(e);
1101
1102       var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
1103
1104       var differenceX = currentOffset.pageX - startOffset.pageX;
1105       var differenceY = currentOffset.pageY - startOffset.pageY;
1106
1107       applyTouchMove(differenceX, differenceY);
1108       startOffset = currentOffset;
1109
1110       var currentTime = (new Date()).getTime();
1111
1112       var timeGap = currentTime - startTime;
1113       if (timeGap > 0) {
1114         speed.x = differenceX / timeGap;
1115         speed.y = differenceY / timeGap;
1116         startTime = currentTime;
1117       }
1118
1119       if (shouldPreventDefault(differenceX, differenceY)) {
1120         e.stopPropagation();
1121         e.preventDefault();
1122       }
1123     }
1124   }
1125   function touchEnd() {
1126     if (!inGlobalTouch && inLocalTouch) {
1127       inLocalTouch = false;
1128
1129       clearInterval(easingLoop);
1130       easingLoop = setInterval(function () {
1131         if (!instances.get(element)) {
1132           clearInterval(easingLoop);
1133           return;
1134         }
1135
1136         if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
1137           clearInterval(easingLoop);
1138           return;
1139         }
1140
1141         applyTouchMove(speed.x * 30, speed.y * 30);
1142
1143         speed.x *= 0.8;
1144         speed.y *= 0.8;
1145       }, 10);
1146     }
1147   }
1148
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);
1155   }
1156
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);
1170     }
1171   }
1172 }
1173
1174 module.exports = function (element, supportsTouch, supportsIePointer) {
1175   var i = instances.get(element);
1176   bindTouchHandler(element, i, supportsTouch, supportsIePointer);
1177 };
1178
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
1182  */
1183 'use strict';
1184
1185 var cls = require('../lib/class')
1186   , h = require('../lib/helper')
1187   , instances = require('./instances')
1188   , updateGeometry = require('./update-geometry');
1189
1190 // Handlers
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');
1198
1199 module.exports = function (element, userSettings) {
1200   userSettings = typeof userSettings === 'object' ? userSettings : {};
1201
1202   cls.add(element, 'ps-container');
1203
1204   // Create a plugin instance.
1205   var i = instances.add(element);
1206
1207   i.settings = h.extend(i.settings, userSettings);
1208
1209   clickRailHandler(element);
1210   dragScrollbarHandler(element);
1211   mouseWheelHandler(element);
1212   nativeScrollHandler(element);
1213
1214   if (i.settings.useSelectionScroll) {
1215     selectionHandler(element);
1216   }
1217
1218   if (h.env.supportsTouch || h.env.supportsIePointer) {
1219     touchHandler(element, h.env.supportsTouch, h.env.supportsIePointer);
1220   }
1221   if (i.settings.useKeyboard) {
1222     keyboardHandler(element);
1223   }
1224
1225   updateGeometry(element);
1226 };
1227
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
1231  */
1232 'use strict';
1233
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');
1239
1240 var instances = {};
1241
1242 function Instance(element) {
1243   var i = this;
1244
1245   i.settings = h.clone(defaultSettings);
1246   i.containerWidth = null;
1247   i.containerHeight = null;
1248   i.contentWidth = null;
1249   i.contentHeight = null;
1250
1251   i.isRtl = d.css(element, 'direction') === "rtl";
1252   i.isNegativeScroll = (function () {
1253     var originalScrollLeft = element.scrollLeft;
1254     var result = null;
1255     element.scrollLeft = -1;
1256     result = element.scrollLeft < 0;
1257     element.scrollLeft = originalScrollLeft;
1258     return result;
1259   })();
1260   i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
1261   i.event = new EventManager();
1262   i.ownerDocument = element.ownerDocument || document;
1263
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;
1280
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;
1297 }
1298
1299 function getId(element) {
1300   if (typeof element.dataset === 'undefined') {
1301     return element.getAttribute('data-ps-id');
1302   } else {
1303     return element.dataset.psId;
1304   }
1305 }
1306
1307 function setId(element, id) {
1308   if (typeof element.dataset === 'undefined') {
1309     element.setAttribute('data-ps-id', id);
1310   } else {
1311     element.dataset.psId = id;
1312   }
1313 }
1314
1315 function removeId(element) {
1316   if (typeof element.dataset === 'undefined') {
1317     element.removeAttribute('data-ps-id');
1318   } else {
1319     delete element.dataset.psId;
1320   }
1321 }
1322
1323 exports.add = function (element) {
1324   var newId = guid();
1325   setId(element, newId);
1326   instances[newId] = new Instance(element);
1327   return instances[newId];
1328 };
1329
1330 exports.remove = function (element) {
1331   delete instances[getId(element)];
1332   removeId(element);
1333 };
1334
1335 exports.get = function (element) {
1336   return instances[getId(element)];
1337 };
1338
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
1342  */
1343 'use strict';
1344
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');
1350
1351 function getThumbSize(i, thumbSize) {
1352   if (i.settings.minScrollbarLength) {
1353     thumbSize = Math.max(thumbSize, i.settings.minScrollbarLength);
1354   }
1355   if (i.settings.maxScrollbarLength) {
1356     thumbSize = Math.min(thumbSize, i.settings.maxScrollbarLength);
1357   }
1358   return thumbSize;
1359 }
1360
1361 function updateCss(element, i) {
1362   var xRailOffset = {width: i.railXWidth};
1363   if (i.isRtl) {
1364     xRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth - i.contentWidth;
1365   } else {
1366     xRailOffset.left = element.scrollLeft;
1367   }
1368   if (i.isScrollbarXUsingBottom) {
1369     xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
1370   } else {
1371     xRailOffset.top = i.scrollbarXTop + element.scrollTop;
1372   }
1373   d.css(i.scrollbarXRail, xRailOffset);
1374
1375   var yRailOffset = {top: element.scrollTop, height: i.railYHeight};
1376   if (i.isScrollbarYUsingRight) {
1377     if (i.isRtl) {
1378       yRailOffset.right = i.contentWidth - (i.negativeScrollAdjustment + element.scrollLeft) - i.scrollbarYRight - i.scrollbarYOuterWidth;
1379     } else {
1380       yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
1381     }
1382   } else {
1383     if (i.isRtl) {
1384       yRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth * 2 - i.contentWidth - i.scrollbarYLeft - i.scrollbarYOuterWidth;
1385     } else {
1386       yRailOffset.left = i.scrollbarYLeft + element.scrollLeft;
1387     }
1388   }
1389   d.css(i.scrollbarYRail, yRailOffset);
1390
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});
1393 }
1394
1395 module.exports = function (element) {
1396   var i = instances.get(element);
1397
1398   i.containerWidth = element.clientWidth;
1399   i.containerHeight = element.clientHeight;
1400   i.contentWidth = element.scrollWidth;
1401   i.contentHeight = element.scrollHeight;
1402
1403   var existingRails;
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) {
1408         d.remove(rail);
1409       });
1410     }
1411     d.appendTo(i.scrollbarXRail, element);
1412   }
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) {
1417         d.remove(rail);
1418       });
1419     }
1420     d.appendTo(i.scrollbarYRail, element);
1421   }
1422
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));
1429   } else {
1430     i.scrollbarXActive = false;
1431   }
1432
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));
1439   } else {
1440     i.scrollbarYActive = false;
1441   }
1442
1443   if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
1444     i.scrollbarXLeft = i.railXWidth - i.scrollbarXWidth;
1445   }
1446   if (i.scrollbarYTop >= i.railYHeight - i.scrollbarYHeight) {
1447     i.scrollbarYTop = i.railYHeight - i.scrollbarYHeight;
1448   }
1449
1450   updateCss(element, i);
1451
1452   if (i.scrollbarXActive) {
1453     cls.add(element, 'ps-active-x');
1454   } else {
1455     cls.remove(element, 'ps-active-x');
1456     i.scrollbarXWidth = 0;
1457     i.scrollbarXLeft = 0;
1458     updateScroll(element, 'left', 0);
1459   }
1460   if (i.scrollbarYActive) {
1461     cls.add(element, 'ps-active-y');
1462   } else {
1463     cls.remove(element, 'ps-active-y');
1464     i.scrollbarYHeight = 0;
1465     i.scrollbarYTop = 0;
1466     updateScroll(element, 'top', 0);
1467   }
1468 };
1469
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
1473  */
1474 'use strict';
1475
1476 var instances = require('./instances');
1477
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')
1488   , lastTop
1489   , lastLeft;
1490
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);
1501
1502 module.exports = function (element, axis, value) {
1503   if (typeof element === 'undefined') {
1504     throw 'You must provide an element to the update-scroll function';
1505   }
1506
1507   if (typeof axis === 'undefined') {
1508     throw 'You must provide an axis to the update-scroll function';
1509   }
1510
1511   if (typeof value === 'undefined') {
1512     throw 'You must provide a value to the update-scroll function';
1513   }
1514
1515   if (axis === 'top' && value <= 0) {
1516     element.scrollTop = 0;
1517     element.dispatchEvent(yStartEvent);
1518     return; // don't allow negative scroll
1519   }
1520
1521   if (axis === 'left' && value <= 0) {
1522     element.scrollLeft = 0;
1523     element.dispatchEvent(xStartEvent);
1524     return; // don't allow negative scroll
1525   }
1526
1527   var i = instances.get(element);
1528
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
1533   }
1534
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
1539   }
1540
1541   if (!lastTop) {
1542     lastTop = element.scrollTop;
1543   }
1544
1545   if (!lastLeft) {
1546     lastLeft = element.scrollLeft;
1547   }
1548
1549   if (axis === 'top' && value < lastTop) {
1550     element.dispatchEvent(upEvent);
1551   }
1552
1553   if (axis === 'top' && value > lastTop) {
1554     element.dispatchEvent(downEvent);
1555   }
1556
1557   if (axis === 'left' && value < lastLeft) {
1558     element.dispatchEvent(leftEvent);
1559   }
1560
1561   if (axis === 'left' && value > lastLeft) {
1562     element.dispatchEvent(rightEvent);
1563   }
1564
1565   if (axis === 'top') {
1566     element.scrollTop = lastTop = value;
1567     element.dispatchEvent(yEvent);
1568   }
1569
1570   if (axis === 'left') {
1571     element.scrollLeft = lastLeft = value;
1572     element.dispatchEvent(xEvent);
1573   }
1574
1575 };
1576
1577 },{"./instances":18}],21:[function(require,module,exports){
1578 /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
1579  * Licensed under the MIT License
1580  */
1581 'use strict';
1582
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');
1588
1589 module.exports = function (element) {
1590   var i = instances.get(element);
1591
1592   if (!i) {
1593     return;
1594   }
1595
1596   // Recalcuate negative scrollLeft adjustment
1597   i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
1598
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'));
1604
1605   // Hide scrollbars not to affect scrollWidth and scrollHeight
1606   d.css(i.scrollbarXRail, 'display', 'none');
1607   d.css(i.scrollbarYRail, 'display', 'none');
1608
1609   updateGeometry(element);
1610
1611   // Update top/left scroll to trigger events
1612   updateScroll(element, 'top', element.scrollTop);
1613   updateScroll(element, 'left', element.scrollLeft);
1614
1615   d.css(i.scrollbarXRail, 'display', '');
1616   d.css(i.scrollbarYRail, 'display', '');
1617 };
1618
1619 },{"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-geometry":19,"./update-scroll":20}]},{},[1]);