You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2197 lines
54 KiB

  1. /*! iScroll v5.2.0-snapshot ~ (c) 2008-2017 Matteo Spinelli ~ http://cubiq.org/license */
  2. (function (window, document, Math) {
  3. var rAF = window.requestAnimationFrame ||
  4. window.webkitRequestAnimationFrame ||
  5. window.mozRequestAnimationFrame ||
  6. window.oRequestAnimationFrame ||
  7. window.msRequestAnimationFrame ||
  8. function (callback) { window.setTimeout(callback, 1000 / 60); };
  9. var utils = (function () {
  10. var me = {};
  11. var _elementStyle = document.createElement('div').style;
  12. var _vendor = (function () {
  13. var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'],
  14. transform,
  15. i = 0,
  16. l = vendors.length;
  17. for ( ; i < l; i++ ) {
  18. transform = vendors[i] + 'ransform';
  19. if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1);
  20. }
  21. return false;
  22. })();
  23. function _prefixStyle (style) {
  24. if ( _vendor === false ) return false;
  25. if ( _vendor === '' ) return style;
  26. return _vendor + style.charAt(0).toUpperCase() + style.substr(1);
  27. }
  28. me.getTime = Date.now || function getTime () { return new Date().getTime(); };
  29. me.extend = function (target, obj) {
  30. for ( var i in obj ) {
  31. target[i] = obj[i];
  32. }
  33. };
  34. me.addEvent = function (el, type, fn, capture) {
  35. el.addEventListener(type, fn, !!capture);
  36. };
  37. me.removeEvent = function (el, type, fn, capture) {
  38. el.removeEventListener(type, fn, !!capture);
  39. };
  40. me.prefixPointerEvent = function (pointerEvent) {
  41. return window.MSPointerEvent ?
  42. 'MSPointer' + pointerEvent.charAt(7).toUpperCase() + pointerEvent.substr(8):
  43. pointerEvent;
  44. };
  45. me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) {
  46. var distance = current - start,
  47. speed = Math.abs(distance) / time,
  48. destination,
  49. duration;
  50. deceleration = deceleration === undefined ? 0.0006 : deceleration;
  51. destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
  52. duration = speed / deceleration;
  53. if ( destination < lowerMargin ) {
  54. destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
  55. distance = Math.abs(destination - current);
  56. duration = distance / speed;
  57. } else if ( destination > 0 ) {
  58. destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
  59. distance = Math.abs(current) + destination;
  60. duration = distance / speed;
  61. }
  62. return {
  63. destination: Math.round(destination),
  64. duration: duration
  65. };
  66. };
  67. var _transform = _prefixStyle('transform');
  68. me.extend(me, {
  69. hasTransform: _transform !== false,
  70. hasPerspective: _prefixStyle('perspective') in _elementStyle,
  71. hasTouch: 'ontouchstart' in window,
  72. hasPointer: !!(window.PointerEvent || window.MSPointerEvent), // IE10 is prefixed
  73. hasTransition: _prefixStyle('transition') in _elementStyle
  74. });
  75. /*
  76. This should find all Android browsers lower than build 535.19 (both stock browser and webview)
  77. - galaxy S2 is ok
  78. - 2.3.6 : `AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1`
  79. - 4.0.4 : `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
  80. - galaxy S3 is badAndroid (stock brower, webview)
  81. `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
  82. - galaxy S4 is badAndroid (stock brower, webview)
  83. `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
  84. - galaxy S5 is OK
  85. `AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
  86. - galaxy S6 is OK
  87. `AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
  88. */
  89. me.isBadAndroid = (function() {
  90. var appVersion = window.navigator.appVersion;
  91. // Android browser is not a chrome browser.
  92. if (/Android/.test(appVersion) && !(/Chrome\/\d/.test(appVersion))) {
  93. var safariVersion = appVersion.match(/Safari\/(\d+.\d)/);
  94. if(safariVersion && typeof safariVersion === "object" && safariVersion.length >= 2) {
  95. return parseFloat(safariVersion[1]) < 535.19;
  96. } else {
  97. return true;
  98. }
  99. } else {
  100. return false;
  101. }
  102. })();
  103. me.extend(me.style = {}, {
  104. transform: _transform,
  105. transitionTimingFunction: _prefixStyle('transitionTimingFunction'),
  106. transitionDuration: _prefixStyle('transitionDuration'),
  107. transitionDelay: _prefixStyle('transitionDelay'),
  108. transformOrigin: _prefixStyle('transformOrigin'),
  109. touchAction: _prefixStyle('touchAction')
  110. });
  111. me.hasClass = function (e, c) {
  112. var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
  113. return re.test(e.className);
  114. };
  115. me.addClass = function (e, c) {
  116. if ( me.hasClass(e, c) ) {
  117. return;
  118. }
  119. var newclass = e.className.split(' ');
  120. newclass.push(c);
  121. e.className = newclass.join(' ');
  122. };
  123. me.removeClass = function (e, c) {
  124. if ( !me.hasClass(e, c) ) {
  125. return;
  126. }
  127. var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g');
  128. e.className = e.className.replace(re, ' ');
  129. };
  130. me.offset = function (el) {
  131. var left = -el.offsetLeft,
  132. top = -el.offsetTop;
  133. // jshint -W084
  134. while (el = el.offsetParent) {
  135. left -= el.offsetLeft;
  136. top -= el.offsetTop;
  137. }
  138. // jshint +W084
  139. return {
  140. left: left,
  141. top: top
  142. };
  143. };
  144. me.preventDefaultException = function (el, exceptions) {
  145. for ( var i in exceptions ) {
  146. if ( exceptions[i].test(el[i]) ) {
  147. return true;
  148. }
  149. }
  150. return false;
  151. };
  152. me.extend(me.eventType = {}, {
  153. touchstart: 1,
  154. touchmove: 1,
  155. touchend: 1,
  156. mousedown: 2,
  157. mousemove: 2,
  158. mouseup: 2,
  159. pointerdown: 3,
  160. pointermove: 3,
  161. pointerup: 3,
  162. MSPointerDown: 3,
  163. MSPointerMove: 3,
  164. MSPointerUp: 3
  165. });
  166. me.extend(me.ease = {}, {
  167. quadratic: {
  168. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  169. fn: function (k) {
  170. return k * ( 2 - k );
  171. }
  172. },
  173. circular: {
  174. style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1)
  175. fn: function (k) {
  176. return Math.sqrt( 1 - ( --k * k ) );
  177. }
  178. },
  179. back: {
  180. style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)',
  181. fn: function (k) {
  182. var b = 4;
  183. return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1;
  184. }
  185. },
  186. bounce: {
  187. style: '',
  188. fn: function (k) {
  189. if ( ( k /= 1 ) < ( 1 / 2.75 ) ) {
  190. return 7.5625 * k * k;
  191. } else if ( k < ( 2 / 2.75 ) ) {
  192. return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
  193. } else if ( k < ( 2.5 / 2.75 ) ) {
  194. return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
  195. } else {
  196. return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
  197. }
  198. }
  199. },
  200. elastic: {
  201. style: '',
  202. fn: function (k) {
  203. var f = 0.22,
  204. e = 0.4;
  205. if ( k === 0 ) { return 0; }
  206. if ( k == 1 ) { return 1; }
  207. return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 );
  208. }
  209. }
  210. });
  211. me.tap = function (e, eventName) {
  212. var ev = document.createEvent('Event');
  213. ev.initEvent(eventName, true, true);
  214. ev.pageX = e.pageX;
  215. ev.pageY = e.pageY;
  216. e.target.dispatchEvent(ev);
  217. };
  218. me.click = function (e) {
  219. var target = e.target,
  220. ev;
  221. if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
  222. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
  223. // initMouseEvent is deprecated.
  224. ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
  225. ev.initEvent('click', true, true);
  226. ev.view = e.view || window;
  227. ev.detail = 1;
  228. ev.screenX = target.screenX || 0;
  229. ev.screenY = target.screenY || 0;
  230. ev.clientX = target.clientX || 0;
  231. ev.clientY = target.clientY || 0;
  232. ev.ctrlKey = !!e.ctrlKey;
  233. ev.altKey = !!e.altKey;
  234. ev.shiftKey = !!e.shiftKey;
  235. ev.metaKey = !!e.metaKey;
  236. ev.button = 0;
  237. ev.relatedTarget = null;
  238. ev._constructed = true;
  239. target.dispatchEvent(ev);
  240. }
  241. };
  242. me.getTouchAction = function(eventPassthrough, addPinch) {
  243. var touchAction = 'none';
  244. if ( eventPassthrough === 'vertical' ) {
  245. touchAction = 'pan-y';
  246. } else if (eventPassthrough === 'horizontal' ) {
  247. touchAction = 'pan-x';
  248. }
  249. if (addPinch && touchAction != 'none') {
  250. // add pinch-zoom support if the browser supports it, but if not (eg. Chrome <55) do nothing
  251. touchAction += ' pinch-zoom';
  252. }
  253. return touchAction;
  254. };
  255. me.getRect = function(el) {
  256. if (el instanceof SVGElement) {
  257. var rect = el.getBoundingClientRect();
  258. return {
  259. top : rect.top,
  260. left : rect.left,
  261. width : rect.width,
  262. height : rect.height
  263. };
  264. } else {
  265. return {
  266. top : el.offsetTop,
  267. left : el.offsetLeft,
  268. width : el.offsetWidth,
  269. height : el.offsetHeight
  270. };
  271. }
  272. };
  273. return me;
  274. })();
  275. function IScroll (el, options) {
  276. this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
  277. this.scroller = this.wrapper.children[0];
  278. this.scrollerStyle = this.scroller.style; // cache style for better performance
  279. this.options = {
  280. resizeScrollbars: true,
  281. mouseWheelSpeed: 20,
  282. snapThreshold: 0.334,
  283. // INSERT POINT: OPTIONS
  284. disablePointer : !utils.hasPointer,
  285. disableTouch : utils.hasPointer || !utils.hasTouch,
  286. disableMouse : utils.hasPointer || utils.hasTouch,
  287. startX: 0,
  288. startY: 0,
  289. scrollY: true,
  290. directionLockThreshold: 5,
  291. momentum: true,
  292. bounce: true,
  293. bounceTime: 600,
  294. bounceEasing: '',
  295. preventDefault: true,
  296. preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },
  297. HWCompositing: true,
  298. useTransition: true,
  299. useTransform: true,
  300. bindToWrapper: typeof window.onmousedown === "undefined"
  301. };
  302. for ( var i in options ) {
  303. this.options[i] = options[i];
  304. }
  305. // Normalize options
  306. this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : '';
  307. this.options.useTransition = utils.hasTransition && this.options.useTransition;
  308. this.options.useTransform = utils.hasTransform && this.options.useTransform;
  309. this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough;
  310. this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault;
  311. // If you want eventPassthrough I have to lock one of the axes
  312. this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY;
  313. this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX;
  314. // With eventPassthrough we also need lockDirection mechanism
  315. this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough;
  316. this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold;
  317. this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing;
  318. this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling;
  319. if ( this.options.tap === true ) {
  320. this.options.tap = 'tap';
  321. }
  322. // https://github.com/cubiq/iscroll/issues/1029
  323. if (!this.options.useTransition && !this.options.useTransform) {
  324. if(!(/relative|absolute/i).test(this.scrollerStyle.position)) {
  325. this.scrollerStyle.position = "relative";
  326. }
  327. }
  328. if ( this.options.shrinkScrollbars == 'scale' ) {
  329. this.options.useTransition = false;
  330. }
  331. this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1;
  332. if ( this.options.probeType == 3 ) {
  333. this.options.useTransition = false; }
  334. // INSERT POINT: NORMALIZATION
  335. // Some defaults
  336. this.x = 0;
  337. this.y = 0;
  338. this.directionX = 0;
  339. this.directionY = 0;
  340. this._events = {};
  341. // INSERT POINT: DEFAULTS
  342. this._init();
  343. this.refresh();
  344. this.scrollTo(this.options.startX, this.options.startY);
  345. this.enable();
  346. }
  347. IScroll.prototype = {
  348. version: '5.2.0-snapshot',
  349. _init: function () {
  350. this._initEvents();
  351. if ( this.options.scrollbars || this.options.indicators ) {
  352. this._initIndicators();
  353. }
  354. if ( this.options.mouseWheel ) {
  355. this._initWheel();
  356. }
  357. if ( this.options.snap ) {
  358. this._initSnap();
  359. }
  360. if ( this.options.keyBindings ) {
  361. this._initKeys();
  362. }
  363. // INSERT POINT: _init
  364. },
  365. destroy: function () {
  366. this._initEvents(true);
  367. clearTimeout(this.resizeTimeout);
  368. this.resizeTimeout = null;
  369. this._execEvent('destroy');
  370. },
  371. _transitionEnd: function (e) {
  372. if ( e.target != this.scroller || !this.isInTransition ) {
  373. return;
  374. }
  375. this._transitionTime();
  376. if ( !this.resetPosition(this.options.bounceTime) ) {
  377. this.isInTransition = false;
  378. this._execEvent('scrollEnd');
  379. }
  380. },
  381. _start: function (e) {
  382. // React to left mouse button only
  383. if ( utils.eventType[e.type] != 1 ) {
  384. // for button property
  385. // http://unixpapa.com/js/mouse.html
  386. var button;
  387. if (!e.which) {
  388. /* IE case */
  389. button = (e.button < 2) ? 0 :
  390. ((e.button == 4) ? 1 : 2);
  391. } else {
  392. /* All others */
  393. button = e.button;
  394. }
  395. if ( button !== 0 ) {
  396. return;
  397. }
  398. }
  399. if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) {
  400. return;
  401. }
  402. if ( this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
  403. e.preventDefault();
  404. }
  405. var point = e.touches ? e.touches[0] : e,
  406. pos;
  407. this.initiated = utils.eventType[e.type];
  408. this.moved = false;
  409. this.distX = 0;
  410. this.distY = 0;
  411. this.directionX = 0;
  412. this.directionY = 0;
  413. this.directionLocked = 0;
  414. this.startTime = utils.getTime();
  415. if ( this.options.useTransition && this.isInTransition ) {
  416. this._transitionTime();
  417. this.isInTransition = false;
  418. pos = this.getComputedPosition();
  419. this._translate(Math.round(pos.x), Math.round(pos.y));
  420. this._execEvent('scrollEnd');
  421. } else if ( !this.options.useTransition && this.isAnimating ) {
  422. this.isAnimating = false;
  423. this._execEvent('scrollEnd');
  424. }
  425. this.startX = this.x;
  426. this.startY = this.y;
  427. this.absStartX = this.x;
  428. this.absStartY = this.y;
  429. this.pointX = point.pageX;
  430. this.pointY = point.pageY;
  431. this._execEvent('beforeScrollStart');
  432. },
  433. _move: function (e) {
  434. if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) {
  435. return;
  436. }
  437. if ( this.options.preventDefault ) { // increases performance on Android? TODO: check!
  438. e.preventDefault();
  439. }
  440. var point = e.touches ? e.touches[0] : e,
  441. deltaX = point.pageX - this.pointX,
  442. deltaY = point.pageY - this.pointY,
  443. timestamp = utils.getTime(),
  444. newX, newY,
  445. absDistX, absDistY;
  446. this.pointX = point.pageX;
  447. this.pointY = point.pageY;
  448. this.distX += deltaX;
  449. this.distY += deltaY;
  450. absDistX = Math.abs(this.distX);
  451. absDistY = Math.abs(this.distY);
  452. // We need to move at least 10 pixels for the scrolling to initiate
  453. if ( timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10) ) {
  454. return;
  455. }
  456. // If you are scrolling in one direction lock the other
  457. if ( !this.directionLocked && !this.options.freeScroll ) {
  458. if ( absDistX > absDistY + this.options.directionLockThreshold ) {
  459. this.directionLocked = 'h'; // lock horizontally
  460. } else if ( absDistY >= absDistX + this.options.directionLockThreshold ) {
  461. this.directionLocked = 'v'; // lock vertically
  462. } else {
  463. this.directionLocked = 'n'; // no lock
  464. }
  465. }
  466. if ( this.directionLocked == 'h' ) {
  467. if ( this.options.eventPassthrough == 'vertical' ) {
  468. e.preventDefault();
  469. } else if ( this.options.eventPassthrough == 'horizontal' ) {
  470. this.initiated = false;
  471. return;
  472. }
  473. deltaY = 0;
  474. } else if ( this.directionLocked == 'v' ) {
  475. if ( this.options.eventPassthrough == 'horizontal' ) {
  476. e.preventDefault();
  477. } else if ( this.options.eventPassthrough == 'vertical' ) {
  478. this.initiated = false;
  479. return;
  480. }
  481. deltaX = 0;
  482. }
  483. deltaX = this.hasHorizontalScroll ? deltaX : 0;
  484. deltaY = this.hasVerticalScroll ? deltaY : 0;
  485. newX = this.x + deltaX;
  486. newY = this.y + deltaY;
  487. // Slow down if outside of the boundaries
  488. if ( newX > 0 || newX < this.maxScrollX ) {
  489. newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX;
  490. }
  491. if ( newY > 0 || newY < this.maxScrollY ) {
  492. newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY;
  493. }
  494. this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
  495. this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
  496. if ( !this.moved ) {
  497. this._execEvent('scrollStart');
  498. }
  499. this.moved = true;
  500. this._translate(newX, newY);
  501. /* REPLACE START: _move */
  502. if ( timestamp - this.startTime > 300 ) {
  503. this.startTime = timestamp;
  504. this.startX = this.x;
  505. this.startY = this.y;
  506. if ( this.options.probeType == 1 ) {
  507. this._execEvent('scroll');
  508. }
  509. }
  510. if ( this.options.probeType > 1 ) {
  511. this._execEvent('scroll');
  512. }
  513. /* REPLACE END: _move */
  514. },
  515. _end: function (e) {
  516. if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) {
  517. return;
  518. }
  519. if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
  520. e.preventDefault();
  521. }
  522. var point = e.changedTouches ? e.changedTouches[0] : e,
  523. momentumX,
  524. momentumY,
  525. duration = utils.getTime() - this.startTime,
  526. newX = Math.round(this.x),
  527. newY = Math.round(this.y),
  528. distanceX = Math.abs(newX - this.startX),
  529. distanceY = Math.abs(newY - this.startY),
  530. time = 0,
  531. easing = '';
  532. this.isInTransition = 0;
  533. this.initiated = 0;
  534. this.endTime = utils.getTime();
  535. // reset if we are outside of the boundaries
  536. if ( this.resetPosition(this.options.bounceTime) ) {
  537. return;
  538. }
  539. this.scrollTo(newX, newY); // ensures that the last position is rounded
  540. // we scrolled less than 10 pixels
  541. if ( !this.moved ) {
  542. if ( this.options.tap ) {
  543. utils.tap(e, this.options.tap);
  544. }
  545. if ( this.options.click ) {
  546. utils.click(e);
  547. }
  548. this._execEvent('scrollCancel');
  549. return;
  550. }
  551. if ( this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) {
  552. this._execEvent('flick');
  553. return;
  554. }
  555. // start momentum animation if needed
  556. if ( this.options.momentum && duration < 300 ) {
  557. momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : { destination: newX, duration: 0 };
  558. momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : { destination: newY, duration: 0 };
  559. newX = momentumX.destination;
  560. newY = momentumY.destination;
  561. time = Math.max(momentumX.duration, momentumY.duration);
  562. this.isInTransition = 1;
  563. }
  564. if ( this.options.snap ) {
  565. var snap = this._nearestSnap(newX, newY);
  566. this.currentPage = snap;
  567. time = this.options.snapSpeed || Math.max(
  568. Math.max(
  569. Math.min(Math.abs(newX - snap.x), 1000),
  570. Math.min(Math.abs(newY - snap.y), 1000)
  571. ), 300);
  572. newX = snap.x;
  573. newY = snap.y;
  574. this.directionX = 0;
  575. this.directionY = 0;
  576. easing = this.options.bounceEasing;
  577. }
  578. // INSERT POINT: _end
  579. if ( newX != this.x || newY != this.y ) {
  580. // change easing function when scroller goes out of the boundaries
  581. if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) {
  582. easing = utils.ease.quadratic;
  583. }
  584. this.scrollTo(newX, newY, time, easing);
  585. return;
  586. }
  587. this._execEvent('scrollEnd');
  588. },
  589. _resize: function () {
  590. var that = this;
  591. clearTimeout(this.resizeTimeout);
  592. this.resizeTimeout = setTimeout(function () {
  593. that.refresh();
  594. }, this.options.resizePolling);
  595. },
  596. resetPosition: function (time) {
  597. var x = this.x,
  598. y = this.y;
  599. time = time || 0;
  600. if ( !this.hasHorizontalScroll || this.x > 0 ) {
  601. x = 0;
  602. } else if ( this.x < this.maxScrollX ) {
  603. x = this.maxScrollX;
  604. }
  605. if ( !this.hasVerticalScroll || this.y > 0 ) {
  606. y = 0;
  607. } else if ( this.y < this.maxScrollY ) {
  608. y = this.maxScrollY;
  609. }
  610. if ( x == this.x && y == this.y ) {
  611. return false;
  612. }
  613. this.scrollTo(x, y, time, this.options.bounceEasing);
  614. return true;
  615. },
  616. disable: function () {
  617. this.enabled = false;
  618. },
  619. enable: function () {
  620. this.enabled = true;
  621. },
  622. refresh: function () {
  623. utils.getRect(this.wrapper); // Force reflow
  624. this.wrapperWidth = this.wrapper.clientWidth;
  625. this.wrapperHeight = this.wrapper.clientHeight;
  626. var rect = utils.getRect(this.scroller);
  627. /* REPLACE START: refresh */
  628. this.scrollerWidth = rect.width;
  629. this.scrollerHeight = rect.height;
  630. this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
  631. this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
  632. /* REPLACE END: refresh */
  633. this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
  634. this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
  635. if ( !this.hasHorizontalScroll ) {
  636. this.maxScrollX = 0;
  637. this.scrollerWidth = this.wrapperWidth;
  638. }
  639. if ( !this.hasVerticalScroll ) {
  640. this.maxScrollY = 0;
  641. this.scrollerHeight = this.wrapperHeight;
  642. }
  643. this.endTime = 0;
  644. this.directionX = 0;
  645. this.directionY = 0;
  646. if(utils.hasPointer && !this.options.disablePointer) {
  647. // The wrapper should have `touchAction` property for using pointerEvent.
  648. this.wrapper.style[utils.style.touchAction] = utils.getTouchAction(this.options.eventPassthrough, true);
  649. // case. not support 'pinch-zoom'
  650. // https://github.com/cubiq/iscroll/issues/1118#issuecomment-270057583
  651. if (!this.wrapper.style[utils.style.touchAction]) {
  652. this.wrapper.style[utils.style.touchAction] = utils.getTouchAction(this.options.eventPassthrough, false);
  653. }
  654. }
  655. this.wrapperOffset = utils.offset(this.wrapper);
  656. this._execEvent('refresh');
  657. this.resetPosition();
  658. // INSERT POINT: _refresh
  659. },
  660. on: function (type, fn) {
  661. if ( !this._events[type] ) {
  662. this._events[type] = [];
  663. }
  664. this._events[type].push(fn);
  665. },
  666. off: function (type, fn) {
  667. if ( !this._events[type] ) {
  668. return;
  669. }
  670. var index = this._events[type].indexOf(fn);
  671. if ( index > -1 ) {
  672. this._events[type].splice(index, 1);
  673. }
  674. },
  675. _execEvent: function (type) {
  676. if ( !this._events[type] ) {
  677. return;
  678. }
  679. var i = 0,
  680. l = this._events[type].length;
  681. if ( !l ) {
  682. return;
  683. }
  684. for ( ; i < l; i++ ) {
  685. this._events[type][i].apply(this, [].slice.call(arguments, 1));
  686. }
  687. },
  688. scrollBy: function (x, y, time, easing) {
  689. x = this.x + x;
  690. y = this.y + y;
  691. time = time || 0;
  692. this.scrollTo(x, y, time, easing);
  693. },
  694. scrollTo: function (x, y, time, easing) {
  695. easing = easing || utils.ease.circular;
  696. this.isInTransition = this.options.useTransition && time > 0;
  697. var transitionType = this.options.useTransition && easing.style;
  698. if ( !time || transitionType ) {
  699. if(transitionType) {
  700. this._transitionTimingFunction(easing.style);
  701. this._transitionTime(time);
  702. }
  703. this._translate(x, y);
  704. } else {
  705. this._animate(x, y, time, easing.fn);
  706. }
  707. },
  708. scrollToElement: function (el, time, offsetX, offsetY, easing) {
  709. el = el.nodeType ? el : this.scroller.querySelector(el);
  710. if ( !el ) {
  711. return;
  712. }
  713. var pos = utils.offset(el);
  714. pos.left -= this.wrapperOffset.left;
  715. pos.top -= this.wrapperOffset.top;
  716. // if offsetX/Y are true we center the element to the screen
  717. var elRect = utils.getRect(el);
  718. var wrapperRect = utils.getRect(this.wrapper);
  719. if ( offsetX === true ) {
  720. offsetX = Math.round(elRect.width / 2 - wrapperRect.width / 2);
  721. }
  722. if ( offsetY === true ) {
  723. offsetY = Math.round(elRect.height / 2 - wrapperRect.height / 2);
  724. }
  725. pos.left -= offsetX || 0;
  726. pos.top -= offsetY || 0;
  727. pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
  728. pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;
  729. time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time;
  730. this.scrollTo(pos.left, pos.top, time, easing);
  731. },
  732. _transitionTime: function (time) {
  733. if (!this.options.useTransition) {
  734. return;
  735. }
  736. time = time || 0;
  737. var durationProp = utils.style.transitionDuration;
  738. if(!durationProp) {
  739. return;
  740. }
  741. this.scrollerStyle[durationProp] = time + 'ms';
  742. if ( !time && utils.isBadAndroid ) {
  743. this.scrollerStyle[durationProp] = '0.0001ms';
  744. // remove 0.0001ms
  745. var self = this;
  746. rAF(function() {
  747. if(self.scrollerStyle[durationProp] === '0.0001ms') {
  748. self.scrollerStyle[durationProp] = '0s';
  749. }
  750. });
  751. }
  752. if ( this.indicators ) {
  753. for ( var i = this.indicators.length; i--; ) {
  754. this.indicators[i].transitionTime(time);
  755. }
  756. }
  757. // INSERT POINT: _transitionTime
  758. },
  759. _transitionTimingFunction: function (easing) {
  760. this.scrollerStyle[utils.style.transitionTimingFunction] = easing;
  761. if ( this.indicators ) {
  762. for ( var i = this.indicators.length; i--; ) {
  763. this.indicators[i].transitionTimingFunction(easing);
  764. }
  765. }
  766. // INSERT POINT: _transitionTimingFunction
  767. },
  768. _translate: function (x, y) {
  769. if ( this.options.useTransform ) {
  770. /* REPLACE START: _translate */
  771. this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ;
  772. /* REPLACE END: _translate */
  773. } else {
  774. x = Math.round(x);
  775. y = Math.round(y);
  776. this.scrollerStyle.left = x + 'px';
  777. this.scrollerStyle.top = y + 'px';
  778. }
  779. this.x = x;
  780. this.y = y;
  781. if ( this.indicators ) {
  782. for ( var i = this.indicators.length; i--; ) {
  783. this.indicators[i].updatePosition();
  784. }
  785. }
  786. // INSERT POINT: _translate
  787. },
  788. _initEvents: function (remove) {
  789. var eventType = remove ? utils.removeEvent : utils.addEvent,
  790. target = this.options.bindToWrapper ? this.wrapper : window;
  791. eventType(window, 'orientationchange', this);
  792. eventType(window, 'resize', this);
  793. if ( this.options.click ) {
  794. eventType(this.wrapper, 'click', this, true);
  795. }
  796. if ( !this.options.disableMouse ) {
  797. eventType(this.wrapper, 'mousedown', this);
  798. eventType(target, 'mousemove', this);
  799. eventType(target, 'mousecancel', this);
  800. eventType(target, 'mouseup', this);
  801. }
  802. if ( utils.hasPointer && !this.options.disablePointer ) {
  803. eventType(this.wrapper, utils.prefixPointerEvent('pointerdown'), this);
  804. eventType(target, utils.prefixPointerEvent('pointermove'), this);
  805. eventType(target, utils.prefixPointerEvent('pointercancel'), this);
  806. eventType(target, utils.prefixPointerEvent('pointerup'), this);
  807. }
  808. if ( utils.hasTouch && !this.options.disableTouch ) {
  809. eventType(this.wrapper, 'touchstart', this);
  810. eventType(target, 'touchmove', this);
  811. eventType(target, 'touchcancel', this);
  812. eventType(target, 'touchend', this);
  813. }
  814. eventType(this.scroller, 'transitionend', this);
  815. eventType(this.scroller, 'webkitTransitionEnd', this);
  816. eventType(this.scroller, 'oTransitionEnd', this);
  817. eventType(this.scroller, 'MSTransitionEnd', this);
  818. },
  819. getComputedPosition: function () {
  820. var matrix = window.getComputedStyle(this.scroller, null),
  821. x, y;
  822. if ( this.options.useTransform ) {
  823. matrix = matrix[utils.style.transform].split(')')[0].split(', ');
  824. x = +(matrix[12] || matrix[4]);
  825. y = +(matrix[13] || matrix[5]);
  826. } else {
  827. x = +matrix.left.replace(/[^-\d.]/g, '');
  828. y = +matrix.top.replace(/[^-\d.]/g, '');
  829. }
  830. return { x: x, y: y };
  831. },
  832. _initIndicators: function () {
  833. var interactive = this.options.interactiveScrollbars,
  834. customStyle = typeof this.options.scrollbars != 'string',
  835. indicators = [],
  836. indicator;
  837. var that = this;
  838. this.indicators = [];
  839. if ( this.options.scrollbars ) {
  840. // Vertical scrollbar
  841. if ( this.options.scrollY ) {
  842. indicator = {
  843. el: createDefaultScrollbar('v', interactive, this.options.scrollbars),
  844. interactive: interactive,
  845. defaultScrollbars: true,
  846. customStyle: customStyle,
  847. resize: this.options.resizeScrollbars,
  848. shrink: this.options.shrinkScrollbars,
  849. fade: this.options.fadeScrollbars,
  850. listenX: false
  851. };
  852. this.wrapper.appendChild(indicator.el);
  853. indicators.push(indicator);
  854. }
  855. // Horizontal scrollbar
  856. if ( this.options.scrollX ) {
  857. indicator = {
  858. el: createDefaultScrollbar('h', interactive, this.options.scrollbars),
  859. interactive: interactive,
  860. defaultScrollbars: true,
  861. customStyle: customStyle,
  862. resize: this.options.resizeScrollbars,
  863. shrink: this.options.shrinkScrollbars,
  864. fade: this.options.fadeScrollbars,
  865. listenY: false
  866. };
  867. this.wrapper.appendChild(indicator.el);
  868. indicators.push(indicator);
  869. }
  870. }
  871. if ( this.options.indicators ) {
  872. // TODO: check concat compatibility
  873. indicators = indicators.concat(this.options.indicators);
  874. }
  875. for ( var i = indicators.length; i--; ) {
  876. this.indicators.push( new Indicator(this, indicators[i]) );
  877. }
  878. // TODO: check if we can use array.map (wide compatibility and performance issues)
  879. function _indicatorsMap (fn) {
  880. if (that.indicators) {
  881. for ( var i = that.indicators.length; i--; ) {
  882. fn.call(that.indicators[i]);
  883. }
  884. }
  885. }
  886. if ( this.options.fadeScrollbars ) {
  887. this.on('scrollEnd', function () {
  888. _indicatorsMap(function () {
  889. this.fade();
  890. });
  891. });
  892. this.on('scrollCancel', function () {
  893. _indicatorsMap(function () {
  894. this.fade();
  895. });
  896. });
  897. this.on('scrollStart', function () {
  898. _indicatorsMap(function () {
  899. this.fade(1);
  900. });
  901. });
  902. this.on('beforeScrollStart', function () {
  903. _indicatorsMap(function () {
  904. this.fade(1, true);
  905. });
  906. });
  907. }
  908. this.on('refresh', function () {
  909. _indicatorsMap(function () {
  910. this.refresh();
  911. });
  912. });
  913. this.on('destroy', function () {
  914. _indicatorsMap(function () {
  915. this.destroy();
  916. });
  917. delete this.indicators;
  918. });
  919. },
  920. _initWheel: function () {
  921. utils.addEvent(this.wrapper, 'wheel', this);
  922. utils.addEvent(this.wrapper, 'mousewheel', this);
  923. utils.addEvent(this.wrapper, 'DOMMouseScroll', this);
  924. this.on('destroy', function () {
  925. clearTimeout(this.wheelTimeout);
  926. this.wheelTimeout = null;
  927. utils.removeEvent(this.wrapper, 'wheel', this);
  928. utils.removeEvent(this.wrapper, 'mousewheel', this);
  929. utils.removeEvent(this.wrapper, 'DOMMouseScroll', this);
  930. });
  931. },
  932. _wheel: function (e) {
  933. if ( !this.enabled ) {
  934. return;
  935. }
  936. e.preventDefault();
  937. var wheelDeltaX, wheelDeltaY,
  938. newX, newY,
  939. that = this;
  940. if ( this.wheelTimeout === undefined ) {
  941. that._execEvent('scrollStart');
  942. }
  943. // Execute the scrollEnd event after 400ms the wheel stopped scrolling
  944. clearTimeout(this.wheelTimeout);
  945. this.wheelTimeout = setTimeout(function () {
  946. if(!that.options.snap) {
  947. that._execEvent('scrollEnd');
  948. }
  949. that.wheelTimeout = undefined;
  950. }, 400);
  951. if ( 'deltaX' in e ) {
  952. if (e.deltaMode === 1) {
  953. wheelDeltaX = -e.deltaX * this.options.mouseWheelSpeed;
  954. wheelDeltaY = -e.deltaY * this.options.mouseWheelSpeed;
  955. } else {
  956. wheelDeltaX = -e.deltaX;
  957. wheelDeltaY = -e.deltaY;
  958. }
  959. } else if ( 'wheelDeltaX' in e ) {
  960. wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed;
  961. wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed;
  962. } else if ( 'wheelDelta' in e ) {
  963. wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed;
  964. } else if ( 'detail' in e ) {
  965. wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed;
  966. } else {
  967. return;
  968. }
  969. wheelDeltaX *= this.options.invertWheelDirection;
  970. wheelDeltaY *= this.options.invertWheelDirection;
  971. if ( !this.hasVerticalScroll ) {
  972. wheelDeltaX = wheelDeltaY;
  973. wheelDeltaY = 0;
  974. }
  975. if ( this.options.snap ) {
  976. newX = this.currentPage.pageX;
  977. newY = this.currentPage.pageY;
  978. if ( wheelDeltaX > 0 ) {
  979. newX--;
  980. } else if ( wheelDeltaX < 0 ) {
  981. newX++;
  982. }
  983. if ( wheelDeltaY > 0 ) {
  984. newY--;
  985. } else if ( wheelDeltaY < 0 ) {
  986. newY++;
  987. }
  988. this.goToPage(newX, newY);
  989. return;
  990. }
  991. newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0);
  992. newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0);
  993. this.directionX = wheelDeltaX > 0 ? -1 : wheelDeltaX < 0 ? 1 : 0;
  994. this.directionY = wheelDeltaY > 0 ? -1 : wheelDeltaY < 0 ? 1 : 0;
  995. if ( newX > 0 ) {
  996. newX = 0;
  997. } else if ( newX < this.maxScrollX ) {
  998. newX = this.maxScrollX;
  999. }
  1000. if ( newY > 0 ) {
  1001. newY = 0;
  1002. } else if ( newY < this.maxScrollY ) {
  1003. newY = this.maxScrollY;
  1004. }
  1005. this.scrollTo(newX, newY, 0);
  1006. if ( this.options.probeType > 1 ) {
  1007. this._execEvent('scroll');
  1008. }
  1009. // INSERT POINT: _wheel
  1010. },
  1011. _initSnap: function () {
  1012. this.currentPage = {};
  1013. if ( typeof this.options.snap == 'string' ) {
  1014. this.options.snap = this.scroller.querySelectorAll(this.options.snap);
  1015. }
  1016. this.on('refresh', function () {
  1017. var i = 0, l,
  1018. m = 0, n,
  1019. cx, cy,
  1020. x = 0, y,
  1021. stepX = this.options.snapStepX || this.wrapperWidth,
  1022. stepY = this.options.snapStepY || this.wrapperHeight,
  1023. el,
  1024. rect;
  1025. this.pages = [];
  1026. if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) {
  1027. return;
  1028. }
  1029. if ( this.options.snap === true ) {
  1030. cx = Math.round( stepX / 2 );
  1031. cy = Math.round( stepY / 2 );
  1032. while ( x > -this.scrollerWidth ) {
  1033. this.pages[i] = [];
  1034. l = 0;
  1035. y = 0;
  1036. while ( y > -this.scrollerHeight ) {
  1037. this.pages[i][l] = {
  1038. x: Math.max(x, this.maxScrollX),
  1039. y: Math.max(y, this.maxScrollY),
  1040. width: stepX,
  1041. height: stepY,
  1042. cx: x - cx,
  1043. cy: y - cy
  1044. };
  1045. y -= stepY;
  1046. l++;
  1047. }
  1048. x -= stepX;
  1049. i++;
  1050. }
  1051. } else {
  1052. el = this.options.snap;
  1053. l = el.length;
  1054. n = -1;
  1055. for ( ; i < l; i++ ) {
  1056. rect = utils.getRect(el[i]);
  1057. if ( i === 0 || rect.left <= utils.getRect(el[i-1]).left ) {
  1058. m = 0;
  1059. n++;
  1060. }
  1061. if ( !this.pages[m] ) {
  1062. this.pages[m] = [];
  1063. }
  1064. x = Math.max(-rect.left, this.maxScrollX);
  1065. y = Math.max(-rect.top, this.maxScrollY);
  1066. cx = x - Math.round(rect.width / 2);
  1067. cy = y - Math.round(rect.height / 2);
  1068. this.pages[m][n] = {
  1069. x: x,
  1070. y: y,
  1071. width: rect.width,
  1072. height: rect.height,
  1073. cx: cx,
  1074. cy: cy
  1075. };
  1076. if ( x > this.maxScrollX ) {
  1077. m++;
  1078. }
  1079. }
  1080. }
  1081. this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0);
  1082. // Update snap threshold if needed
  1083. if ( this.options.snapThreshold % 1 === 0 ) {
  1084. this.snapThresholdX = this.options.snapThreshold;
  1085. this.snapThresholdY = this.options.snapThreshold;
  1086. } else {
  1087. this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold);
  1088. this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold);
  1089. }
  1090. });
  1091. this.on('flick', function () {
  1092. var time = this.options.snapSpeed || Math.max(
  1093. Math.max(
  1094. Math.min(Math.abs(this.x - this.startX), 1000),
  1095. Math.min(Math.abs(this.y - this.startY), 1000)
  1096. ), 300);
  1097. this.goToPage(
  1098. this.currentPage.pageX + this.directionX,
  1099. this.currentPage.pageY + this.directionY,
  1100. time
  1101. );
  1102. });
  1103. },
  1104. _nearestSnap: function (x, y) {
  1105. if ( !this.pages.length ) {
  1106. return { x: 0, y: 0, pageX: 0, pageY: 0 };
  1107. }
  1108. var i = 0,
  1109. l = this.pages.length,
  1110. m = 0;
  1111. // Check if we exceeded the snap threshold
  1112. if ( Math.abs(x - this.absStartX) < this.snapThresholdX &&
  1113. Math.abs(y - this.absStartY) < this.snapThresholdY ) {
  1114. return this.currentPage;
  1115. }
  1116. if ( x > 0 ) {
  1117. x = 0;
  1118. } else if ( x < this.maxScrollX ) {
  1119. x = this.maxScrollX;
  1120. }
  1121. if ( y > 0 ) {
  1122. y = 0;
  1123. } else if ( y < this.maxScrollY ) {
  1124. y = this.maxScrollY;
  1125. }
  1126. for ( ; i < l; i++ ) {
  1127. if ( x >= this.pages[i][0].cx ) {
  1128. x = this.pages[i][0].x;
  1129. break;
  1130. }
  1131. }
  1132. l = this.pages[i].length;
  1133. for ( ; m < l; m++ ) {
  1134. if ( y >= this.pages[0][m].cy ) {
  1135. y = this.pages[0][m].y;
  1136. break;
  1137. }
  1138. }
  1139. if ( i == this.currentPage.pageX ) {
  1140. i += this.directionX;
  1141. if ( i < 0 ) {
  1142. i = 0;
  1143. } else if ( i >= this.pages.length ) {
  1144. i = this.pages.length - 1;
  1145. }
  1146. x = this.pages[i][0].x;
  1147. }
  1148. if ( m == this.currentPage.pageY ) {
  1149. m += this.directionY;
  1150. if ( m < 0 ) {
  1151. m = 0;
  1152. } else if ( m >= this.pages[0].length ) {
  1153. m = this.pages[0].length - 1;
  1154. }
  1155. y = this.pages[0][m].y;
  1156. }
  1157. return {
  1158. x: x,
  1159. y: y,
  1160. pageX: i,
  1161. pageY: m
  1162. };
  1163. },
  1164. goToPage: function (x, y, time, easing) {
  1165. easing = easing || this.options.bounceEasing;
  1166. if ( x >= this.pages.length ) {
  1167. x = this.pages.length - 1;
  1168. } else if ( x < 0 ) {
  1169. x = 0;
  1170. }
  1171. if ( y >= this.pages[x].length ) {
  1172. y = this.pages[x].length - 1;
  1173. } else if ( y < 0 ) {
  1174. y = 0;
  1175. }
  1176. var posX = this.pages[x][y].x,
  1177. posY = this.pages[x][y].y;
  1178. time = time === undefined ? this.options.snapSpeed || Math.max(
  1179. Math.max(
  1180. Math.min(Math.abs(posX - this.x), 1000),
  1181. Math.min(Math.abs(posY - this.y), 1000)
  1182. ), 300) : time;
  1183. this.currentPage = {
  1184. x: posX,
  1185. y: posY,
  1186. pageX: x,
  1187. pageY: y
  1188. };
  1189. this.scrollTo(posX, posY, time, easing);
  1190. },
  1191. next: function (time, easing) {
  1192. var x = this.currentPage.pageX,
  1193. y = this.currentPage.pageY;
  1194. x++;
  1195. if ( x >= this.pages.length && this.hasVerticalScroll ) {
  1196. x = 0;
  1197. y++;
  1198. }
  1199. this.goToPage(x, y, time, easing);
  1200. },
  1201. prev: function (time, easing) {
  1202. var x = this.currentPage.pageX,
  1203. y = this.currentPage.pageY;
  1204. x--;
  1205. if ( x < 0 && this.hasVerticalScroll ) {
  1206. x = 0;
  1207. y--;
  1208. }
  1209. this.goToPage(x, y, time, easing);
  1210. },
  1211. _initKeys: function (e) {
  1212. // default key bindings
  1213. var keys = {
  1214. pageUp: 33,
  1215. pageDown: 34,
  1216. end: 35,
  1217. home: 36,
  1218. left: 37,
  1219. up: 38,
  1220. right: 39,
  1221. down: 40
  1222. };
  1223. var i;
  1224. // if you give me characters I give you keycode
  1225. if ( typeof this.options.keyBindings == 'object' ) {
  1226. for ( i in this.options.keyBindings ) {
  1227. if ( typeof this.options.keyBindings[i] == 'string' ) {
  1228. this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0);
  1229. }
  1230. }
  1231. } else {
  1232. this.options.keyBindings = {};
  1233. }
  1234. for ( i in keys ) {
  1235. this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i];
  1236. }
  1237. utils.addEvent(window, 'keydown', this);
  1238. this.on('destroy', function () {
  1239. utils.removeEvent(window, 'keydown', this);
  1240. });
  1241. },
  1242. _key: function (e) {
  1243. if ( !this.enabled ) {
  1244. return;
  1245. }
  1246. var snap = this.options.snap, // we are using this alot, better to cache it
  1247. newX = snap ? this.currentPage.pageX : this.x,
  1248. newY = snap ? this.currentPage.pageY : this.y,
  1249. now = utils.getTime(),
  1250. prevTime = this.keyTime || 0,
  1251. acceleration = 0.250,
  1252. pos;
  1253. if ( this.options.useTransition && this.isInTransition ) {
  1254. pos = this.getComputedPosition();
  1255. this._translate(Math.round(pos.x), Math.round(pos.y));
  1256. this.isInTransition = false;
  1257. }
  1258. this.keyAcceleration = now - prevTime < 200 ? Math.min(this.keyAcceleration + acceleration, 50) : 0;
  1259. switch ( e.keyCode ) {
  1260. case this.options.keyBindings.pageUp:
  1261. if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) {
  1262. newX += snap ? 1 : this.wrapperWidth;
  1263. } else {
  1264. newY += snap ? 1 : this.wrapperHeight;
  1265. }
  1266. break;
  1267. case this.options.keyBindings.pageDown:
  1268. if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) {
  1269. newX -= snap ? 1 : this.wrapperWidth;
  1270. } else {
  1271. newY -= snap ? 1 : this.wrapperHeight;
  1272. }
  1273. break;
  1274. case this.options.keyBindings.end:
  1275. newX = snap ? this.pages.length-1 : this.maxScrollX;
  1276. newY = snap ? this.pages[0].length-1 : this.maxScrollY;
  1277. break;
  1278. case this.options.keyBindings.home:
  1279. newX = 0;
  1280. newY = 0;
  1281. break;
  1282. case this.options.keyBindings.left:
  1283. newX += snap ? -1 : 5 + this.keyAcceleration>>0;
  1284. break;
  1285. case this.options.keyBindings.up:
  1286. newY += snap ? 1 : 5 + this.keyAcceleration>>0;
  1287. break;
  1288. case this.options.keyBindings.right:
  1289. newX -= snap ? -1 : 5 + this.keyAcceleration>>0;
  1290. break;
  1291. case this.options.keyBindings.down:
  1292. newY -= snap ? 1 : 5 + this.keyAcceleration>>0;
  1293. break;
  1294. default:
  1295. return;
  1296. }
  1297. if ( snap ) {
  1298. this.goToPage(newX, newY);
  1299. return;
  1300. }
  1301. if ( newX > 0 ) {
  1302. newX = 0;
  1303. this.keyAcceleration = 0;
  1304. } else if ( newX < this.maxScrollX ) {
  1305. newX = this.maxScrollX;
  1306. this.keyAcceleration = 0;
  1307. }
  1308. if ( newY > 0 ) {
  1309. newY = 0;
  1310. this.keyAcceleration = 0;
  1311. } else if ( newY < this.maxScrollY ) {
  1312. newY = this.maxScrollY;
  1313. this.keyAcceleration = 0;
  1314. }
  1315. this.scrollTo(newX, newY, 0);
  1316. this.keyTime = now;
  1317. },
  1318. _animate: function (destX, destY, duration, easingFn) {
  1319. var that = this,
  1320. startX = this.x,
  1321. startY = this.y,
  1322. startTime = utils.getTime(),
  1323. destTime = startTime + duration;
  1324. function step () {
  1325. var now = utils.getTime(),
  1326. newX, newY,
  1327. easing;
  1328. if ( now >= destTime ) {
  1329. that.isAnimating = false;
  1330. that._translate(destX, destY);
  1331. if ( !that.resetPosition(that.options.bounceTime) ) {
  1332. that._execEvent('scrollEnd');
  1333. }
  1334. return;
  1335. }
  1336. now = ( now - startTime ) / duration;
  1337. easing = easingFn(now);
  1338. newX = ( destX - startX ) * easing + startX;
  1339. newY = ( destY - startY ) * easing + startY;
  1340. that._translate(newX, newY);
  1341. if ( that.isAnimating ) {
  1342. rAF(step);
  1343. }
  1344. if ( that.options.probeType == 3 ) {
  1345. that._execEvent('scroll');
  1346. }
  1347. }
  1348. this.isAnimating = true;
  1349. step();
  1350. },
  1351. handleEvent: function (e) {
  1352. switch ( e.type ) {
  1353. case 'touchstart':
  1354. case 'pointerdown':
  1355. case 'MSPointerDown':
  1356. case 'mousedown':
  1357. this._start(e);
  1358. break;
  1359. case 'touchmove':
  1360. case 'pointermove':
  1361. case 'MSPointerMove':
  1362. case 'mousemove':
  1363. this._move(e);
  1364. break;
  1365. case 'touchend':
  1366. case 'pointerup':
  1367. case 'MSPointerUp':
  1368. case 'mouseup':
  1369. case 'touchcancel':
  1370. case 'pointercancel':
  1371. case 'MSPointerCancel':
  1372. case 'mousecancel':
  1373. this._end(e);
  1374. break;
  1375. case 'orientationchange':
  1376. case 'resize':
  1377. this._resize();
  1378. break;
  1379. case 'transitionend':
  1380. case 'webkitTransitionEnd':
  1381. case 'oTransitionEnd':
  1382. case 'MSTransitionEnd':
  1383. this._transitionEnd(e);
  1384. break;
  1385. case 'wheel':
  1386. case 'DOMMouseScroll':
  1387. case 'mousewheel':
  1388. this._wheel(e);
  1389. break;
  1390. case 'keydown':
  1391. this._key(e);
  1392. break;
  1393. case 'click':
  1394. if ( this.enabled && !e._constructed ) {
  1395. e.preventDefault();
  1396. e.stopPropagation();
  1397. }
  1398. break;
  1399. }
  1400. }
  1401. };
  1402. function createDefaultScrollbar (direction, interactive, type) {
  1403. var scrollbar = document.createElement('div'),
  1404. indicator = document.createElement('div');
  1405. if ( type === true ) {
  1406. scrollbar.style.cssText = 'position:absolute;z-index:9999';
  1407. indicator.style.cssText = '-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px';
  1408. }
  1409. indicator.className = 'iScrollIndicator';
  1410. if ( direction == 'h' ) {
  1411. if ( type === true ) {
  1412. scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0';
  1413. indicator.style.height = '100%';
  1414. }
  1415. scrollbar.className = 'iScrollHorizontalScrollbar';
  1416. } else {
  1417. if ( type === true ) {
  1418. scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px';
  1419. indicator.style.width = '100%';
  1420. }
  1421. scrollbar.className = 'iScrollVerticalScrollbar';
  1422. }
  1423. scrollbar.style.cssText += ';overflow:hidden';
  1424. if ( !interactive ) {
  1425. scrollbar.style.pointerEvents = 'none';
  1426. }
  1427. scrollbar.appendChild(indicator);
  1428. return scrollbar;
  1429. }
  1430. function Indicator (scroller, options) {
  1431. this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el;
  1432. this.wrapperStyle = this.wrapper.style;
  1433. this.indicator = this.wrapper.children[0];
  1434. this.indicatorStyle = this.indicator.style;
  1435. this.scroller = scroller;
  1436. this.options = {
  1437. listenX: true,
  1438. listenY: true,
  1439. interactive: false,
  1440. resize: true,
  1441. defaultScrollbars: false,
  1442. shrink: false,
  1443. fade: false,
  1444. speedRatioX: 0,
  1445. speedRatioY: 0
  1446. };
  1447. for ( var i in options ) {
  1448. this.options[i] = options[i];
  1449. }
  1450. this.sizeRatioX = 1;
  1451. this.sizeRatioY = 1;
  1452. this.maxPosX = 0;
  1453. this.maxPosY = 0;
  1454. if ( this.options.interactive ) {
  1455. if ( !this.options.disableTouch ) {
  1456. utils.addEvent(this.indicator, 'touchstart', this);
  1457. utils.addEvent(window, 'touchend', this);
  1458. }
  1459. if ( !this.options.disablePointer ) {
  1460. utils.addEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
  1461. utils.addEvent(window, utils.prefixPointerEvent('pointerup'), this);
  1462. }
  1463. if ( !this.options.disableMouse ) {
  1464. utils.addEvent(this.indicator, 'mousedown', this);
  1465. utils.addEvent(window, 'mouseup', this);
  1466. }
  1467. }
  1468. if ( this.options.fade ) {
  1469. this.wrapperStyle[utils.style.transform] = this.scroller.translateZ;
  1470. var durationProp = utils.style.transitionDuration;
  1471. if(!durationProp) {
  1472. return;
  1473. }
  1474. this.wrapperStyle[durationProp] = utils.isBadAndroid ? '0.0001ms' : '0ms';
  1475. // remove 0.0001ms
  1476. var self = this;
  1477. if(utils.isBadAndroid) {
  1478. rAF(function() {
  1479. if(self.wrapperStyle[durationProp] === '0.0001ms') {
  1480. self.wrapperStyle[durationProp] = '0s';
  1481. }
  1482. });
  1483. }
  1484. this.wrapperStyle.opacity = '0';
  1485. }
  1486. }
  1487. Indicator.prototype = {
  1488. handleEvent: function (e) {
  1489. switch ( e.type ) {
  1490. case 'touchstart':
  1491. case 'pointerdown':
  1492. case 'MSPointerDown':
  1493. case 'mousedown':
  1494. this._start(e);
  1495. break;
  1496. case 'touchmove':
  1497. case 'pointermove':
  1498. case 'MSPointerMove':
  1499. case 'mousemove':
  1500. this._move(e);
  1501. break;
  1502. case 'touchend':
  1503. case 'pointerup':
  1504. case 'MSPointerUp':
  1505. case 'mouseup':
  1506. case 'touchcancel':
  1507. case 'pointercancel':
  1508. case 'MSPointerCancel':
  1509. case 'mousecancel':
  1510. this._end(e);
  1511. break;
  1512. }
  1513. },
  1514. destroy: function () {
  1515. if ( this.options.fadeScrollbars ) {
  1516. clearTimeout(this.fadeTimeout);
  1517. this.fadeTimeout = null;
  1518. }
  1519. if ( this.options.interactive ) {
  1520. utils.removeEvent(this.indicator, 'touchstart', this);
  1521. utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
  1522. utils.removeEvent(this.indicator, 'mousedown', this);
  1523. utils.removeEvent(window, 'touchmove', this);
  1524. utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
  1525. utils.removeEvent(window, 'mousemove', this);
  1526. utils.removeEvent(window, 'touchend', this);
  1527. utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this);
  1528. utils.removeEvent(window, 'mouseup', this);
  1529. }
  1530. if ( this.options.defaultScrollbars && this.wrapper.parentNode ) {
  1531. this.wrapper.parentNode.removeChild(this.wrapper);
  1532. }
  1533. },
  1534. _start: function (e) {
  1535. var point = e.touches ? e.touches[0] : e;
  1536. e.preventDefault();
  1537. e.stopPropagation();
  1538. this.transitionTime();
  1539. this.initiated = true;
  1540. this.moved = false;
  1541. this.lastPointX = point.pageX;
  1542. this.lastPointY = point.pageY;
  1543. this.startTime = utils.getTime();
  1544. if ( !this.options.disableTouch ) {
  1545. utils.addEvent(window, 'touchmove', this);
  1546. }
  1547. if ( !this.options.disablePointer ) {
  1548. utils.addEvent(window, utils.prefixPointerEvent('pointermove'), this);
  1549. }
  1550. if ( !this.options.disableMouse ) {
  1551. utils.addEvent(window, 'mousemove', this);
  1552. }
  1553. this.scroller._execEvent('beforeScrollStart');
  1554. },
  1555. _move: function (e) {
  1556. var point = e.touches ? e.touches[0] : e,
  1557. deltaX, deltaY,
  1558. newX, newY,
  1559. timestamp = utils.getTime();
  1560. if ( !this.moved ) {
  1561. this.scroller._execEvent('scrollStart');
  1562. }
  1563. this.moved = true;
  1564. deltaX = point.pageX - this.lastPointX;
  1565. this.lastPointX = point.pageX;
  1566. deltaY = point.pageY - this.lastPointY;
  1567. this.lastPointY = point.pageY;
  1568. newX = this.x + deltaX;
  1569. newY = this.y + deltaY;
  1570. this._pos(newX, newY);
  1571. if ( this.scroller.options.probeType == 1 && timestamp - this.startTime > 300 ) {
  1572. this.startTime = timestamp;
  1573. this.scroller._execEvent('scroll');
  1574. } else if ( this.scroller.options.probeType > 1 ) {
  1575. this.scroller._execEvent('scroll');
  1576. }
  1577. // INSERT POINT: indicator._move
  1578. e.preventDefault();
  1579. e.stopPropagation();
  1580. },
  1581. _end: function (e) {
  1582. if ( !this.initiated ) {
  1583. return;
  1584. }
  1585. this.initiated = false;
  1586. e.preventDefault();
  1587. e.stopPropagation();
  1588. utils.removeEvent(window, 'touchmove', this);
  1589. utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
  1590. utils.removeEvent(window, 'mousemove', this);
  1591. if ( this.scroller.options.snap ) {
  1592. var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y);
  1593. var time = this.options.snapSpeed || Math.max(
  1594. Math.max(
  1595. Math.min(Math.abs(this.scroller.x - snap.x), 1000),
  1596. Math.min(Math.abs(this.scroller.y - snap.y), 1000)
  1597. ), 300);
  1598. if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) {
  1599. this.scroller.directionX = 0;
  1600. this.scroller.directionY = 0;
  1601. this.scroller.currentPage = snap;
  1602. this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing);
  1603. }
  1604. }
  1605. if ( this.moved ) {
  1606. this.scroller._execEvent('scrollEnd');
  1607. }
  1608. },
  1609. transitionTime: function (time) {
  1610. time = time || 0;
  1611. var durationProp = utils.style.transitionDuration;
  1612. if(!durationProp) {
  1613. return;
  1614. }
  1615. this.indicatorStyle[durationProp] = time + 'ms';
  1616. if ( !time && utils.isBadAndroid ) {
  1617. this.indicatorStyle[durationProp] = '0.0001ms';
  1618. // remove 0.0001ms
  1619. var self = this;
  1620. rAF(function() {
  1621. if(self.indicatorStyle[durationProp] === '0.0001ms') {
  1622. self.indicatorStyle[durationProp] = '0s';
  1623. }
  1624. });
  1625. }
  1626. },
  1627. transitionTimingFunction: function (easing) {
  1628. this.indicatorStyle[utils.style.transitionTimingFunction] = easing;
  1629. },
  1630. refresh: function () {
  1631. this.transitionTime();
  1632. if ( this.options.listenX && !this.options.listenY ) {
  1633. this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none';
  1634. } else if ( this.options.listenY && !this.options.listenX ) {
  1635. this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none';
  1636. } else {
  1637. this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none';
  1638. }
  1639. if ( this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ) {
  1640. utils.addClass(this.wrapper, 'iScrollBothScrollbars');
  1641. utils.removeClass(this.wrapper, 'iScrollLoneScrollbar');
  1642. if ( this.options.defaultScrollbars && this.options.customStyle ) {
  1643. if ( this.options.listenX ) {
  1644. this.wrapper.style.right = '8px';
  1645. } else {
  1646. this.wrapper.style.bottom = '8px';
  1647. }
  1648. }
  1649. } else {
  1650. utils.removeClass(this.wrapper, 'iScrollBothScrollbars');
  1651. utils.addClass(this.wrapper, 'iScrollLoneScrollbar');
  1652. if ( this.options.defaultScrollbars && this.options.customStyle ) {
  1653. if ( this.options.listenX ) {
  1654. this.wrapper.style.right = '2px';
  1655. } else {
  1656. this.wrapper.style.bottom = '2px';
  1657. }
  1658. }
  1659. }
  1660. utils.getRect(this.wrapper); // force refresh
  1661. if ( this.options.listenX ) {
  1662. this.wrapperWidth = this.wrapper.clientWidth;
  1663. if ( this.options.resize ) {
  1664. this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
  1665. this.indicatorStyle.width = this.indicatorWidth + 'px';
  1666. } else {
  1667. this.indicatorWidth = this.indicator.clientWidth;
  1668. }
  1669. this.maxPosX = this.wrapperWidth - this.indicatorWidth;
  1670. if ( this.options.shrink == 'clip' ) {
  1671. this.minBoundaryX = -this.indicatorWidth + 8;
  1672. this.maxBoundaryX = this.wrapperWidth - 8;
  1673. } else {
  1674. this.minBoundaryX = 0;
  1675. this.maxBoundaryX = this.maxPosX;
  1676. }
  1677. this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));
  1678. }
  1679. if ( this.options.listenY ) {
  1680. this.wrapperHeight = this.wrapper.clientHeight;
  1681. if ( this.options.resize ) {
  1682. this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8);
  1683. this.indicatorStyle.height = this.indicatorHeight + 'px';
  1684. } else {
  1685. this.indicatorHeight = this.indicator.clientHeight;
  1686. }
  1687. this.maxPosY = this.wrapperHeight - this.indicatorHeight;
  1688. if ( this.options.shrink == 'clip' ) {
  1689. this.minBoundaryY = -this.indicatorHeight + 8;
  1690. this.maxBoundaryY = this.wrapperHeight - 8;
  1691. } else {
  1692. this.minBoundaryY = 0;
  1693. this.maxBoundaryY = this.maxPosY;
  1694. }
  1695. this.maxPosY = this.wrapperHeight - this.indicatorHeight;
  1696. this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY));
  1697. }
  1698. this.updatePosition();
  1699. },
  1700. updatePosition: function () {
  1701. var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0,
  1702. y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0;
  1703. if ( !this.options.ignoreBoundaries ) {
  1704. if ( x < this.minBoundaryX ) {
  1705. if ( this.options.shrink == 'scale' ) {
  1706. this.width = Math.max(this.indicatorWidth + x, 8);
  1707. this.indicatorStyle.width = this.width + 'px';
  1708. }
  1709. x = this.minBoundaryX;
  1710. } else if ( x > this.maxBoundaryX ) {
  1711. if ( this.options.shrink == 'scale' ) {
  1712. this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8);
  1713. this.indicatorStyle.width = this.width + 'px';
  1714. x = this.maxPosX + this.indicatorWidth - this.width;
  1715. } else {
  1716. x = this.maxBoundaryX;
  1717. }
  1718. } else if ( this.options.shrink == 'scale' && this.width != this.indicatorWidth ) {
  1719. this.width = this.indicatorWidth;
  1720. this.indicatorStyle.width = this.width + 'px';
  1721. }
  1722. if ( y < this.minBoundaryY ) {
  1723. if ( this.options.shrink == 'scale' ) {
  1724. this.height = Math.max(this.indicatorHeight + y * 3, 8);
  1725. this.indicatorStyle.height = this.height + 'px';
  1726. }
  1727. y = this.minBoundaryY;
  1728. } else if ( y > this.maxBoundaryY ) {
  1729. if ( this.options.shrink == 'scale' ) {
  1730. this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8);
  1731. this.indicatorStyle.height = this.height + 'px';
  1732. y = this.maxPosY + this.indicatorHeight - this.height;
  1733. } else {
  1734. y = this.maxBoundaryY;
  1735. }
  1736. } else if ( this.options.shrink == 'scale' && this.height != this.indicatorHeight ) {
  1737. this.height = this.indicatorHeight;
  1738. this.indicatorStyle.height = this.height + 'px';
  1739. }
  1740. }
  1741. this.x = x;
  1742. this.y = y;
  1743. if ( this.scroller.options.useTransform ) {
  1744. this.indicatorStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.scroller.translateZ;
  1745. } else {
  1746. this.indicatorStyle.left = x + 'px';
  1747. this.indicatorStyle.top = y + 'px';
  1748. }
  1749. },
  1750. _pos: function (x, y) {
  1751. if ( x < 0 ) {
  1752. x = 0;
  1753. } else if ( x > this.maxPosX ) {
  1754. x = this.maxPosX;
  1755. }
  1756. if ( y < 0 ) {
  1757. y = 0;
  1758. } else if ( y > this.maxPosY ) {
  1759. y = this.maxPosY;
  1760. }
  1761. x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x;
  1762. y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y;
  1763. this.scroller.scrollTo(x, y);
  1764. },
  1765. fade: function (val, hold) {
  1766. if ( hold && !this.visible ) {
  1767. return;
  1768. }
  1769. clearTimeout(this.fadeTimeout);
  1770. this.fadeTimeout = null;
  1771. var time = val ? 250 : 500,
  1772. delay = val ? 0 : 300;
  1773. val = val ? '1' : '0';
  1774. this.wrapperStyle[utils.style.transitionDuration] = time + 'ms';
  1775. this.fadeTimeout = setTimeout((function (val) {
  1776. this.wrapperStyle.opacity = val;
  1777. this.visible = +val;
  1778. }).bind(this, val), delay);
  1779. }
  1780. };
  1781. IScroll.utils = utils;
  1782. if ( typeof module != 'undefined' && module.exports ) {
  1783. module.exports = IScroll;
  1784. } else if ( typeof define == 'function' && define.amd ) {
  1785. define( function () { return IScroll; } );
  1786. } else {
  1787. window.IScroll = IScroll;
  1788. }
  1789. })(window, document, Math);