perfect-scrollbar.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. (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){
  2. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  3. * Licensed under the MIT License
  4. */
  5. 'use strict';
  6. var ps = require('../main');
  7. if (typeof define === 'function' && define.amd) {
  8. // AMD
  9. define(ps);
  10. } else {
  11. // Add to a global object.
  12. window.PerfectScrollbar = ps;
  13. if (typeof window.Ps === 'undefined') {
  14. window.Ps = ps;
  15. }
  16. }
  17. },{"../main":7}],2:[function(require,module,exports){
  18. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  19. * Licensed under the MIT License
  20. */
  21. 'use strict';
  22. function oldAdd(element, className) {
  23. var classes = element.className.split(' ');
  24. if (classes.indexOf(className) < 0) {
  25. classes.push(className);
  26. }
  27. element.className = classes.join(' ');
  28. }
  29. function oldRemove(element, className) {
  30. var classes = element.className.split(' ');
  31. var idx = classes.indexOf(className);
  32. if (idx >= 0) {
  33. classes.splice(idx, 1);
  34. }
  35. element.className = classes.join(' ');
  36. }
  37. exports.add = function (element, className) {
  38. if (element.classList) {
  39. element.classList.add(className);
  40. } else {
  41. oldAdd(element, className);
  42. }
  43. };
  44. exports.remove = function (element, className) {
  45. if (element.classList) {
  46. element.classList.remove(className);
  47. } else {
  48. oldRemove(element, className);
  49. }
  50. };
  51. exports.list = function (element) {
  52. if (element.classList) {
  53. return element.classList;
  54. } else {
  55. return element.className.split(' ');
  56. }
  57. };
  58. },{}],3:[function(require,module,exports){
  59. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  60. * Licensed under the MIT License
  61. */
  62. 'use strict';
  63. exports.e = function (tagName, className) {
  64. var element = document.createElement(tagName);
  65. element.className = className;
  66. return element;
  67. };
  68. exports.appendTo = function (child, parent) {
  69. parent.appendChild(child);
  70. return child;
  71. };
  72. function cssGet(element, styleName) {
  73. return window.getComputedStyle(element)[styleName];
  74. }
  75. function cssSet(element, styleName, styleValue) {
  76. if (typeof styleValue === 'number') {
  77. styleValue = styleValue.toString() + 'px';
  78. }
  79. element.style[styleName] = styleValue;
  80. return element;
  81. }
  82. function cssMultiSet(element, obj) {
  83. for (var key in obj) {
  84. var val = obj[key];
  85. if (typeof val === 'number') {
  86. val = val.toString() + 'px';
  87. }
  88. element.style[key] = val;
  89. }
  90. return element;
  91. }
  92. exports.css = function (element, styleNameOrObject, styleValue) {
  93. if (typeof styleNameOrObject === 'object') {
  94. // multiple set with object
  95. return cssMultiSet(element, styleNameOrObject);
  96. } else {
  97. if (typeof styleValue === 'undefined') {
  98. return cssGet(element, styleNameOrObject);
  99. } else {
  100. return cssSet(element, styleNameOrObject, styleValue);
  101. }
  102. }
  103. };
  104. exports.matches = function (element, query) {
  105. if (typeof element.matches !== 'undefined') {
  106. return element.matches(query);
  107. } else {
  108. if (typeof element.matchesSelector !== 'undefined') {
  109. return element.matchesSelector(query);
  110. } else if (typeof element.webkitMatchesSelector !== 'undefined') {
  111. return element.webkitMatchesSelector(query);
  112. } else if (typeof element.mozMatchesSelector !== 'undefined') {
  113. return element.mozMatchesSelector(query);
  114. } else if (typeof element.msMatchesSelector !== 'undefined') {
  115. return element.msMatchesSelector(query);
  116. }
  117. }
  118. };
  119. exports.remove = function (element) {
  120. if (typeof element.remove !== 'undefined') {
  121. element.remove();
  122. } else {
  123. element.parentNode.removeChild(element);
  124. }
  125. };
  126. },{}],4:[function(require,module,exports){
  127. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  128. * Licensed under the MIT License
  129. */
  130. 'use strict';
  131. var EventElement = function (element) {
  132. this.element = element;
  133. this.events = {};
  134. };
  135. EventElement.prototype.bind = function (eventName, handler) {
  136. if (typeof this.events[eventName] === 'undefined') {
  137. this.events[eventName] = [];
  138. }
  139. this.events[eventName].push(handler);
  140. this.element.addEventListener(eventName, handler, false);
  141. };
  142. EventElement.prototype.unbind = function (eventName, handler) {
  143. var isHandlerProvided = (typeof handler !== 'undefined');
  144. this.events[eventName] = this.events[eventName].filter(function (hdlr) {
  145. if (isHandlerProvided && hdlr !== handler) {
  146. return true;
  147. }
  148. this.element.removeEventListener(eventName, hdlr, false);
  149. return false;
  150. }, this);
  151. };
  152. EventElement.prototype.unbindAll = function () {
  153. for (var name in this.events) {
  154. this.unbind(name);
  155. }
  156. };
  157. var EventManager = function () {
  158. this.eventElements = [];
  159. };
  160. EventManager.prototype.eventElement = function (element) {
  161. var ee = this.eventElements.filter(function (eventElement) {
  162. return eventElement.element === element;
  163. })[0];
  164. if (typeof ee === 'undefined') {
  165. ee = new EventElement(element);
  166. this.eventElements.push(ee);
  167. }
  168. return ee;
  169. };
  170. EventManager.prototype.bind = function (element, eventName, handler) {
  171. this.eventElement(element).bind(eventName, handler);
  172. };
  173. EventManager.prototype.unbind = function (element, eventName, handler) {
  174. this.eventElement(element).unbind(eventName, handler);
  175. };
  176. EventManager.prototype.unbindAll = function () {
  177. for (var i = 0; i < this.eventElements.length; i++) {
  178. this.eventElements[i].unbindAll();
  179. }
  180. };
  181. EventManager.prototype.once = function (element, eventName, handler) {
  182. var ee = this.eventElement(element);
  183. var onceHandler = function (e) {
  184. ee.unbind(eventName, onceHandler);
  185. handler(e);
  186. };
  187. ee.bind(eventName, onceHandler);
  188. };
  189. module.exports = EventManager;
  190. },{}],5:[function(require,module,exports){
  191. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  192. * Licensed under the MIT License
  193. */
  194. 'use strict';
  195. module.exports = (function () {
  196. function s4() {
  197. return Math.floor((1 + Math.random()) * 0x10000)
  198. .toString(16)
  199. .substring(1);
  200. }
  201. return function () {
  202. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  203. s4() + '-' + s4() + s4() + s4();
  204. };
  205. })();
  206. },{}],6:[function(require,module,exports){
  207. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  208. * Licensed under the MIT License
  209. */
  210. 'use strict';
  211. var cls = require('./class')
  212. , d = require('./dom');
  213. exports.toInt = function (x) {
  214. if (typeof x === 'string') {
  215. return parseInt(x, 10);
  216. } else {
  217. return ~~x;
  218. }
  219. };
  220. exports.clone = function (obj) {
  221. if (obj === null) {
  222. return null;
  223. } else if (typeof obj === 'object') {
  224. var result = {};
  225. for (var key in obj) {
  226. result[key] = this.clone(obj[key]);
  227. }
  228. return result;
  229. } else {
  230. return obj;
  231. }
  232. };
  233. exports.extend = function (original, source) {
  234. var result = this.clone(original);
  235. for (var key in source) {
  236. result[key] = this.clone(source[key]);
  237. }
  238. return result;
  239. };
  240. exports.isEditable = function (el) {
  241. return d.matches(el, "input,[contenteditable]") ||
  242. d.matches(el, "select,[contenteditable]") ||
  243. d.matches(el, "textarea,[contenteditable]") ||
  244. d.matches(el, "button,[contenteditable]");
  245. };
  246. exports.removePsClasses = function (element) {
  247. var clsList = cls.list(element);
  248. for (var i = 0; i < clsList.length; i++) {
  249. var className = clsList[i];
  250. if (className.indexOf('ps-') === 0) {
  251. cls.remove(element, className);
  252. }
  253. }
  254. };
  255. exports.outerWidth = function (element) {
  256. return this.toInt(d.css(element, 'width')) +
  257. this.toInt(d.css(element, 'paddingLeft')) +
  258. this.toInt(d.css(element, 'paddingRight')) +
  259. this.toInt(d.css(element, 'borderLeftWidth')) +
  260. this.toInt(d.css(element, 'borderRightWidth'));
  261. };
  262. exports.startScrolling = function (element, axis) {
  263. cls.add(element, 'ps-in-scrolling');
  264. if (typeof axis !== 'undefined') {
  265. cls.add(element, 'ps-' + axis);
  266. } else {
  267. cls.add(element, 'ps-x');
  268. cls.add(element, 'ps-y');
  269. }
  270. };
  271. exports.stopScrolling = function (element, axis) {
  272. cls.remove(element, 'ps-in-scrolling');
  273. if (typeof axis !== 'undefined') {
  274. cls.remove(element, 'ps-' + axis);
  275. } else {
  276. cls.remove(element, 'ps-x');
  277. cls.remove(element, 'ps-y');
  278. }
  279. };
  280. exports.env = {
  281. isWebKit: 'WebkitAppearance' in document.documentElement.style,
  282. supportsTouch: (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch),
  283. supportsIePointer: window.navigator.msMaxTouchPoints !== null
  284. };
  285. },{"./class":2,"./dom":3}],7:[function(require,module,exports){
  286. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  287. * Licensed under the MIT License
  288. */
  289. 'use strict';
  290. var destroy = require('./plugin/destroy')
  291. , initialize = require('./plugin/initialize')
  292. , update = require('./plugin/update');
  293. module.exports = {
  294. initialize: initialize,
  295. update: update,
  296. destroy: destroy
  297. };
  298. },{"./plugin/destroy":9,"./plugin/initialize":17,"./plugin/update":20}],8:[function(require,module,exports){
  299. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  300. * Licensed under the MIT License
  301. */
  302. 'use strict';
  303. module.exports = {
  304. wheelSpeed: 1,
  305. wheelPropagation: false,
  306. swipePropagation: true,
  307. minScrollbarLength: null,
  308. maxScrollbarLength: null,
  309. useBothWheelAxes: false,
  310. useKeyboard: true,
  311. suppressScrollX: false,
  312. suppressScrollY: false,
  313. scrollXMarginOffset: 0,
  314. scrollYMarginOffset: 0
  315. };
  316. },{}],9:[function(require,module,exports){
  317. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  318. * Licensed under the MIT License
  319. */
  320. 'use strict';
  321. var d = require('../lib/dom')
  322. , h = require('../lib/helper')
  323. , instances = require('./instances');
  324. module.exports = function (element) {
  325. var i = instances.get(element);
  326. i.event.unbindAll();
  327. d.remove(i.scrollbarX);
  328. d.remove(i.scrollbarY);
  329. d.remove(i.scrollbarXRail);
  330. d.remove(i.scrollbarYRail);
  331. h.removePsClasses(element);
  332. instances.remove(element);
  333. };
  334. },{"../lib/dom":3,"../lib/helper":6,"./instances":18}],10:[function(require,module,exports){
  335. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  336. * Licensed under the MIT License
  337. */
  338. 'use strict';
  339. var h = require('../../lib/helper')
  340. , instances = require('../instances')
  341. , updateGeometry = require('../update-geometry');
  342. function bindClickRailHandler(element, i) {
  343. function pageOffset(el) {
  344. return el.getBoundingClientRect();
  345. }
  346. var stopPropagation = window.Event.prototype.stopPropagation.bind;
  347. i.event.bind(i.scrollbarY, 'click', stopPropagation);
  348. i.event.bind(i.scrollbarYRail, 'click', function (e) {
  349. var halfOfScrollbarLength = h.toInt(i.scrollbarYHeight / 2);
  350. var positionTop = e.pageY - pageOffset(i.scrollbarYRail).top - halfOfScrollbarLength;
  351. var maxPositionTop = i.containerHeight - i.scrollbarYHeight;
  352. var positionRatio = positionTop / maxPositionTop;
  353. if (positionRatio < 0) {
  354. positionRatio = 0;
  355. } else if (positionRatio > 1) {
  356. positionRatio = 1;
  357. }
  358. element.scrollTop = (i.contentHeight - i.containerHeight) * positionRatio;
  359. updateGeometry(element);
  360. });
  361. i.event.bind(i.scrollbarX, 'click', stopPropagation);
  362. i.event.bind(i.scrollbarXRail, 'click', function (e) {
  363. var halfOfScrollbarLength = h.toInt(i.scrollbarXWidth / 2);
  364. var positionLeft = e.pageX - pageOffset(i.scrollbarXRail).left - halfOfScrollbarLength;
  365. console.log(e.pageX, i.scrollbarXRail.offsetLeft);
  366. var maxPositionLeft = i.containerWidth - i.scrollbarXWidth;
  367. var positionRatio = positionLeft / maxPositionLeft;
  368. if (positionRatio < 0) {
  369. positionRatio = 0;
  370. } else if (positionRatio > 1) {
  371. positionRatio = 1;
  372. }
  373. element.scrollLeft = (i.contentWidth - i.containerWidth) * positionRatio;
  374. updateGeometry(element);
  375. });
  376. }
  377. module.exports = function (element) {
  378. var i = instances.get(element);
  379. bindClickRailHandler(element, i);
  380. };
  381. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19}],11:[function(require,module,exports){
  382. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  383. * Licensed under the MIT License
  384. */
  385. 'use strict';
  386. var d = require('../../lib/dom')
  387. , h = require('../../lib/helper')
  388. , instances = require('../instances')
  389. , updateGeometry = require('../update-geometry');
  390. function bindMouseScrollXHandler(element, i) {
  391. var currentLeft = null;
  392. var currentPageX = null;
  393. function updateScrollLeft(deltaX) {
  394. var newLeft = currentLeft + deltaX;
  395. var maxLeft = i.containerWidth - i.scrollbarXWidth;
  396. if (newLeft < 0) {
  397. i.scrollbarXLeft = 0;
  398. } else if (newLeft > maxLeft) {
  399. i.scrollbarXLeft = maxLeft;
  400. } else {
  401. i.scrollbarXLeft = newLeft;
  402. }
  403. var scrollLeft = h.toInt(i.scrollbarXLeft * (i.contentWidth - i.containerWidth) / (i.containerWidth - i.scrollbarXWidth));
  404. element.scrollLeft = scrollLeft;
  405. }
  406. var mouseMoveHandler = function (e) {
  407. updateScrollLeft(e.pageX - currentPageX);
  408. updateGeometry(element);
  409. e.stopPropagation();
  410. e.preventDefault();
  411. };
  412. var mouseUpHandler = function () {
  413. h.stopScrolling(element, 'x');
  414. i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  415. };
  416. i.event.bind(i.scrollbarX, 'mousedown', function (e) {
  417. currentPageX = e.pageX;
  418. currentLeft = h.toInt(d.css(i.scrollbarX, 'left'));
  419. h.startScrolling(element, 'x');
  420. i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  421. i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
  422. e.stopPropagation();
  423. e.preventDefault();
  424. });
  425. }
  426. function bindMouseScrollYHandler(element, i) {
  427. var currentTop = null;
  428. var currentPageY = null;
  429. function updateScrollTop(deltaY) {
  430. var newTop = currentTop + deltaY;
  431. var maxTop = i.containerHeight - i.scrollbarYHeight;
  432. if (newTop < 0) {
  433. i.scrollbarYTop = 0;
  434. } else if (newTop > maxTop) {
  435. i.scrollbarYTop = maxTop;
  436. } else {
  437. i.scrollbarYTop = newTop;
  438. }
  439. var scrollTop = h.toInt(i.scrollbarYTop * (i.contentHeight - i.containerHeight) / (i.containerHeight - i.scrollbarYHeight));
  440. element.scrollTop = scrollTop;
  441. }
  442. var mouseMoveHandler = function (e) {
  443. updateScrollTop(e.pageY - currentPageY);
  444. updateGeometry(element);
  445. e.stopPropagation();
  446. e.preventDefault();
  447. };
  448. var mouseUpHandler = function () {
  449. h.stopScrolling(element, 'y');
  450. i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  451. };
  452. i.event.bind(i.scrollbarY, 'mousedown', function (e) {
  453. currentPageY = e.pageY;
  454. currentTop = h.toInt(d.css(i.scrollbarY, 'top'));
  455. h.startScrolling(element, 'y');
  456. i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
  457. i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
  458. e.stopPropagation();
  459. e.preventDefault();
  460. });
  461. }
  462. module.exports = function (element) {
  463. var i = instances.get(element);
  464. bindMouseScrollXHandler(element, i);
  465. bindMouseScrollYHandler(element, i);
  466. };
  467. },{"../../lib/dom":3,"../../lib/helper":6,"../instances":18,"../update-geometry":19}],12:[function(require,module,exports){
  468. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  469. * Licensed under the MIT License
  470. */
  471. 'use strict';
  472. var h = require('../../lib/helper')
  473. , instances = require('../instances')
  474. , updateGeometry = require('../update-geometry');
  475. function bindKeyboardHandler(element, i) {
  476. var hovered = false;
  477. i.event.bind(element, 'mouseenter', function () {
  478. hovered = true;
  479. });
  480. i.event.bind(element, 'mouseleave', function () {
  481. hovered = false;
  482. });
  483. var shouldPrevent = false;
  484. function shouldPreventDefault(deltaX, deltaY) {
  485. var scrollTop = element.scrollTop;
  486. if (deltaX === 0) {
  487. if (!i.scrollbarYActive) {
  488. return false;
  489. }
  490. if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
  491. return !i.settings.wheelPropagation;
  492. }
  493. }
  494. var scrollLeft = element.scrollLeft;
  495. if (deltaY === 0) {
  496. if (!i.scrollbarXActive) {
  497. return false;
  498. }
  499. if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
  500. return !i.settings.wheelPropagation;
  501. }
  502. }
  503. return true;
  504. }
  505. i.event.bind(i.ownerDocument, 'keydown', function (e) {
  506. if (e.isDefaultPrevented && e.isDefaultPrevented()) {
  507. return;
  508. }
  509. if (!hovered) {
  510. return;
  511. }
  512. var activeElement = document.activeElement ? document.activeElement : i.ownerDocument.activeElement;
  513. if (activeElement) {
  514. // go deeper if element is a webcomponent
  515. while (activeElement.shadowRoot) {
  516. activeElement = activeElement.shadowRoot.activeElement;
  517. }
  518. if (h.isEditable(activeElement)) {
  519. return;
  520. }
  521. }
  522. var deltaX = 0;
  523. var deltaY = 0;
  524. switch (e.which) {
  525. case 37: // left
  526. deltaX = -30;
  527. break;
  528. case 38: // up
  529. deltaY = 30;
  530. break;
  531. case 39: // right
  532. deltaX = 30;
  533. break;
  534. case 40: // down
  535. deltaY = -30;
  536. break;
  537. case 33: // page up
  538. deltaY = 90;
  539. break;
  540. case 32: // space bar
  541. case 34: // page down
  542. deltaY = -90;
  543. break;
  544. case 35: // end
  545. if (e.ctrlKey) {
  546. deltaY = -i.contentHeight;
  547. } else {
  548. deltaY = -i.containerHeight;
  549. }
  550. break;
  551. case 36: // home
  552. if (e.ctrlKey) {
  553. deltaY = element.scrollTop;
  554. } else {
  555. deltaY = i.containerHeight;
  556. }
  557. break;
  558. default:
  559. return;
  560. }
  561. element.scrollTop = element.scrollTop - deltaY;
  562. element.scrollLeft = element.scrollLeft + deltaX;
  563. updateGeometry(element);
  564. shouldPrevent = shouldPreventDefault(deltaX, deltaY);
  565. if (shouldPrevent) {
  566. e.preventDefault();
  567. }
  568. });
  569. }
  570. module.exports = function (element) {
  571. var i = instances.get(element);
  572. bindKeyboardHandler(element, i);
  573. };
  574. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19}],13:[function(require,module,exports){
  575. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  576. * Licensed under the MIT License
  577. */
  578. 'use strict';
  579. var h = require('../../lib/helper')
  580. , instances = require('../instances')
  581. , updateGeometry = require('../update-geometry');
  582. function bindMouseWheelHandler(element, i) {
  583. var shouldPrevent = false;
  584. function shouldPreventDefault(deltaX, deltaY) {
  585. var scrollTop = element.scrollTop;
  586. if (deltaX === 0) {
  587. if (!i.scrollbarYActive) {
  588. return false;
  589. }
  590. if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
  591. return !i.settings.wheelPropagation;
  592. }
  593. }
  594. var scrollLeft = element.scrollLeft;
  595. if (deltaY === 0) {
  596. if (!i.scrollbarXActive) {
  597. return false;
  598. }
  599. if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
  600. return !i.settings.wheelPropagation;
  601. }
  602. }
  603. return true;
  604. }
  605. function getDeltaFromEvent(e) {
  606. var deltaX = e.deltaX;
  607. var deltaY = -1 * e.deltaY;
  608. if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
  609. // OS X Safari
  610. deltaX = -1 * e.wheelDeltaX / 6;
  611. deltaY = e.wheelDeltaY / 6;
  612. }
  613. if (e.deltaMode && e.deltaMode === 1) {
  614. // Firefox in deltaMode 1: Line scrolling
  615. deltaX *= 10;
  616. deltaY *= 10;
  617. }
  618. if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
  619. // IE in some mouse drivers
  620. deltaX = 0;
  621. deltaY = e.wheelDelta;
  622. }
  623. return [deltaX, deltaY];
  624. }
  625. function mousewheelHandler(e) {
  626. // FIXME: this is a quick fix for the select problem in FF and IE.
  627. // If there comes an effective way to deal with the problem,
  628. // this lines should be removed.
  629. if (!h.env.isWebKit && element.querySelector('select:focus')) {
  630. return;
  631. }
  632. var delta = getDeltaFromEvent(e);
  633. var deltaX = delta[0];
  634. var deltaY = delta[1];
  635. shouldPrevent = false;
  636. if (!i.settings.useBothWheelAxes) {
  637. // deltaX will only be used for horizontal scrolling and deltaY will
  638. // only be used for vertical scrolling - this is the default
  639. element.scrollTop = element.scrollTop - (deltaY * i.settings.wheelSpeed);
  640. element.scrollLeft = element.scrollLeft + (deltaX * i.settings.wheelSpeed);
  641. } else if (i.scrollbarYActive && !i.scrollbarXActive) {
  642. // only vertical scrollbar is active and useBothWheelAxes option is
  643. // active, so let's scroll vertical bar using both mouse wheel axes
  644. if (deltaY) {
  645. element.scrollTop = element.scrollTop - (deltaY * i.settings.wheelSpeed);
  646. } else {
  647. element.scrollTop = element.scrollTop + (deltaX * i.settings.wheelSpeed);
  648. }
  649. shouldPrevent = true;
  650. } else if (i.scrollbarXActive && !i.scrollbarYActive) {
  651. // useBothWheelAxes and only horizontal bar is active, so use both
  652. // wheel axes for horizontal bar
  653. if (deltaX) {
  654. element.scrollLeft = element.scrollLeft + (deltaX * i.settings.wheelSpeed);
  655. } else {
  656. element.scrollLeft = element.scrollLeft - (deltaY * i.settings.wheelSpeed);
  657. }
  658. shouldPrevent = true;
  659. }
  660. updateGeometry(element);
  661. shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
  662. if (shouldPrevent) {
  663. e.stopPropagation();
  664. e.preventDefault();
  665. }
  666. }
  667. if (typeof window.onwheel !== "undefined") {
  668. i.event.bind(element, 'wheel', mousewheelHandler);
  669. } else if (typeof window.onmousewheel !== "undefined") {
  670. i.event.bind(element, 'mousewheel', mousewheelHandler);
  671. }
  672. }
  673. module.exports = function (element) {
  674. var i = instances.get(element);
  675. bindMouseWheelHandler(element, i);
  676. };
  677. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19}],14:[function(require,module,exports){
  678. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  679. * Licensed under the MIT License
  680. */
  681. 'use strict';
  682. var instances = require('../instances')
  683. , updateGeometry = require('../update-geometry');
  684. function bindNativeScrollHandler(element, i) {
  685. i.event.bind(element, 'scroll', function () {
  686. updateGeometry(element);
  687. });
  688. }
  689. module.exports = function (element) {
  690. var i = instances.get(element);
  691. bindNativeScrollHandler(element, i);
  692. };
  693. },{"../instances":18,"../update-geometry":19}],15:[function(require,module,exports){
  694. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  695. * Licensed under the MIT License
  696. */
  697. 'use strict';
  698. var h = require('../../lib/helper')
  699. , instances = require('../instances')
  700. , updateGeometry = require('../update-geometry');
  701. function bindSelectionHandler(element, i) {
  702. function getRangeNode() {
  703. var selection = window.getSelection ? window.getSelection() :
  704. document.getSelection ? document.getSelection() : '';
  705. if (selection.toString().length === 0) {
  706. return null;
  707. } else {
  708. return selection.getRangeAt(0).commonAncestorContainer;
  709. }
  710. }
  711. var scrollingLoop = null;
  712. var scrollDiff = {top: 0, left: 0};
  713. function startScrolling() {
  714. if (!scrollingLoop) {
  715. scrollingLoop = setInterval(function () {
  716. if (!instances.get(element)) {
  717. clearInterval(scrollingLoop);
  718. return;
  719. }
  720. element.scrollTop = element.scrollTop + scrollDiff.top;
  721. element.scrollLeft = element.scrollLeft + scrollDiff.left;
  722. updateGeometry(element);
  723. }, 50); // every .1 sec
  724. }
  725. }
  726. function stopScrolling() {
  727. if (scrollingLoop) {
  728. clearInterval(scrollingLoop);
  729. scrollingLoop = null;
  730. }
  731. h.stopScrolling(element);
  732. }
  733. var isSelected = false;
  734. i.event.bind(i.ownerDocument, 'selectionchange', function () {
  735. if (element.contains(getRangeNode())) {
  736. isSelected = true;
  737. } else {
  738. isSelected = false;
  739. stopScrolling();
  740. }
  741. });
  742. i.event.bind(window, 'mouseup', function () {
  743. if (isSelected) {
  744. isSelected = false;
  745. stopScrolling();
  746. }
  747. });
  748. i.event.bind(window, 'mousemove', function (e) {
  749. if (isSelected) {
  750. var mousePosition = {x: e.pageX, y: e.pageY};
  751. var containerGeometry = {
  752. left: element.offsetLeft,
  753. right: element.offsetLeft + element.offsetWidth,
  754. top: element.offsetTop,
  755. bottom: element.offsetTop + element.offsetHeight
  756. };
  757. if (mousePosition.x < containerGeometry.left + 3) {
  758. scrollDiff.left = -5;
  759. h.startScrolling(element, 'x');
  760. } else if (mousePosition.x > containerGeometry.right - 3) {
  761. scrollDiff.left = 5;
  762. h.startScrolling(element, 'x');
  763. } else {
  764. scrollDiff.left = 0;
  765. }
  766. if (mousePosition.y < containerGeometry.top + 3) {
  767. if (containerGeometry.top + 3 - mousePosition.y < 5) {
  768. scrollDiff.top = -5;
  769. } else {
  770. scrollDiff.top = -20;
  771. }
  772. h.startScrolling(element, 'y');
  773. } else if (mousePosition.y > containerGeometry.bottom - 3) {
  774. if (mousePosition.y - containerGeometry.bottom + 3 < 5) {
  775. scrollDiff.top = 5;
  776. } else {
  777. scrollDiff.top = 20;
  778. }
  779. h.startScrolling(element, 'y');
  780. } else {
  781. scrollDiff.top = 0;
  782. }
  783. if (scrollDiff.top === 0 && scrollDiff.left === 0) {
  784. stopScrolling();
  785. } else {
  786. startScrolling();
  787. }
  788. }
  789. });
  790. }
  791. module.exports = function (element) {
  792. var i = instances.get(element);
  793. bindSelectionHandler(element, i);
  794. };
  795. },{"../../lib/helper":6,"../instances":18,"../update-geometry":19}],16:[function(require,module,exports){
  796. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  797. * Licensed under the MIT License
  798. */
  799. 'use strict';
  800. var instances = require('../instances')
  801. , updateGeometry = require('../update-geometry');
  802. function bindTouchHandler(element, i, supportsTouch, supportsIePointer) {
  803. function shouldPreventDefault(deltaX, deltaY) {
  804. var scrollTop = element.scrollTop;
  805. var scrollLeft = element.scrollLeft;
  806. var magnitudeX = Math.abs(deltaX);
  807. var magnitudeY = Math.abs(deltaY);
  808. if (magnitudeY > magnitudeX) {
  809. // user is perhaps trying to swipe up/down the page
  810. if (((deltaY < 0) && (scrollTop === i.contentHeight - i.containerHeight)) ||
  811. ((deltaY > 0) && (scrollTop === 0))) {
  812. return !i.settings.swipePropagation;
  813. }
  814. } else if (magnitudeX > magnitudeY) {
  815. // user is perhaps trying to swipe left/right across the page
  816. if (((deltaX < 0) && (scrollLeft === i.contentWidth - i.containerWidth)) ||
  817. ((deltaX > 0) && (scrollLeft === 0))) {
  818. return !i.settings.swipePropagation;
  819. }
  820. }
  821. return true;
  822. }
  823. function applyTouchMove(differenceX, differenceY) {
  824. element.scrollTop = element.scrollTop - differenceY;
  825. element.scrollLeft = element.scrollLeft - differenceX;
  826. updateGeometry(element);
  827. }
  828. var startOffset = {};
  829. var startTime = 0;
  830. var speed = {};
  831. var easingLoop = null;
  832. var inGlobalTouch = false;
  833. var inLocalTouch = false;
  834. function globalTouchStart() {
  835. inGlobalTouch = true;
  836. }
  837. function globalTouchEnd() {
  838. inGlobalTouch = false;
  839. }
  840. function getTouch(e) {
  841. if (e.targetTouches) {
  842. return e.targetTouches[0];
  843. } else {
  844. // Maybe IE pointer
  845. return e;
  846. }
  847. }
  848. function shouldHandle(e) {
  849. if (e.targetTouches && e.targetTouches.length === 1) {
  850. return true;
  851. }
  852. if (e.pointerType && e.pointerType !== 'mouse' && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
  853. return true;
  854. }
  855. return false;
  856. }
  857. function touchStart(e) {
  858. if (shouldHandle(e)) {
  859. inLocalTouch = true;
  860. var touch = getTouch(e);
  861. startOffset.pageX = touch.pageX;
  862. startOffset.pageY = touch.pageY;
  863. startTime = (new Date()).getTime();
  864. if (easingLoop !== null) {
  865. clearInterval(easingLoop);
  866. }
  867. e.stopPropagation();
  868. }
  869. }
  870. function touchMove(e) {
  871. if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
  872. var touch = getTouch(e);
  873. var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
  874. var differenceX = currentOffset.pageX - startOffset.pageX;
  875. var differenceY = currentOffset.pageY - startOffset.pageY;
  876. applyTouchMove(differenceX, differenceY);
  877. startOffset = currentOffset;
  878. var currentTime = (new Date()).getTime();
  879. var timeGap = currentTime - startTime;
  880. if (timeGap > 0) {
  881. speed.x = differenceX / timeGap;
  882. speed.y = differenceY / timeGap;
  883. startTime = currentTime;
  884. }
  885. if (shouldPreventDefault(differenceX, differenceY)) {
  886. e.stopPropagation();
  887. e.preventDefault();
  888. }
  889. }
  890. }
  891. function touchEnd() {
  892. if (!inGlobalTouch && inLocalTouch) {
  893. inLocalTouch = false;
  894. clearInterval(easingLoop);
  895. easingLoop = setInterval(function () {
  896. if (!instances.get(element)) {
  897. clearInterval(easingLoop);
  898. return;
  899. }
  900. if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
  901. clearInterval(easingLoop);
  902. return;
  903. }
  904. applyTouchMove(speed.x * 30, speed.y * 30);
  905. speed.x *= 0.8;
  906. speed.y *= 0.8;
  907. }, 10);
  908. }
  909. }
  910. if (supportsTouch) {
  911. i.event.bind(window, 'touchstart', globalTouchStart);
  912. i.event.bind(window, 'touchend', globalTouchEnd);
  913. i.event.bind(element, 'touchstart', touchStart);
  914. i.event.bind(element, 'touchmove', touchMove);
  915. i.event.bind(element, 'touchend', touchEnd);
  916. }
  917. if (supportsIePointer) {
  918. if (window.PointerEvent) {
  919. i.event.bind(window, 'pointerdown', globalTouchStart);
  920. i.event.bind(window, 'pointerup', globalTouchEnd);
  921. i.event.bind(element, 'pointerdown', touchStart);
  922. i.event.bind(element, 'pointermove', touchMove);
  923. i.event.bind(element, 'pointerup', touchEnd);
  924. } else if (window.MSPointerEvent) {
  925. i.event.bind(window, 'MSPointerDown', globalTouchStart);
  926. i.event.bind(window, 'MSPointerUp', globalTouchEnd);
  927. i.event.bind(element, 'MSPointerDown', touchStart);
  928. i.event.bind(element, 'MSPointerMove', touchMove);
  929. i.event.bind(element, 'MSPointerUp', touchEnd);
  930. }
  931. }
  932. }
  933. module.exports = function (element, supportsTouch, supportsIePointer) {
  934. var i = instances.get(element);
  935. bindTouchHandler(element, i, supportsTouch, supportsIePointer);
  936. };
  937. },{"../instances":18,"../update-geometry":19}],17:[function(require,module,exports){
  938. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  939. * Licensed under the MIT License
  940. */
  941. 'use strict';
  942. var cls = require('../lib/class')
  943. , h = require('../lib/helper')
  944. , instances = require('./instances')
  945. , updateGeometry = require('./update-geometry');
  946. // Handlers
  947. var clickRailHandler = require('./handler/click-rail')
  948. , dragScrollbarHandler = require('./handler/drag-scrollbar')
  949. , keyboardHandler = require('./handler/keyboard')
  950. , mouseWheelHandler = require('./handler/mouse-wheel')
  951. , nativeScrollHandler = require('./handler/native-scroll')
  952. , selectionHandler = require('./handler/selection')
  953. , touchHandler = require('./handler/touch');
  954. module.exports = function (element, userSettings) {
  955. userSettings = typeof userSettings === 'object' ? userSettings : {};
  956. cls.add(element, 'ps-container');
  957. // Create a plugin instance.
  958. var i = instances.add(element);
  959. i.settings = h.extend(i.settings, userSettings);
  960. clickRailHandler(element);
  961. dragScrollbarHandler(element);
  962. mouseWheelHandler(element);
  963. nativeScrollHandler(element);
  964. selectionHandler(element);
  965. if (h.env.supportsTouch || h.env.supportsIePointer) {
  966. touchHandler(element, h.env.supportsTouch, h.env.supportsIePointer);
  967. }
  968. if (i.settings.useKeyboard) {
  969. keyboardHandler(element);
  970. }
  971. updateGeometry(element);
  972. };
  973. },{"../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){
  974. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  975. * Licensed under the MIT License
  976. */
  977. 'use strict';
  978. var d = require('../lib/dom')
  979. , defaultSettings = require('./default-setting')
  980. , EventManager = require('../lib/event-manager')
  981. , guid = require('../lib/guid')
  982. , h = require('../lib/helper');
  983. var instances = {};
  984. function Instance(element) {
  985. var i = this;
  986. i.settings = h.clone(defaultSettings);
  987. i.containerWidth = null;
  988. i.containerHeight = null;
  989. i.contentWidth = null;
  990. i.contentHeight = null;
  991. i.isRtl = d.css(element, 'direction') === "rtl";
  992. i.event = new EventManager();
  993. i.ownerDocument = element.ownerDocument || document;
  994. i.scrollbarXRail = d.appendTo(d.e('div', 'ps-scrollbar-x-rail'), element);
  995. i.scrollbarX = d.appendTo(d.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
  996. i.scrollbarXActive = null;
  997. i.scrollbarXWidth = null;
  998. i.scrollbarXLeft = null;
  999. i.scrollbarXBottom = h.toInt(d.css(i.scrollbarXRail, 'bottom'));
  1000. i.isScrollbarXUsingBottom = i.scrollbarXBottom === i.scrollbarXBottom; // !isNaN
  1001. i.scrollbarXTop = i.isScrollbarXUsingBottom ? null : h.toInt(d.css(i.scrollbarXRail, 'top'));
  1002. i.railBorderXWidth = h.toInt(d.css(i.scrollbarXRail, 'borderLeftWidth')) + h.toInt(d.css(i.scrollbarXRail, 'borderRightWidth'));
  1003. i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
  1004. i.railXWidth = null;
  1005. i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
  1006. i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
  1007. i.scrollbarYActive = null;
  1008. i.scrollbarYHeight = null;
  1009. i.scrollbarYTop = null;
  1010. i.scrollbarYRight = h.toInt(d.css(i.scrollbarYRail, 'right'));
  1011. i.isScrollbarYUsingRight = i.scrollbarYRight === i.scrollbarYRight; // !isNaN
  1012. i.scrollbarYLeft = i.isScrollbarYUsingRight ? null : h.toInt(d.css(i.scrollbarYRail, 'left'));
  1013. i.scrollbarYOuterWidth = i.isRtl ? h.outerWidth(i.scrollbarY) : null;
  1014. i.railBorderYWidth = h.toInt(d.css(i.scrollbarYRail, 'borderTopWidth')) + h.toInt(d.css(i.scrollbarYRail, 'borderBottomWidth'));
  1015. i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
  1016. i.railYHeight = null;
  1017. }
  1018. function getId(element) {
  1019. if (typeof element.dataset === 'undefined') {
  1020. return element.getAttribute('data-ps-id');
  1021. } else {
  1022. return element.dataset.psId;
  1023. }
  1024. }
  1025. function setId(element, id) {
  1026. if (typeof element.dataset === 'undefined') {
  1027. element.setAttribute('data-ps-id', id);
  1028. } else {
  1029. element.dataset.psId = id;
  1030. }
  1031. }
  1032. function removeId(element) {
  1033. if (typeof element.dataset === 'undefined') {
  1034. element.removeAttribute('data-ps-id');
  1035. } else {
  1036. delete element.dataset.psId;
  1037. }
  1038. }
  1039. exports.add = function (element) {
  1040. var newId = guid();
  1041. setId(element, newId);
  1042. instances[newId] = new Instance(element);
  1043. return instances[newId];
  1044. };
  1045. exports.remove = function (element) {
  1046. delete instances[getId(element)];
  1047. removeId(element);
  1048. };
  1049. exports.get = function (element) {
  1050. return instances[getId(element)];
  1051. };
  1052. },{"../lib/dom":3,"../lib/event-manager":4,"../lib/guid":5,"../lib/helper":6,"./default-setting":8}],19:[function(require,module,exports){
  1053. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  1054. * Licensed under the MIT License
  1055. */
  1056. 'use strict';
  1057. var cls = require('../lib/class')
  1058. , d = require('../lib/dom')
  1059. , h = require('../lib/helper')
  1060. , instances = require('./instances');
  1061. function getThumbSize(i, thumbSize) {
  1062. if (i.settings.minScrollbarLength) {
  1063. thumbSize = Math.max(thumbSize, i.settings.minScrollbarLength);
  1064. }
  1065. if (i.settings.maxScrollbarLength) {
  1066. thumbSize = Math.min(thumbSize, i.settings.maxScrollbarLength);
  1067. }
  1068. return thumbSize;
  1069. }
  1070. function updateCss(element, i) {
  1071. var xRailOffset = {width: i.railXWidth};
  1072. if (i.isRtl) {
  1073. xRailOffset.left = element.scrollLeft + i.containerWidth - i.contentWidth;
  1074. } else {
  1075. xRailOffset.left = element.scrollLeft;
  1076. }
  1077. if (i.isScrollbarXUsingBottom) {
  1078. xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
  1079. } else {
  1080. xRailOffset.top = i.scrollbarXTop + element.scrollTop;
  1081. }
  1082. d.css(i.scrollbarXRail, xRailOffset);
  1083. var yRailOffset = {top: element.scrollTop, height: i.railYHeight};
  1084. if (i.isScrollbarYUsingRight) {
  1085. if (i.isRtl) {
  1086. yRailOffset.right = i.contentWidth - element.scrollLeft - i.scrollbarYRight - i.scrollbarYOuterWidth;
  1087. } else {
  1088. yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
  1089. }
  1090. } else {
  1091. if (i.isRtl) {
  1092. yRailOffset.left = element.scrollLeft + i.containerWidth * 2 - i.contentWidth - i.scrollbarYLeft - i.scrollbarYOuterWidth;
  1093. } else {
  1094. yRailOffset.left = i.scrollbarYLeft + element.scrollLeft;
  1095. }
  1096. }
  1097. d.css(i.scrollbarYRail, yRailOffset);
  1098. d.css(i.scrollbarX, {left: i.scrollbarXLeft, width: i.scrollbarXWidth - i.railBorderXWidth});
  1099. d.css(i.scrollbarY, {top: i.scrollbarYTop, height: i.scrollbarYHeight - i.railBorderYWidth});
  1100. }
  1101. module.exports = function (element) {
  1102. var i = instances.get(element);
  1103. i.containerWidth = element.clientWidth;
  1104. i.containerHeight = element.clientHeight;
  1105. i.contentWidth = element.scrollWidth;
  1106. i.contentHeight = element.scrollHeight;
  1107. if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
  1108. i.scrollbarXActive = true;
  1109. i.railXWidth = i.containerWidth - i.railXMarginWidth;
  1110. i.scrollbarXWidth = getThumbSize(i, h.toInt(i.railXWidth * i.containerWidth / i.contentWidth));
  1111. i.scrollbarXLeft = h.toInt(element.scrollLeft * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
  1112. } else {
  1113. i.scrollbarXActive = false;
  1114. i.scrollbarXWidth = 0;
  1115. i.scrollbarXLeft = 0;
  1116. element.scrollLeft = 0;
  1117. }
  1118. if (!i.settings.suppressScrollY && i.containerHeight + i.settings.scrollYMarginOffset < i.contentHeight) {
  1119. i.scrollbarYActive = true;
  1120. i.railYHeight = i.containerHeight - i.railYMarginHeight;
  1121. i.scrollbarYHeight = getThumbSize(i, h.toInt(i.railYHeight * i.containerHeight / i.contentHeight));
  1122. i.scrollbarYTop = h.toInt(element.scrollTop * (i.railYHeight - i.scrollbarYHeight) / (i.contentHeight - i.containerHeight));
  1123. } else {
  1124. i.scrollbarYActive = false;
  1125. i.scrollbarYHeight = 0;
  1126. i.scrollbarYTop = 0;
  1127. element.scrollTop = 0;
  1128. }
  1129. if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
  1130. i.scrollbarXLeft = i.railXWidth - i.scrollbarXWidth;
  1131. }
  1132. if (i.scrollbarYTop >= i.railYHeight - i.scrollbarYHeight) {
  1133. i.scrollbarYTop = i.railYHeight - i.scrollbarYHeight;
  1134. }
  1135. updateCss(element, i);
  1136. cls[i.scrollbarXActive ? 'add' : 'remove'](element, 'ps-active-x');
  1137. cls[i.scrollbarYActive ? 'add' : 'remove'](element, 'ps-active-y');
  1138. };
  1139. },{"../lib/class":2,"../lib/dom":3,"../lib/helper":6,"./instances":18}],20:[function(require,module,exports){
  1140. /* Copyright (c) 2015 Hyunje Alex Jun and other contributors
  1141. * Licensed under the MIT License
  1142. */
  1143. 'use strict';
  1144. var d = require('../lib/dom')
  1145. , destroy = require('./destroy')
  1146. , initialize = require('./initialize')
  1147. , instances = require('./instances')
  1148. , updateGeometry = require('./update-geometry');
  1149. module.exports = function (element) {
  1150. var i = instances.get(element);
  1151. if (!i.scrollbarXRail || !element.contains(i.scrollbarXRail) ||
  1152. !i.scrollbarYRail || !element.contains(i.scrollbarYRail)) {
  1153. // If there's something wrong in the plugin, re-initialise.
  1154. destroy(element);
  1155. initialize(element);
  1156. } else {
  1157. // Hide scrollbars not to affect scrollWidth and scrollHeight
  1158. d.css(i.scrollbarXRail, 'display', 'none');
  1159. d.css(i.scrollbarYRail, 'display', 'none');
  1160. updateGeometry(element);
  1161. d.css(i.scrollbarXRail, 'display', 'block');
  1162. d.css(i.scrollbarYRail, 'display', 'block');
  1163. }
  1164. };
  1165. },{"../lib/dom":3,"./destroy":9,"./initialize":17,"./instances":18,"./update-geometry":19}]},{},[1]);