perfect-scrollbar.jquery.js 40 KB

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