perfect-scrollbar v0.6.10

https://github.com/noraesae/perfect-scrollbar

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/21144/134925/perfect-scrollbar%20v0610.js

  1. /* perfect-scrollbar v0.6.10 */
  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. 'use strict';
  4.  
  5. var ps = require('../main')
  6. , psInstances = require('../plugin/instances');
  7.  
  8. function mountJQuery(jQuery) {
  9. jQuery.fn.perfectScrollbar = function (settingOrCommand) {
  10. return this.each(function () {
  11. if (typeof settingOrCommand === 'object' ||
  12. typeof settingOrCommand === 'undefined') {
  13. // If it's an object or none, initialize.
  14. var settings = settingOrCommand;
  15.  
  16. if (!psInstances.get(this)) {
  17. ps.initialize(this, settings);
  18. }
  19. } else {
  20. // Unless, it may be a command.
  21. var command = settingOrCommand;
  22.  
  23. if (command === 'update') {
  24. ps.update(this);
  25. } else if (command === 'destroy') {
  26. ps.destroy(this);
  27. }
  28. }
  29.  
  30. return jQuery(this);
  31. });
  32. };
  33. }
  34.  
  35. if (typeof define === 'function' && define.amd) {
  36. // AMD. Register as an anonymous module.
  37. define(['jquery'], mountJQuery);
  38. } else {
  39. var jq = window.jQuery ? window.jQuery : window.$;
  40. if (typeof jq !== 'undefined') {
  41. mountJQuery(jq);
  42. }
  43. }
  44.  
  45. module.exports = mountJQuery;
  46.  
  47. },{"../main":7,"../plugin/instances":18}],2:[function(require,module,exports){
  48. 'use strict';
  49.  
  50. function oldAdd(element, className) {
  51. var classes = element.className.split(' ');
  52. if (classes.indexOf(className) < 0) {
  53. classes.push(className);
  54. }
  55. element.className = classes.join(' ');
  56. }
  57.  
  58. function oldRemove(element, className) {
  59. var classes = element.className.split(' ');
  60. var idx = classes.indexOf(className);
  61. if (idx >= 0) {
  62. classes.splice(idx, 1);
  63. }
  64. element.className = classes.join(' ');
  65. }
  66.  
  67. exports.add = function (element, className) {
  68. if (element.classList) {
  69. element.classList.add(className);
  70. } else {
  71. oldAdd(element, className);
  72. }
  73. };
  74.  
  75. exports.remove = function (element, className) {
  76. if (element.classList) {
  77. element.classList.remove(className);
  78. } else {
  79. oldRemove(element, className);
  80. }
  81. };
  82.  
  83. exports.list = function (element) {
  84. if (element.classList) {
  85. return Array.prototype.slice.apply(element.classList);
  86. } else {
  87. return element.className.split(' ');
  88. }
  89. };
  90.  
  91. },{}],3:[function(require,module,exports){
  92. 'use strict';
  93.  
  94. var DOM = {};
  95.  
  96. DOM.e = function (tagName, className) {
  97. var element = document.createElement(tagName);
  98. element.className = className;
  99. return element;
  100. };
  101.  
  102. DOM.appendTo = function (child, parent) {
  103. parent.appendChild(child);
  104. return child;
  105. };
  106.  
  107. function cssGet(element, styleName) {
  108. return window.getComputedStyle(element)[styleName];
  109. }
  110.  
  111. function cssSet(element, styleName, styleValue) {
  112. if (typeof styleValue === 'number') {
  113. styleValue = styleValue.toString() + 'px';
  114. }
  115. element.style[styleName] = styleValue;
  116. return element;
  117. }
  118.  
  119. function cssMultiSet(element, obj) {
  120. for (var key in obj) {
  121. var val = obj[key];
  122. if (typeof val === 'number') {
  123. val = val.toString() + 'px';
  124. }
  125. element.style[key] = val;
  126. }
  127. return element;
  128. }
  129.  
  130. DOM.css = function (element, styleNameOrObject, styleValue) {
  131. if (typeof styleNameOrObject === 'object') {
  132. // multiple set with object
  133. return cssMultiSet(element, styleNameOrObject);
  134. } else {
  135. if (typeof styleValue === 'undefined') {
  136. return cssGet(element, styleNameOrObject);
  137. } else {
  138. return cssSet(element, styleNameOrObject, styleValue);
  139. }
  140. }
  141. };
  142.  
  143. DOM.matches = function (element, query) {
  144. if (typeof element.matches !== 'undefined') {
  145. return element.matches(query);
  146. } else {
  147. if (typeof element.matchesSelector !== 'undefined') {
  148. return element.matchesSelector(query);
  149. } else if (typeof element.webkitMatchesSelector !== 'undefined') {
  150. return element.webkitMatchesSelector(query);
  151. } else if (typeof element.mozMatchesSelector !== 'undefined') {
  152. return element.mozMatchesSelector(query);
  153. } else if (typeof element.msMatchesSelector !== 'undefined') {
  154. return element.msMatchesSelector(query);
  155. }
  156. }
  157. };
  158.  
  159. DOM.remove = function (element) {
  160. if (typeof element.remove !== 'undefined') {
  161. element.remove();
  162. } else {
  163. if (element.parentNode) {
  164. element.parentNode.removeChild(element);
  165. }
  166. }
  167. };
  168.  
  169. DOM.queryChildren = function (element, selector) {
  170. return Array.prototype.filter.call(element.childNodes, function (child) {
  171. return DOM.matches(child, selector);
  172. });
  173. };
  174.  
  175. module.exports = DOM;
  176.  
  177. },{}],4:[function(require,module,exports){
  178. 'use strict';
  179.  
  180. var EventElement = function (element) {
  181. this.element = element;
  182. this.events = {};
  183. };
  184.  
  185. EventElement.prototype.bind = function (eventName, handler) {
  186. if (typeof this.events[eventName] === 'undefined') {
  187. this.events[eventName] = [];
  188. }
  189. this.events[eventName].push(handler);
  190. this.element.addEventListener(eventName, handler, false);
  191. };
  192.  
  193. EventElement.prototype.unbind = function (eventName, handler) {
  194. var isHandlerProvided = (typeof handler !== 'undefined');
  195. this.events[eventName] = this.events[eventName].filter(function (hdlr) {
  196. if (isHandlerProvided && hdlr !== handler) {
  197. return true;
  198. }
  199. this.element.removeEventListener(eventName, hdlr, false);
  200. return false;
  201. }, this);
  202. };
  203.  
  204. EventElement.prototype.unbindAll = function () {
  205. for (var name in this.events) {
  206. this.unbind(name);
  207. }
  208. };
  209.  
  210. var EventManager = function () {
  211. this.eventElements = [];
  212. };
  213.  
  214. EventManager.prototype.eventElement = function (element) {
  215. var ee = this.eventElements.filter(function (eventElement) {
  216. return eventElement.element === element;
  217. })[0];
  218. if (typeof ee === 'undefined') {
  219. ee = new EventElement(element);
  220. this.eventElements.push(ee);
  221. }
  222. return ee;
  223. };
  224.  
  225. EventManager.prototype.bind = function (element, eventName, handler) {
  226. this.eventElement(element).bind(eventName, handler);
  227. };
  228.  
  229. EventManager.prototype.unbind = function (element, eventName, handler) {
  230. this.eventElement(element).unbind(eventName, handler);
  231. };
  232.  
  233. EventManager.prototype.unbindAll = function () {
  234. for (var i = 0; i < this.eventElements.length; i++) {
  235. this.eventElements[i].unbindAll();
  236. }
  237. };
  238.  
  239. EventManager.prototype.once = function (element, eventName, handler) {
  240. var ee = this.eventElement(element);
  241. var onceHandler = function (e) {
  242. ee.unbind(eventName, onceHandler);
  243. handler(e);
  244. };
  245. ee.bind(eventName, onceHandler);
  246. };
  247.  
  248. module.exports = EventManager;
  249.  
  250. },{}],5:[function(require,module,exports){
  251. 'use strict';
  252.  
  253. module.exports = (function () {
  254. function s4() {
  255. return Math.floor((1 + Math.random()) * 0x10000)
  256. .toString(16)
  257. .substring(1);
  258. }
  259. return function () {
  260. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  261. s4() + '-' + s4() + s4() + s4();
  262. };
  263. })();
  264.  
  265. },{}],6:[function(require,module,exports){
  266. 'use strict';
  267.  
  268. var cls = require('./class')
  269. , d = require('./dom');
  270.  
  271. exports.toInt = function (x) {
  272. return parseInt(x, 10) || 0;
  273. };
  274.  
  275. exports.clone = function (obj) {
  276. if (obj === null) {
  277. return null;
  278. } else if (typeof obj === 'object') {
  279. var result = {};
  280. for (var key in obj) {
  281. result[key] = this.clone(obj[key]);
  282. }
  283. return result;
  284. } else {
  285. return obj;
  286. }
  287. };
  288.  
  289. exports.extend = function (original, source) {
  290. var result = this.clone(original);
  291. for (var key in source) {
  292. result[key] = this.clone(source[key]);
  293. }
  294. return result;
  295. };
  296.  
  297. exports.isEditable = function (el) {
  298. return d.matches(el, "input,[contenteditable]") ||
  299. d.matches(el, "select,[contenteditable]") ||
  300. d.matches(el, "textarea,[contenteditable]") ||
  301. d.matches(el, "button,[contenteditable]");
  302. };
  303.  
  304. exports.removePsClasses = function (element) {
  305. var clsList = cls.list(element);
  306. for (var i = 0; i < clsList.length; i++) {
  307. var className = clsList[i];
  308. if (className.indexOf('ps-') === 0) {
  309. cls.remove(element, className);
  310. }
  311. }
  312. };
  313.  
  314. exports.outerWidth = function (element) {
  315. return this.toInt(d.css(element, 'width')) +
  316. this.toInt(d.css(element, 'paddingLeft')) +
  317. this.toInt(d.css(element, 'paddingRight')) +
  318. this.toInt(d.css(element, 'borderLeftWidth')) +
  319. this.toInt(d.css(element, 'borderRightWidth'));
  320. };
  321.  
  322. exports.startScrolling = function (element, axis) {
  323. cls.add(element, 'ps-in-scrolling');
  324. if (typeof axis !== 'undefined') {
  325. cls.add(element, 'ps-' + axis);
  326. } else {
  327. cls.add(element, 'ps-x');
  328. cls.add(element, 'ps-y');
  329. }
  330. };
  331.  
  332. exports.stopScrolling = function (element, axis) {
  333. cls.remove(element, 'ps-in-scrolling');
  334. if (typeof axis !== 'undefined') {
  335. cls.remove(element, 'ps-' + axis);
  336. } else {
  337. cls.remove(element, 'ps-x');
  338. cls.remove(element, 'ps-y');
  339. }
  340. };
  341.  
  342. exports.env = {
  343. isWebKit: 'WebkitAppearance' in document.documentElement.style,
  344. supportsTouch: (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch),
  345. supportsIePointer: window.navigator.msMaxTouchPoints !== null
  346. };
  347.  
  348. },{"./class":2,"./dom":3}],7:[function(require,module,exports){
  349. 'use strict';
  350.  
  351. var destroy = require('./plugin/destroy')
  352. , initialize = require('./plugin/initialize')
  353. , update = require('./plugin/update');
  354.  
  355. module.exports = {
  356. initialize: initialize,
  357. update: update,
  358. destroy: destroy
  359. };
  360.  
  361. },{"./plugin/destroy":9,"./plugin/initialize":17,"./plugin/update":21}],8:[function(require,module,exports){
  362. 'use strict';
  363.  
  364. module.exports = {
  365. maxScrollbarLength: null,
  366. minScrollbarLength: null,
  367. scrollXMarginOffset: 0,
  368. scrollYMarginOffset: 0,
  369. stopPropagationOnClick: true,
  370. suppressScrollX: false,
  371. suppressScrollY: false,
  372. swipePropagation: true,
  373. useBothWheelAxes: false,
  374. useKeyboard: true,
  375. useSelectionScroll: false,
  376. wheelPropagation: false,
  377. wheelSpeed: 1,
  378. theme: 'default'
  379. };
  380.  
  381. },{}],9:[function(require,module,exports){
  382. 'use strict';
  383.  
  384. var d = require('../lib/dom')
  385. , h = require('../lib/helper')
  386. , instances = require('./instances');
  387.  
  388. module.exports = function (element) {
  389. var i = instances.get(element);
  390.  
  391. if (!i) {
  392. return;
  393. }
  394.  
  395. i.event.unbindAll();
  396. d.remove(i.scrollbarX);
  397. d.remove(i.scrollbarY);
  398. d.remove(i.scrollbarXRail);
  399. d.remove(i.scrollbarYRail);
  400. h.removePsClasses(element);
  401.  
  402. instances.remove(element);
  403. };
  404.  
  405. },{"../lib/dom":3,"../lib/helper":6,"./instances":18}],10:[function(require,module,exports){
  406. 'use strict';
  407.  
  408. var h = require('../../lib/helper')
  409. , instances = require('../instances')
  410. , updateGeometry = require('../update-geometry')
  411. , updateScroll = require('../update-scroll');
  412.  
  413. function bindClickRailHandler(element, i) {
  414. function pageOffset(el) {
  415. return el.getBoundingClientRect();
  416. }
  417. var stopPropagation = window.Event.prototype.stopPropagation.bind;
  418.  
  419. if (i.settings.stopPropagationOnClick) {
  420. i.event.bind(i.scrollbarY, 'click', stopPropagation);
  421. }
  422. i.event.bind(i.scrollbarYRail, 'click', function (e) {
  423. var halfOfScrollbarLength = h.toInt(i.scrollbarYHeight / 2);
  424. var positionTop = i.railYRatio * (e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength);
  425. var maxPositionTop = i.railYRatio * (i.railYHeight - i.scrollbarYHeight);
  426. var positionRatio = positionTop / maxPositionTop;
  427.  
  428. if (positionRatio < 0) {
  429. positionRatio = 0;
  430. } else if (positionRatio > 1) {
  431. positionRatio = 1;
  432. }
  433.  
  434. updateScroll(element, 'top', (i.contentHeight - i.containerHeight) * positionRatio);
  435. updateGeometry(element);
  436.  
  437. e.stopPropagation();
  438. });
  439.  
  440. if (i.settings.stopPropagationOnClick) {
  441. i.event.bind(i.scrollbarX, 'click', stopPropagation);
  442. }
  443. i.event.bind(i.scrollbarXRail, 'click', function (e) {
  444. var halfOfScrollbarLength = h.toInt(i.scrollbarXWidth / 2);
  445. var positionLeft = i.railXRatio * (e.pageX - window.pageXOffset - pageOffset(i.scrollbarXRail).left - halfOfScrollbarLength);
  446. var maxPositionLeft = i.railXRatio * (i.railXWidth - i.scrollbarXWidth);
  447. var positionRatio = positionLeft / maxPositionLeft;
  448.  
  449. if (positionRatio < 0) {
  450. positionRatio = 0;
  451. } else if (positionRatio > 1) {
  452. positionRatio = 1;
  453. }
  454.  
  455. updateScroll(element, 'left', ((i.contentWidth - i.containerWidth) * positionRatio) - i.negativeScrollAdjustment);
  456. updateGeometry(element);
  457.  
  458. e.stopPropagation();
  459. });
  460. }
  461.  
  462. module.exports = function (element) {
  463. var i = instances.get(element);
  464. bindClickRailHandler(element, i);
  465. };
  466.  
  467. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],11:[function(require,module,exports){
  468. 'use strict';
  469.  
  470. var d = require('../../lib/dom')
  471. , h = require('../../lib/helper')
  472. , instances = require('../instances')
  473. , updateGeometry = require('../update-geometry')
  474. , updateScroll = require('../update-scroll');
  475.  
  476. function bindMouseScrollXHandler(element, i) {
  477. var currentLeft = null;
  478. var currentPageX = null;
  479.  
  480. function updateScrollLeft(deltaX) {
  481. var newLeft = currentLeft + (deltaX * i.railXRatio);
  482. var maxLeft = Math.max(0, i.scrollbarXRail.getBoundingClientRect().left) + (i.railXRatio * (i.railXWidth - i.scrollbarXWidth));
  483.  
  484. if (newLeft < 0) {
  485. i.scrollbarXLeft = 0;
  486. } else if (newLeft > maxLeft) {
  487. i.scrollbarXLeft = maxLeft;
  488. } else {
  489. i.scrollbarXLeft = newLeft;
  490. }
  491.  
  492. var scrollLeft = h.toInt(i.scrollbarXLeft * (i.contentWidth - i.containerWidth) / (i.containerWidth - (i.railXRatio * i.scrollbarXWidth))) - i.negativeScrollAdjustment;
  493. updateScroll(element, 'left', scrollLeft);
  494. }
  495.  
  496. var mouseMoveHandler = function (e) {
  497. updateScrollLeft(e.pageX - currentPageX);
  498. updateGeometry(element);
  499. e.stopPropagation();
  500. e.preventDefault();
  501. };
  502.  
  503. var mouseUpHandler = function () {
  504. h.stopScrolling(element, 'x');
  505. i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  506. };
  507.  
  508. i.event.bind(i.scrollbarX, 'mousedown', function (e) {
  509. currentPageX = e.pageX;
  510. currentLeft = h.toInt(d.css(i.scrollbarX, 'left')) * i.railXRatio;
  511. h.startScrolling(element, 'x');
  512.  
  513. i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  514. i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
  515.  
  516. e.stopPropagation();
  517. e.preventDefault();
  518. });
  519. }
  520.  
  521. function bindMouseScrollYHandler(element, i) {
  522. var currentTop = null;
  523. var currentPageY = null;
  524.  
  525. function updateScrollTop(deltaY) {
  526. var newTop = currentTop + (deltaY * i.railYRatio);
  527. var maxTop = Math.max(0, i.scrollbarYRail.getBoundingClientRect().top) + (i.railYRatio * (i.railYHeight - i.scrollbarYHeight));
  528.  
  529. if (newTop < 0) {
  530. i.scrollbarYTop = 0;
  531. } else if (newTop > maxTop) {
  532. i.scrollbarYTop = maxTop;
  533. } else {
  534. i.scrollbarYTop = newTop;
  535. }
  536.  
  537. var scrollTop = h.toInt(i.scrollbarYTop * (i.contentHeight - i.containerHeight) / (i.containerHeight - (i.railYRatio * i.scrollbarYHeight)));
  538. updateScroll(element, 'top', scrollTop);
  539. }
  540.  
  541. var mouseMoveHandler = function (e) {
  542. updateScrollTop(e.pageY - currentPageY);
  543. updateGeometry(element);
  544. e.stopPropagation();
  545. e.preventDefault();
  546. };
  547.  
  548. var mouseUpHandler = function () {
  549. h.stopScrolling(element, 'y');
  550. i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  551. };
  552.  
  553. i.event.bind(i.scrollbarY, 'mousedown', function (e) {
  554. currentPageY = e.pageY;
  555. currentTop = h.toInt(d.css(i.scrollbarY, 'top')) * i.railYRatio;
  556. h.startScrolling(element, 'y');
  557.  
  558. i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  559. i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
  560.  
  561. e.stopPropagation();
  562. e.preventDefault();
  563. });
  564. }
  565.  
  566. module.exports = function (element) {
  567. var i = instances.get(element);
  568. bindMouseScrollXHandler(element, i);
  569. bindMouseScrollYHandler(element, i);
  570. };
  571.  
  572. },{"../../lib/dom":3,"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],12:[function(require,module,exports){
  573. 'use strict';
  574.  
  575. var h = require('../../lib/helper')
  576. , d = require('../../lib/dom')
  577. , instances = require('../instances')
  578. , updateGeometry = require('../update-geometry')
  579. , updateScroll = require('../update-scroll');
  580.  
  581. function bindKeyboardHandler(element, i) {
  582. var hovered = false;
  583. i.event.bind(element, 'mouseenter', function () {
  584. hovered = true;
  585. });
  586. i.event.bind(element, 'mouseleave', function () {
  587. hovered = false;
  588. });
  589.  
  590. var shouldPrevent = false;
  591. function shouldPreventDefault(deltaX, deltaY) {
  592. var scrollTop = element.scrollTop;
  593. if (deltaX === 0) {
  594. if (!i.scrollbarYActive) {
  595. return false;
  596. }
  597. if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
  598. return !i.settings.wheelPropagation;
  599. }
  600. }
  601.  
  602. var scrollLeft = element.scrollLeft;
  603. if (deltaY === 0) {
  604. if (!i.scrollbarXActive) {
  605. return false;
  606. }
  607. if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
  608. return !i.settings.wheelPropagation;
  609. }
  610. }
  611. return true;
  612. }
  613.  
  614. i.event.bind(i.ownerDocument, 'keydown', function (e) {
  615. if (e.isDefaultPrevented && e.isDefaultPrevented()) {
  616. return;
  617. }
  618.  
  619. var focused = d.matches(i.scrollbarX, ':focus') ||
  620. d.matches(i.scrollbarY, ':focus');
  621.  
  622. if (!hovered && !focused) {
  623. return;
  624. }
  625.  
  626. var activeElement = document.activeElement ? document.activeElement : i.ownerDocument.activeElement;
  627. if (activeElement) {
  628. // go deeper if element is a webcomponent
  629. while (activeElement.shadowRoot) {
  630. activeElement = activeElement.shadowRoot.activeElement;
  631. }
  632. if (h.isEditable(activeElement)) {
  633. return;
  634. }
  635. }
  636.  
  637. var deltaX = 0;
  638. var deltaY = 0;
  639.  
  640. switch (e.which) {
  641. case 37: // left
  642. deltaX = -30;
  643. break;
  644. case 38: // up
  645. deltaY = 30;
  646. break;
  647. case 39: // right
  648. deltaX = 30;
  649. break;
  650. case 40: // down
  651. deltaY = -30;
  652. break;
  653. case 33: // page up
  654. deltaY = 90;
  655. break;
  656. case 32: // space bar
  657. if (e.shiftKey) {
  658. deltaY = 90;
  659. } else {
  660. deltaY = -90;
  661. }
  662. break;
  663. case 34: // page down
  664. deltaY = -90;
  665. break;
  666. case 35: // end
  667. if (e.ctrlKey) {
  668. deltaY = -i.contentHeight;
  669. } else {
  670. deltaY = -i.containerHeight;
  671. }
  672. break;
  673. case 36: // home
  674. if (e.ctrlKey) {
  675. deltaY = element.scrollTop;
  676. } else {
  677. deltaY = i.containerHeight;
  678. }
  679. break;
  680. default:
  681. return;
  682. }
  683.  
  684. updateScroll(element, 'top', element.scrollTop - deltaY);
  685. updateScroll(element, 'left', element.scrollLeft + deltaX);
  686. updateGeometry(element);
  687.  
  688. shouldPrevent = shouldPreventDefault(deltaX, deltaY);
  689. if (shouldPrevent) {
  690. e.preventDefault();
  691. }
  692. });
  693. }
  694.  
  695. module.exports = function (element) {
  696. var i = instances.get(element);
  697. bindKeyboardHandler(element, i);
  698. };
  699.  
  700. },{"../../lib/dom":3,"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],13:[function(require,module,exports){
  701. 'use strict';
  702.  
  703. var instances = require('../instances')
  704. , updateGeometry = require('../update-geometry')
  705. , updateScroll = require('../update-scroll');
  706.  
  707. function bindMouseWheelHandler(element, i) {
  708. var shouldPrevent = false;
  709.  
  710. function shouldPreventDefault(deltaX, deltaY) {
  711. var scrollTop = element.scrollTop;
  712. if (deltaX === 0) {
  713. if (!i.scrollbarYActive) {
  714. return false;
  715. }
  716. if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
  717. return !i.settings.wheelPropagation;
  718. }
  719. }
  720.  
  721. var scrollLeft = element.scrollLeft;
  722. if (deltaY === 0) {
  723. if (!i.scrollbarXActive) {
  724. return false;
  725. }
  726. if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
  727. return !i.settings.wheelPropagation;
  728. }
  729. }
  730. return true;
  731. }
  732.  
  733. function getDeltaFromEvent(e) {
  734. var deltaX = e.deltaX;
  735. var deltaY = -1 * e.deltaY;
  736.  
  737. if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
  738. // OS X Safari
  739. deltaX = -1 * e.wheelDeltaX / 6;
  740. deltaY = e.wheelDeltaY / 6;
  741. }
  742.  
  743. if (e.deltaMode && e.deltaMode === 1) {
  744. // Firefox in deltaMode 1: Line scrolling
  745. deltaX *= 10;
  746. deltaY *= 10;
  747. }
  748.  
  749. if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
  750. // IE in some mouse drivers
  751. deltaX = 0;
  752. deltaY = e.wheelDelta;
  753. }
  754.  
  755. return [deltaX, deltaY];
  756. }
  757.  
  758. function shouldBeConsumedByTextarea(deltaX, deltaY) {
  759. var hoveredTextarea = element.querySelector('textarea:hover');
  760. if (hoveredTextarea) {
  761. var maxScrollTop = hoveredTextarea.scrollHeight - hoveredTextarea.clientHeight;
  762. if (maxScrollTop > 0) {
  763. if (!(hoveredTextarea.scrollTop === 0 && deltaY > 0) &&
  764. !(hoveredTextarea.scrollTop === maxScrollTop && deltaY < 0)) {
  765. return true;
  766. }
  767. }
  768. var maxScrollLeft = hoveredTextarea.scrollLeft - hoveredTextarea.clientWidth;
  769. if (maxScrollLeft > 0) {
  770. if (!(hoveredTextarea.scrollLeft === 0 && deltaX < 0) &&
  771. !(hoveredTextarea.scrollLeft === maxScrollLeft && deltaX > 0)) {
  772. return true;
  773. }
  774. }
  775. }
  776. return false;
  777. }
  778.  
  779. function mousewheelHandler(e) {
  780. var delta = getDeltaFromEvent(e);
  781.  
  782. var deltaX = delta[0];
  783. var deltaY = delta[1];
  784.  
  785. if (shouldBeConsumedByTextarea(deltaX, deltaY)) {
  786. return;
  787. }
  788.  
  789. shouldPrevent = false;
  790. if (!i.settings.useBothWheelAxes) {
  791. // deltaX will only be used for horizontal scrolling and deltaY will
  792. // only be used for vertical scrolling - this is the default
  793. updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
  794. updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
  795. } else if (i.scrollbarYActive && !i.scrollbarXActive) {
  796. // only vertical scrollbar is active and useBothWheelAxes option is
  797. // active, so let's scroll vertical bar using both mouse wheel axes
  798. if (deltaY) {
  799. updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
  800. } else {
  801. updateScroll(element, 'top', element.scrollTop + (deltaX * i.settings.wheelSpeed));
  802. }
  803. shouldPrevent = true;
  804. } else if (i.scrollbarXActive && !i.scrollbarYActive) {
  805. // useBothWheelAxes and only horizontal bar is active, so use both
  806. // wheel axes for horizontal bar
  807. if (deltaX) {
  808. updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
  809. } else {
  810. updateScroll(element, 'left', element.scrollLeft - (deltaY * i.settings.wheelSpeed));
  811. }
  812. shouldPrevent = true;
  813. }
  814.  
  815. updateGeometry(element);
  816.  
  817. shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
  818. if (shouldPrevent) {
  819. e.stopPropagation();
  820. e.preventDefault();
  821. }
  822. }
  823.  
  824. if (typeof window.onwheel !== "undefined") {
  825. i.event.bind(element, 'wheel', mousewheelHandler);
  826. } else if (typeof window.onmousewheel !== "undefined") {
  827. i.event.bind(element, 'mousewheel', mousewheelHandler);
  828. }
  829. }
  830.  
  831. module.exports = function (element) {
  832. var i = instances.get(element);
  833. bindMouseWheelHandler(element, i);
  834. };
  835.  
  836. },{"../instances":18,"../update-geometry":19,"../update-scroll":20}],14:[function(require,module,exports){
  837. 'use strict';
  838.  
  839. var instances = require('../instances')
  840. , updateGeometry = require('../update-geometry');
  841.  
  842. function bindNativeScrollHandler(element, i) {
  843. i.event.bind(element, 'scroll', function () {
  844. updateGeometry(element);
  845. });
  846. }
  847.  
  848. module.exports = function (element) {
  849. var i = instances.get(element);
  850. bindNativeScrollHandler(element, i);
  851. };
  852.  
  853. },{"../instances":18,"../update-geometry":19}],15:[function(require,module,exports){
  854. 'use strict';
  855.  
  856. var h = require('../../lib/helper')
  857. , instances = require('../instances')
  858. , updateGeometry = require('../update-geometry')
  859. , updateScroll = require('../update-scroll');
  860.  
  861. function bindSelectionHandler(element, i) {
  862. function getRangeNode() {
  863. var selection = window.getSelection ? window.getSelection() :
  864. document.getSelection ? document.getSelection() : '';
  865. if (selection.toString().length === 0) {
  866. return null;
  867. } else {
  868. return selection.getRangeAt(0).commonAncestorContainer;
  869. }
  870. }
  871.  
  872. var scrollingLoop = null;
  873. var scrollDiff = {top: 0, left: 0};
  874. function startScrolling() {
  875. if (!scrollingLoop) {
  876. scrollingLoop = setInterval(function () {
  877. if (!instances.get(element)) {
  878. clearInterval(scrollingLoop);
  879. return;
  880. }
  881.  
  882. updateScroll(element, 'top', element.scrollTop + scrollDiff.top);
  883. updateScroll(element, 'left', element.scrollLeft + scrollDiff.left);
  884. updateGeometry(element);
  885. }, 50); // every .1 sec
  886. }
  887. }
  888. function stopScrolling() {
  889. if (scrollingLoop) {
  890. clearInterval(scrollingLoop);
  891. scrollingLoop = null;
  892. }
  893. h.stopScrolling(element);
  894. }
  895.  
  896. var isSelected = false;
  897. i.event.bind(i.ownerDocument, 'selectionchange', function () {
  898. if (element.contains(getRangeNode())) {
  899. isSelected = true;
  900. } else {
  901. isSelected = false;
  902. stopScrolling();
  903. }
  904. });
  905. i.event.bind(window, 'mouseup', function () {
  906. if (isSelected) {
  907. isSelected = false;
  908. stopScrolling();
  909. }
  910. });
  911.  
  912. i.event.bind(window, 'mousemove', function (e) {
  913. if (isSelected) {
  914. var mousePosition = {x: e.pageX, y: e.pageY};
  915. var containerGeometry = {
  916. left: element.offsetLeft,
  917. right: element.offsetLeft + element.offsetWidth,
  918. top: element.offsetTop,
  919. bottom: element.offsetTop + element.offsetHeight
  920. };
  921.  
  922. if (mousePosition.x < containerGeometry.left + 3) {
  923. scrollDiff.left = -5;
  924. h.startScrolling(element, 'x');
  925. } else if (mousePosition.x > containerGeometry.right - 3) {
  926. scrollDiff.left = 5;
  927. h.startScrolling(element, 'x');
  928. } else {
  929. scrollDiff.left = 0;
  930. }
  931.  
  932. if (mousePosition.y < containerGeometry.top + 3) {
  933. if (containerGeometry.top + 3 - mousePosition.y < 5) {
  934. scrollDiff.top = -5;
  935. } else {
  936. scrollDiff.top = -20;
  937. }
  938. h.startScrolling(element, 'y');
  939. } else if (mousePosition.y > containerGeometry.bottom - 3) {
  940. if (mousePosition.y - containerGeometry.bottom + 3 < 5) {
  941. scrollDiff.top = 5;
  942. } else {
  943. scrollDiff.top = 20;
  944. }
  945. h.startScrolling(element, 'y');
  946. } else {
  947. scrollDiff.top = 0;
  948. }
  949.  
  950. if (scrollDiff.top === 0 && scrollDiff.left === 0) {
  951. stopScrolling();
  952. } else {
  953. startScrolling();
  954. }
  955. }
  956. });
  957. }
  958.  
  959. module.exports = function (element) {
  960. var i = instances.get(element);
  961. bindSelectionHandler(element, i);
  962. };
  963.  
  964. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19,"../update-scroll":20}],16:[function(require,module,exports){
  965. 'use strict';
  966.  
  967. var instances = require('../instances')
  968. , updateGeometry = require('../update-geometry')
  969. , updateScroll = require('../update-scroll');
  970.  
  971. function bindTouchHandler(element, i, supportsTouch, supportsIePointer) {
  972. function shouldPreventDefault(deltaX, deltaY) {
  973. var scrollTop = element.scrollTop;
  974. var scrollLeft = element.scrollLeft;
  975. var magnitudeX = Math.abs(deltaX);
  976. var magnitudeY = Math.abs(deltaY);
  977.  
  978. if (magnitudeY > magnitudeX) {
  979. // user is perhaps trying to swipe up/down the page
  980.  
  981. if (((deltaY < 0) && (scrollTop === i.contentHeight - i.containerHeight)) ||
  982. ((deltaY > 0) && (scrollTop === 0))) {
  983. return !i.settings.swipePropagation;
  984. }
  985. } else if (magnitudeX > magnitudeY) {
  986. // user is perhaps trying to swipe left/right across the page
  987.  
  988. if (((deltaX < 0) && (scrollLeft === i.contentWidth - i.containerWidth)) ||
  989. ((deltaX > 0) && (scrollLeft === 0))) {
  990. return !i.settings.swipePropagation;
  991. }
  992. }
  993.  
  994. return true;
  995. }
  996.  
  997. function applyTouchMove(differenceX, differenceY) {
  998. updateScroll(element, 'top', element.scrollTop - differenceY);
  999. updateScroll(element, 'left', element.scrollLeft - differenceX);
  1000.  
  1001. updateGeometry(element);
  1002. }
  1003.  
  1004. var startOffset = {};
  1005. var startTime = 0;
  1006. var speed = {};
  1007. var easingLoop = null;
  1008. var inGlobalTouch = false;
  1009. var inLocalTouch = false;
  1010.  
  1011. function globalTouchStart() {
  1012. inGlobalTouch = true;
  1013. }
  1014. function globalTouchEnd() {
  1015. inGlobalTouch = false;
  1016. }
  1017.  
  1018. function getTouch(e) {
  1019. if (e.targetTouches) {
  1020. return e.targetTouches[0];
  1021. } else {
  1022. // Maybe IE pointer
  1023. return e;
  1024. }
  1025. }
  1026. function shouldHandle(e) {
  1027. if (e.targetTouches && e.targetTouches.length === 1) {
  1028. return true;
  1029. }
  1030. if (e.pointerType && e.pointerType !== 'mouse' && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
  1031. return true;
  1032. }
  1033. return false;
  1034. }
  1035. function touchStart(e) {
  1036. if (shouldHandle(e)) {
  1037. inLocalTouch = true;
  1038.  
  1039. var touch = getTouch(e);
  1040.  
  1041. startOffset.pageX = touch.pageX;
  1042. startOffset.pageY = touch.pageY;
  1043.  
  1044. startTime = (new Date()).getTime();
  1045.  
  1046. if (easingLoop !== null) {
  1047. clearInterval(easingLoop);
  1048. }
  1049.  
  1050. e.stopPropagation();
  1051. }
  1052. }
  1053. function touchMove(e) {
  1054. if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
  1055. var touch = getTouch(e);
  1056.  
  1057. var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
  1058.  
  1059. var differenceX = currentOffset.pageX - startOffset.pageX;
  1060. var differenceY = currentOffset.pageY - startOffset.pageY;
  1061.  
  1062. applyTouchMove(differenceX, differenceY);
  1063. startOffset = currentOffset;
  1064.  
  1065. var currentTime = (new Date()).getTime();
  1066.  
  1067. var timeGap = currentTime - startTime;
  1068. if (timeGap > 0) {
  1069. speed.x = differenceX / timeGap;
  1070. speed.y = differenceY / timeGap;
  1071. startTime = currentTime;
  1072. }
  1073.  
  1074. if (shouldPreventDefault(differenceX, differenceY)) {
  1075. e.stopPropagation();
  1076. e.preventDefault();
  1077. }
  1078. }
  1079. }
  1080. function touchEnd() {
  1081. if (!inGlobalTouch && inLocalTouch) {
  1082. inLocalTouch = false;
  1083.  
  1084. clearInterval(easingLoop);
  1085. easingLoop = setInterval(function () {
  1086. if (!instances.get(element)) {
  1087. clearInterval(easingLoop);
  1088. return;
  1089. }
  1090.  
  1091. if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
  1092. clearInterval(easingLoop);
  1093. return;
  1094. }
  1095.  
  1096. applyTouchMove(speed.x * 30, speed.y * 30);
  1097.  
  1098. speed.x *= 0.8;
  1099. speed.y *= 0.8;
  1100. }, 10);
  1101. }
  1102. }
  1103.  
  1104. if (supportsTouch) {
  1105. i.event.bind(window, 'touchstart', globalTouchStart);
  1106. i.event.bind(window, 'touchend', globalTouchEnd);
  1107. i.event.bind(element, 'touchstart', touchStart);
  1108. i.event.bind(element, 'touchmove', touchMove);
  1109. i.event.bind(element, 'touchend', touchEnd);
  1110. }
  1111.  
  1112. if (supportsIePointer) {
  1113. if (window.PointerEvent) {
  1114. i.event.bind(window, 'pointerdown', globalTouchStart);
  1115. i.event.bind(window, 'pointerup', globalTouchEnd);
  1116. i.event.bind(element, 'pointerdown', touchStart);
  1117. i.event.bind(element, 'pointermove', touchMove);
  1118. i.event.bind(element, 'pointerup', touchEnd);
  1119. } else if (window.MSPointerEvent) {
  1120. i.event.bind(window, 'MSPointerDown', globalTouchStart);
  1121. i.event.bind(window, 'MSPointerUp', globalTouchEnd);
  1122. i.event.bind(element, 'MSPointerDown', touchStart);
  1123. i.event.bind(element, 'MSPointerMove', touchMove);
  1124. i.event.bind(element, 'MSPointerUp', touchEnd);
  1125. }
  1126. }
  1127. }
  1128.  
  1129. module.exports = function (element, supportsTouch, supportsIePointer) {
  1130. var i = instances.get(element);
  1131. bindTouchHandler(element, i, supportsTouch, supportsIePointer);
  1132. };
  1133.  
  1134. },{"../instances":18,"../update-geometry":19,"../update-scroll":20}],17:[function(require,module,exports){
  1135. 'use strict';
  1136.  
  1137. var cls = require('../lib/class')
  1138. , h = require('../lib/helper')
  1139. , instances = require('./instances')
  1140. , updateGeometry = require('./update-geometry');
  1141.  
  1142. // Handlers
  1143. var clickRailHandler = require('./handler/click-rail')
  1144. , dragScrollbarHandler = require('./handler/drag-scrollbar')
  1145. , keyboardHandler = require('./handler/keyboard')
  1146. , mouseWheelHandler = require('./handler/mouse-wheel')
  1147. , nativeScrollHandler = require('./handler/native-scroll')
  1148. , selectionHandler = require('./handler/selection')
  1149. , touchHandler = require('./handler/touch');
  1150.  
  1151. module.exports = function (element, userSettings) {
  1152. userSettings = typeof userSettings === 'object' ? userSettings : {};
  1153.  
  1154. cls.add(element, 'ps-container');
  1155.  
  1156. // Create a plugin instance.
  1157. var i = instances.add(element);
  1158.  
  1159. i.settings = h.extend(i.settings, userSettings);
  1160. cls.add(element, 'ps-theme-' + i.settings.theme);
  1161.  
  1162. clickRailHandler(element);
  1163. dragScrollbarHandler(element);
  1164. mouseWheelHandler(element);
  1165. nativeScrollHandler(element);
  1166.  
  1167. if (i.settings.useSelectionScroll) {
  1168. selectionHandler(element);
  1169. }
  1170.  
  1171. if (h.env.supportsTouch || h.env.supportsIePointer) {
  1172. touchHandler(element, h.env.supportsTouch, h.env.supportsIePointer);
  1173. }
  1174. if (i.settings.useKeyboard) {
  1175. keyboardHandler(element);
  1176. }
  1177.  
  1178. updateGeometry(element);
  1179. };
  1180.  
  1181. },{"../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){
  1182. 'use strict';
  1183.  
  1184. var cls = require('../lib/class')
  1185. , d = require('../lib/dom')
  1186. , defaultSettings = require('./default-setting')
  1187. , EventManager = require('../lib/event-manager')
  1188. , guid = require('../lib/guid')
  1189. , h = require('../lib/helper');
  1190.  
  1191. var instances = {};
  1192.  
  1193. function Instance(element) {
  1194. var i = this;
  1195.  
  1196. i.settings = h.clone(defaultSettings);
  1197. i.containerWidth = null;
  1198. i.containerHeight = null;
  1199. i.contentWidth = null;
  1200. i.contentHeight = null;
  1201.  
  1202. i.isRtl = d.css(element, 'direction') === "rtl";
  1203. i.isNegativeScroll = (function () {
  1204. var originalScrollLeft = element.scrollLeft;
  1205. var result = null;
  1206. element.scrollLeft = -1;
  1207. result = element.scrollLeft < 0;
  1208. element.scrollLeft = originalScrollLeft;
  1209. return result;
  1210. })();
  1211. i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
  1212. i.event = new EventManager();
  1213. i.ownerDocument = element.ownerDocument || document;
  1214.  
  1215. function focus() {
  1216. cls.add(element, 'ps-focus');
  1217. }
  1218.  
  1219. function blur() {
  1220. cls.remove(element, 'ps-focus');
  1221. }
  1222.  
  1223. i.scrollbarXRail = d.appendTo(d.e('div', 'ps-scrollbar-x-rail'), element);
  1224. i.scrollbarX = d.appendTo(d.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
  1225. i.scrollbarX.setAttribute('tabindex', 0);
  1226. i.event.bind(i.scrollbarX, 'focus', focus);
  1227. i.event.bind(i.scrollbarX, 'blur', blur);
  1228. i.scrollbarXActive = null;
  1229. i.scrollbarXWidth = null;
  1230. i.scrollbarXLeft = null;
  1231. i.scrollbarXBottom = h.toInt(d.css(i.scrollbarXRail, 'bottom'));
  1232. i.isScrollbarXUsingBottom = i.scrollbarXBottom === i.scrollbarXBottom; // !isNaN
  1233. i.scrollbarXTop = i.isScrollbarXUsingBottom ? null : h.toInt(d.css(i.scrollbarXRail, 'top'));
  1234. i.railBorderXWidth = h.toInt(d.css(i.scrollbarXRail, 'borderLeftWidth')) + h.toInt(d.css(i.scrollbarXRail, 'borderRightWidth'));
  1235. // Set rail to display:block to calculate margins
  1236. d.css(i.scrollbarXRail, 'display', 'block');
  1237. i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
  1238. d.css(i.scrollbarXRail, 'display', '');
  1239. i.railXWidth = null;
  1240. i.railXRatio = null;
  1241.  
  1242. i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
  1243. i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
  1244. i.scrollbarY.setAttribute('tabindex', 0);
  1245. i.event.bind(i.scrollbarY, 'focus', focus);
  1246. i.event.bind(i.scrollbarY, 'blur', blur);
  1247. i.scrollbarYActive = null;
  1248. i.scrollbarYHeight = null;
  1249. i.scrollbarYTop = null;
  1250. i.scrollbarYRight = h.toInt(d.css(i.scrollbarYRail, 'right'));
  1251. i.isScrollbarYUsingRight = i.scrollbarYRight === i.scrollbarYRight; // !isNaN
  1252. i.scrollbarYLeft = i.isScrollbarYUsingRight ? null : h.toInt(d.css(i.scrollbarYRail, 'left'));
  1253. i.scrollbarYOuterWidth = i.isRtl ? h.outerWidth(i.scrollbarY) : null;
  1254. i.railBorderYWidth = h.toInt(d.css(i.scrollbarYRail, 'borderTopWidth')) + h.toInt(d.css(i.scrollbarYRail, 'borderBottomWidth'));
  1255. d.css(i.scrollbarYRail, 'display', 'block');
  1256. i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
  1257. d.css(i.scrollbarYRail, 'display', '');
  1258. i.railYHeight = null;
  1259. i.railYRatio = null;
  1260. }
  1261.  
  1262. function getId(element) {
  1263. if (typeof element.dataset === 'undefined') {
  1264. return element.getAttribute('data-ps-id');
  1265. } else {
  1266. return element.dataset.psId;
  1267. }
  1268. }
  1269.  
  1270. function setId(element, id) {
  1271. if (typeof element.dataset === 'undefined') {
  1272. element.setAttribute('data-ps-id', id);
  1273. } else {
  1274. element.dataset.psId = id;
  1275. }
  1276. }
  1277.  
  1278. function removeId(element) {
  1279. if (typeof element.dataset === 'undefined') {
  1280. element.removeAttribute('data-ps-id');
  1281. } else {
  1282. delete element.dataset.psId;
  1283. }
  1284. }
  1285.  
  1286. exports.add = function (element) {
  1287. var newId = guid();
  1288. setId(element, newId);
  1289. instances[newId] = new Instance(element);
  1290. return instances[newId];
  1291. };
  1292.  
  1293. exports.remove = function (element) {
  1294. delete instances[getId(element)];
  1295. removeId(element);
  1296. };
  1297.  
  1298. exports.get = function (element) {
  1299. return instances[getId(element)];
  1300. };
  1301.  
  1302. },{"../lib/class":2,"../lib/dom":3,"../lib/event-manager":4,"../lib/guid":5,"../lib/helper":6,"./default-setting":8}],19:[function(require,module,exports){
  1303. 'use strict';
  1304.  
  1305. var cls = require('../lib/class')
  1306. , d = require('../lib/dom')
  1307. , h = require('../lib/helper')
  1308. , instances = require('./instances')
  1309. , updateScroll = require('./update-scroll');
  1310.  
  1311. function getThumbSize(i, thumbSize) {
  1312. if (i.settings.minScrollbarLength) {
  1313. thumbSize = Math.max(thumbSize, i.settings.minScrollbarLength);
  1314. }
  1315. if (i.settings.maxScrollbarLength) {
  1316. thumbSize = Math.min(thumbSize, i.settings.maxScrollbarLength);
  1317. }
  1318. return thumbSize;
  1319. }
  1320.  
  1321. function updateCss(element, i) {
  1322. var xRailOffset = {width: i.railXWidth};
  1323. if (i.isRtl) {
  1324. xRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth - i.contentWidth;
  1325. } else {
  1326. xRailOffset.left = element.scrollLeft;
  1327. }
  1328. if (i.isScrollbarXUsingBottom) {
  1329. xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
  1330. } else {
  1331. xRailOffset.top = i.scrollbarXTop + element.scrollTop;
  1332. }
  1333. d.css(i.scrollbarXRail, xRailOffset);
  1334.  
  1335. var yRailOffset = {top: element.scrollTop, height: i.railYHeight};
  1336. if (i.isScrollbarYUsingRight) {
  1337. if (i.isRtl) {
  1338. yRailOffset.right = i.contentWidth - (i.negativeScrollAdjustment + element.scrollLeft) - i.scrollbarYRight - i.scrollbarYOuterWidth;
  1339. } else {
  1340. yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
  1341. }
  1342. } else {
  1343. if (i.isRtl) {
  1344. yRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth * 2 - i.contentWidth - i.scrollbarYLeft - i.scrollbarYOuterWidth;
  1345. } else {
  1346. yRailOffset.left = i.scrollbarYLeft + element.scrollLeft;
  1347. }
  1348. }
  1349. d.css(i.scrollbarYRail, yRailOffset);
  1350.  
  1351. d.css(i.scrollbarX, {left: i.scrollbarXLeft, width: i.scrollbarXWidth - i.railBorderXWidth});
  1352. d.css(i.scrollbarY, {top: i.scrollbarYTop, height: i.scrollbarYHeight - i.railBorderYWidth});
  1353. }
  1354.  
  1355. module.exports = function (element) {
  1356. var i = instances.get(element);
  1357.  
  1358. i.containerWidth = element.clientWidth;
  1359. i.containerHeight = element.clientHeight;
  1360. i.contentWidth = element.scrollWidth;
  1361. i.contentHeight = element.scrollHeight;
  1362.  
  1363. var existingRails;
  1364. if (!element.contains(i.scrollbarXRail)) {
  1365. existingRails = d.queryChildren(element, '.ps-scrollbar-x-rail');
  1366. if (existingRails.length > 0) {
  1367. existingRails.forEach(function (rail) {
  1368. d.remove(rail);
  1369. });
  1370. }
  1371. d.appendTo(i.scrollbarXRail, element);
  1372. }
  1373. if (!element.contains(i.scrollbarYRail)) {
  1374. existingRails = d.queryChildren(element, '.ps-scrollbar-y-rail');
  1375. if (existingRails.length > 0) {
  1376. existingRails.forEach(function (rail) {
  1377. d.remove(rail);
  1378. });
  1379. }
  1380. d.appendTo(i.scrollbarYRail, element);
  1381. }
  1382.  
  1383. if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
  1384. i.scrollbarXActive = true;
  1385. i.railXWidth = i.containerWidth - i.railXMarginWidth;
  1386. i.railXRatio = i.containerWidth / i.railXWidth;
  1387. i.scrollbarXWidth = getThumbSize(i, h.toInt(i.railXWidth * i.containerWidth / i.contentWidth));
  1388. i.scrollbarXLeft = h.toInt((i.negativeScrollAdjustment + element.scrollLeft) * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
  1389. } else {
  1390. i.scrollbarXActive = false;
  1391. }
  1392.  
  1393. if (!i.settings.suppressScrollY && i.containerHeight + i.settings.scrollYMarginOffset < i.contentHeight) {
  1394. i.scrollbarYActive = true;
  1395. i.railYHeight = i.containerHeight - i.railYMarginHeight;
  1396. i.railYRatio = i.containerHeight / i.railYHeight;
  1397. i.scrollbarYHeight = getThumbSize(i, h.toInt(i.railYHeight * i.containerHeight / i.contentHeight));
  1398. i.scrollbarYTop = h.toInt(element.scrollTop * (i.railYHeight - i.scrollbarYHeight) / (i.contentHeight - i.containerHeight));
  1399. } else {
  1400. i.scrollbarYActive = false;
  1401. }
  1402.  
  1403. if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
  1404. i.scrollbarXLeft = i.railXWidth - i.scrollbarXWidth;
  1405. }
  1406. if (i.scrollbarYTop >= i.railYHeight - i.scrollbarYHeight) {
  1407. i.scrollbarYTop = i.railYHeight - i.scrollbarYHeight;
  1408. }
  1409.  
  1410. updateCss(element, i);
  1411.  
  1412. if (i.scrollbarXActive) {
  1413. cls.add(element, 'ps-active-x');
  1414. } else {
  1415. cls.remove(element, 'ps-active-x');
  1416. i.scrollbarXWidth = 0;
  1417. i.scrollbarXLeft = 0;
  1418. updateScroll(element, 'left', 0);
  1419. }
  1420. if (i.scrollbarYActive) {
  1421. cls.add(element, 'ps-active-y');
  1422. } else {
  1423. cls.remove(element, 'ps-active-y');
  1424. i.scrollbarYHeight = 0;
  1425. i.scrollbarYTop = 0;
  1426. updateScroll(element, 'top', 0);
  1427. }
  1428. };
  1429.  
  1430. },{"../lib/class":2,"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-scroll":20}],20:[function(require,module,exports){
  1431. 'use strict';
  1432.  
  1433. var instances = require('./instances');
  1434.  
  1435. var upEvent = document.createEvent('Event')
  1436. , downEvent = document.createEvent('Event')
  1437. , leftEvent = document.createEvent('Event')
  1438. , rightEvent = document.createEvent('Event')
  1439. , yEvent = document.createEvent('Event')
  1440. , xEvent = document.createEvent('Event')
  1441. , xStartEvent = document.createEvent('Event')
  1442. , xEndEvent = document.createEvent('Event')
  1443. , yStartEvent = document.createEvent('Event')
  1444. , yEndEvent = document.createEvent('Event')
  1445. , lastTop
  1446. , lastLeft;
  1447.  
  1448. upEvent.initEvent('ps-scroll-up', true, true);
  1449. downEvent.initEvent('ps-scroll-down', true, true);
  1450. leftEvent.initEvent('ps-scroll-left', true, true);
  1451. rightEvent.initEvent('ps-scroll-right', true, true);
  1452. yEvent.initEvent('ps-scroll-y', true, true);
  1453. xEvent.initEvent('ps-scroll-x', true, true);
  1454. xStartEvent.initEvent('ps-x-reach-start', true, true);
  1455. xEndEvent.initEvent('ps-x-reach-end', true, true);
  1456. yStartEvent.initEvent('ps-y-reach-start', true, true);
  1457. yEndEvent.initEvent('ps-y-reach-end', true, true);
  1458.  
  1459. module.exports = function (element, axis, value) {
  1460. if (typeof element === 'undefined') {
  1461. throw 'You must provide an element to the update-scroll function';
  1462. }
  1463.  
  1464. if (typeof axis === 'undefined') {
  1465. throw 'You must provide an axis to the update-scroll function';
  1466. }
  1467.  
  1468. if (typeof value === 'undefined') {
  1469. throw 'You must provide a value to the update-scroll function';
  1470. }
  1471.  
  1472. if (axis === 'top' && value <= 0) {
  1473. element.scrollTop = value = 0; // don't allow negative scroll
  1474. element.dispatchEvent(yStartEvent);
  1475. }
  1476.  
  1477. if (axis === 'left' && value <= 0) {
  1478. element.scrollLeft = value = 0; // don't allow negative scroll
  1479. element.dispatchEvent(xStartEvent);
  1480. }
  1481.  
  1482. var i = instances.get(element);
  1483.  
  1484. if (axis === 'top' && value >= i.contentHeight - i.containerHeight) {
  1485. element.scrollTop = value = i.contentHeight - i.containerHeight; // don't allow scroll past container
  1486. element.dispatchEvent(yEndEvent);
  1487. }
  1488.  
  1489. if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
  1490. element.scrollLeft = value = i.contentWidth - i.containerWidth; // don't allow scroll past container
  1491. element.dispatchEvent(xEndEvent);
  1492. }
  1493.  
  1494. if (!lastTop) {
  1495. lastTop = element.scrollTop;
  1496. }
  1497.  
  1498. if (!lastLeft) {
  1499. lastLeft = element.scrollLeft;
  1500. }
  1501.  
  1502. if (axis === 'top' && value < lastTop) {
  1503. element.dispatchEvent(upEvent);
  1504. }
  1505.  
  1506. if (axis === 'top' && value > lastTop) {
  1507. element.dispatchEvent(downEvent);
  1508. }
  1509.  
  1510. if (axis === 'left' && value < lastLeft) {
  1511. element.dispatchEvent(leftEvent);
  1512. }
  1513.  
  1514. if (axis === 'left' && value > lastLeft) {
  1515. element.dispatchEvent(rightEvent);
  1516. }
  1517.  
  1518. if (axis === 'top') {
  1519. element.scrollTop = lastTop = value;
  1520. element.dispatchEvent(yEvent);
  1521. }
  1522.  
  1523. if (axis === 'left') {
  1524. element.scrollLeft = lastLeft = value;
  1525. element.dispatchEvent(xEvent);
  1526. }
  1527.  
  1528. };
  1529.  
  1530. },{"./instances":18}],21:[function(require,module,exports){
  1531. 'use strict';
  1532.  
  1533. var d = require('../lib/dom')
  1534. , h = require('../lib/helper')
  1535. , instances = require('./instances')
  1536. , updateGeometry = require('./update-geometry')
  1537. , updateScroll = require('./update-scroll');
  1538.  
  1539. module.exports = function (element) {
  1540. var i = instances.get(element);
  1541.  
  1542. if (!i) {
  1543. return;
  1544. }
  1545.  
  1546. // Recalcuate negative scrollLeft adjustment
  1547. i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
  1548.  
  1549. // Recalculate rail margins
  1550. d.css(i.scrollbarXRail, 'display', 'block');
  1551. d.css(i.scrollbarYRail, 'display', 'block');
  1552. i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
  1553. i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
  1554.  
  1555. // Hide scrollbars not to affect scrollWidth and scrollHeight
  1556. d.css(i.scrollbarXRail, 'display', 'none');
  1557. d.css(i.scrollbarYRail, 'display', 'none');
  1558.  
  1559. updateGeometry(element);
  1560.  
  1561. // Update top/left scroll to trigger events
  1562. updateScroll(element, 'top', element.scrollTop);
  1563. updateScroll(element, 'left', element.scrollLeft);
  1564.  
  1565. d.css(i.scrollbarXRail, 'display', '');
  1566. d.css(i.scrollbarYRail, 'display', '');
  1567. };
  1568.  
  1569. },{"../lib/dom":3,"../lib/helper":6,"./instances":18,"./update-geometry":19,"./update-scroll":20}]},{},[1]);