bscroll.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["BScroll"] = factory();
  8. else
  9. root["BScroll"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "/assets/";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. 'use strict';
  46. var _bscroll = __webpack_require__(1);
  47. _bscroll.BScroll.Version = ("0.1.12");
  48. module.exports = _bscroll.BScroll;
  49. /***/ },
  50. /* 1 */
  51. /***/ function(module, exports, __webpack_require__) {
  52. 'use strict';
  53. Object.defineProperty(exports, "__esModule", {
  54. value: true
  55. });
  56. exports.BScroll = undefined;
  57. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  58. var _util = __webpack_require__(2);
  59. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  60. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  61. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  62. var TOUCH_EVENT = 1;
  63. var BScroll = exports.BScroll = function (_EventEmitter) {
  64. _inherits(BScroll, _EventEmitter);
  65. function BScroll(el, options) {
  66. _classCallCheck(this, BScroll);
  67. var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(BScroll).call(this));
  68. _this.wrapper = typeof el === 'string' ? document.querySelector(el) : el;
  69. _this.scroller = _this.wrapper.children[0];
  70. _this.scrollerStyle = _this.scroller.style;
  71. _this.options = {
  72. startX: 0,
  73. startY: 0,
  74. scrollY: true,
  75. directionLockThreshold: 5,
  76. momentum: true,
  77. bounce: true,
  78. selectedIndex: 0,
  79. rotate: 25,
  80. wheel: false,
  81. snap: false,
  82. snapLoop: false,
  83. snapThreshold: 0.1,
  84. swipeTime: 2500,
  85. bounceTime: 700,
  86. adjustTime: 400,
  87. swipeBounceTime: 1200,
  88. deceleration: 0.001,
  89. momentumLimitTime: 300,
  90. momentumLimitDistance: 15,
  91. resizePolling: 60,
  92. preventDefault: true,
  93. preventDefaultException: {
  94. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/
  95. },
  96. HWCompositing: true,
  97. useTransition: true,
  98. useTransform: true
  99. };
  100. (0, _util.extend)(_this.options, options);
  101. _this.translateZ = _this.options.HWCompositing && _util.hasPerspective ? ' translateZ(0)' : '';
  102. _this.options.useTransition = _this.options.useTransition && _util.hasTransition;
  103. _this.options.useTransform = _this.options.useTransform && _util.hasTransform;
  104. _this.options.eventPassthrough = _this.options.eventPassthrough === true ? 'vertical' : _this.options.eventPassthrough;
  105. _this.options.preventDefault = !_this.options.eventPassthrough && _this.options.preventDefault;
  106. _this.options.scrollX = _this.options.eventPassthrough === 'horizontal' ? false : _this.options.scrollX;
  107. _this.options.scrollY = _this.options.eventPassthrough === 'vertical' ? false : _this.options.scrollY;
  108. _this.options.freeScroll = _this.options.freeScroll && !_this.options.eventPassthrough;
  109. _this.options.directionLockThreshold = _this.options.eventPassthrough ? 0 : _this.options.directionLockThreshold;
  110. if (_this.options.tap === true) {
  111. _this.options.tap = 'tap';
  112. }
  113. _this._init();
  114. if (_this.options.snap) {
  115. _this._initSnap();
  116. }
  117. _this.refresh();
  118. if (!_this.options.snap) {
  119. _this.scrollTo(_this.options.startX, _this.options.startY);
  120. }
  121. _this.enable();
  122. return _this;
  123. }
  124. _createClass(BScroll, [{
  125. key: '_init',
  126. value: function _init() {
  127. this.x = 0;
  128. this.y = 0;
  129. this.directionX = 0;
  130. this.directionY = 0;
  131. this._addEvents();
  132. }
  133. }, {
  134. key: '_initSnap',
  135. value: function _initSnap() {
  136. var _this2 = this;
  137. this.currentPage = {};
  138. if (this.options.snapLoop) {
  139. var children = this.scroller.children;
  140. if (children.length > 0) {
  141. (0, _util.prepend)(children[children.length - 1].cloneNode(true), this.scroller);
  142. this.scroller.appendChild(children[1].cloneNode(true));
  143. }
  144. }
  145. if (typeof this.options.snap === 'string') {
  146. this.options.snap = this.scroller.querySelectorAll(this.options.snap);
  147. }
  148. this.on('refresh', function () {
  149. _this2.pages = [];
  150. if (!_this2.wrapperWidth || !_this2.wrapperHeight || !_this2.scrollerWidth || !_this2.scrollerHeight) {
  151. return;
  152. }
  153. var stepX = _this2.options.snapStepX || _this2.wrapperWidth;
  154. var stepY = _this2.options.snapStepY || _this2.wrapperHeight;
  155. var x = 0;
  156. var y = void 0;
  157. var cx = void 0;
  158. var cy = void 0;
  159. var i = 0;
  160. var l = void 0;
  161. var m = 0;
  162. var n = void 0;
  163. var el = void 0;
  164. var rect = void 0;
  165. if (_this2.options.snap === true) {
  166. cx = Math.round(stepX / 2);
  167. cy = Math.round(stepY / 2);
  168. while (x > -_this2.scrollerWidth) {
  169. _this2.pages[i] = [];
  170. l = 0;
  171. y = 0;
  172. while (y > -_this2.scrollerHeight) {
  173. _this2.pages[i][l] = {
  174. x: Math.max(x, _this2.maxScrollX),
  175. y: Math.max(y, _this2.maxScrollY),
  176. width: stepX,
  177. height: stepY,
  178. cx: x - cx,
  179. cy: y - cy
  180. };
  181. y -= stepY;
  182. l++;
  183. }
  184. x -= stepX;
  185. i++;
  186. }
  187. } else {
  188. el = _this2.options.snap;
  189. l = el.length;
  190. n = -1;
  191. for (; i < l; i++) {
  192. rect = (0, _util.getRect)(el[i]);
  193. if (i === 0 || rect.left <= (0, _util.getRect)(el[i - 1]).left) {
  194. m = 0;
  195. n++;
  196. }
  197. if (!_this2.pages[m]) {
  198. _this2.pages[m] = [];
  199. }
  200. x = Math.max(-rect.left, _this2.maxScrollX);
  201. y = Math.max(-rect.top, _this2.maxScrollY);
  202. cx = x - Math.round(rect.width / 2);
  203. cy = y - Math.round(rect.height / 2);
  204. _this2.pages[m][n] = {
  205. x: x,
  206. y: y,
  207. width: rect.width,
  208. height: rect.height,
  209. cx: cx,
  210. cy: cy
  211. };
  212. if (x > _this2.maxScrollX) {
  213. m++;
  214. }
  215. }
  216. }
  217. var initPage = _this2.options.snapLoop ? 1 : 0;
  218. _this2.goToPage(_this2.currentPage.pageX || initPage, _this2.currentPage.pageY || 0, 0);
  219. if (_this2.options.snapThreshold % 1 === 0) {
  220. _this2.snapThresholdX = _this2.options.snapThreshold;
  221. _this2.snapThresholdY = _this2.options.snapThreshold;
  222. } else {
  223. _this2.snapThresholdX = Math.round(_this2.pages[_this2.currentPage.pageX][_this2.currentPage.pageY].width * _this2.options.snapThreshold);
  224. _this2.snapThresholdY = Math.round(_this2.pages[_this2.currentPage.pageX][_this2.currentPage.pageY].height * _this2.options.snapThreshold);
  225. }
  226. });
  227. this.on('scrollEnd', function () {
  228. if (_this2.options.snapLoop) {
  229. if (_this2.currentPage.pageX === 0) {
  230. _this2.goToPage(_this2.pages.length - 2, _this2.currentPage.pageY, 0);
  231. }
  232. if (_this2.currentPage.pageX === _this2.pages.length - 1) {
  233. _this2.goToPage(1, _this2.currentPage.pageY, 0);
  234. }
  235. }
  236. });
  237. this.on('flick', function () {
  238. var time = _this2.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(_this2.x - _this2.startX), 1000), Math.min(Math.abs(_this2.y - _this2.startY), 1000)), 300);
  239. _this2.goToPage(_this2.currentPage.pageX + _this2.directionX, _this2.currentPage.pageY + _this2.directionY, time);
  240. });
  241. }
  242. }, {
  243. key: '_nearestSnap',
  244. value: function _nearestSnap(x, y) {
  245. if (!this.pages.length) {
  246. return { x: 0, y: 0, pageX: 0, pageY: 0 };
  247. }
  248. var i = 0;
  249. if (Math.abs(x - this.absStartX) < this.snapThresholdX && Math.abs(y - this.absStartY) < this.snapThresholdY) {
  250. return this.currentPage;
  251. }
  252. if (x > 0) {
  253. x = 0;
  254. } else if (x < this.maxScrollX) {
  255. x = this.maxScrollX;
  256. }
  257. if (y > 0) {
  258. y = 0;
  259. } else if (y < this.maxScrollY) {
  260. y = this.maxScrollY;
  261. }
  262. var l = this.pages.length;
  263. for (; i < l; i++) {
  264. if (x >= this.pages[i][0].cx) {
  265. x = this.pages[i][0].x;
  266. break;
  267. }
  268. }
  269. l = this.pages[i].length;
  270. var m = 0;
  271. for (; m < l; m++) {
  272. if (y >= this.pages[0][m].cy) {
  273. y = this.pages[0][m].y;
  274. break;
  275. }
  276. }
  277. if (i === this.currentPage.pageX) {
  278. i += this.directionX;
  279. if (i < 0) {
  280. i = 0;
  281. } else if (i >= this.pages.length) {
  282. i = this.pages.length - 1;
  283. }
  284. x = this.pages[i][0].x;
  285. }
  286. if (m === this.currentPage.pageY) {
  287. m += this.directionY;
  288. if (m < 0) {
  289. m = 0;
  290. } else if (m >= this.pages[0].length) {
  291. m = this.pages[0].length - 1;
  292. }
  293. y = this.pages[0][m].y;
  294. }
  295. return {
  296. x: x,
  297. y: y,
  298. pageX: i,
  299. pageY: m
  300. };
  301. }
  302. }, {
  303. key: '_addEvents',
  304. value: function _addEvents() {
  305. var eventOperation = _util.addEvent;
  306. this._handleEvents(eventOperation);
  307. }
  308. }, {
  309. key: '_removeEvents',
  310. value: function _removeEvents() {
  311. var eventOperation = _util.removeEvent;
  312. this._handleEvents(eventOperation);
  313. }
  314. }, {
  315. key: '_handleEvents',
  316. value: function _handleEvents(eventOperation) {
  317. var target = this.options.bindToWrapper ? this.wrapper : window;
  318. eventOperation(window, 'orientationchange', this);
  319. eventOperation(window, 'resize', this);
  320. if (this.options.click) {
  321. eventOperation(this.wrapper, 'click', this);
  322. }
  323. if (!this.options.disableMouse) {
  324. eventOperation(this.wrapper, 'mousedown', this);
  325. eventOperation(target, 'mousemove', this);
  326. eventOperation(target, 'mousecancel', this);
  327. eventOperation(target, 'mouseup', this);
  328. }
  329. if (_util.hasTouch && !this.options.disableTouch) {
  330. eventOperation(this.wrapper, 'touchstart', this);
  331. eventOperation(target, 'touchmove', this);
  332. eventOperation(target, 'touchcancel', this);
  333. eventOperation(target, 'touchend', this);
  334. }
  335. eventOperation(this.scroller, _util.style.transitionEnd, this);
  336. }
  337. }, {
  338. key: '_start',
  339. value: function _start(e) {
  340. var _eventType = _util.eventType[e.type];
  341. if (_eventType !== TOUCH_EVENT) {
  342. if (e.button !== 0) {
  343. return;
  344. }
  345. }
  346. if (!this.enabled || this.initiated && this.initiated !== _eventType) {
  347. return;
  348. }
  349. this.initiated = _eventType;
  350. if (this.options.preventDefault && !_util.isBadAndroid && !(0, _util.preventDefaultException)(e.target, this.options.preventDefaultException)) {
  351. e.preventDefault();
  352. }
  353. this.moved = false;
  354. this.distX = 0;
  355. this.distY = 0;
  356. this.directionX = 0;
  357. this.directionY = 0;
  358. this.directionLocked = 0;
  359. this._transitionTime();
  360. this.startTime = +new Date();
  361. if (this.options.wheel) {
  362. this.target = e.target;
  363. }
  364. if (this.options.useTransition && this.isInTransition) {
  365. this.isInTransition = false;
  366. var pos = this.getComputedPosition();
  367. this._translate(Math.round(pos.x), Math.round(pos.y));
  368. if (this.options.wheel) {
  369. this.target = this.items[Math.round(-pos.y / this.itemHeight)];
  370. } else {
  371. this.trigger('scrollEnd');
  372. }
  373. }
  374. var point = e.touches ? e.touches[0] : e;
  375. this.startX = this.x;
  376. this.startY = this.y;
  377. this.absStartX = this.x;
  378. this.absStartY = this.y;
  379. this.pointX = point.pageX;
  380. this.pointY = point.pageY;
  381. this.trigger('beforeScrollStart');
  382. }
  383. }, {
  384. key: '_move',
  385. value: function _move(e) {
  386. if (!this.enabled || _util.eventType[e.type] !== this.initiated) {
  387. return;
  388. }
  389. if (this.options.preventDefault) {
  390. e.preventDefault();
  391. }
  392. var point = e.touches ? e.touches[0] : e;
  393. var deltaX = point.pageX - this.pointX;
  394. var deltaY = point.pageY - this.pointY;
  395. this.pointX = point.pageX;
  396. this.pointY = point.pageY;
  397. this.distX += deltaX;
  398. this.distY += deltaY;
  399. var absDistX = Math.abs(this.distX);
  400. var absDistY = Math.abs(this.distY);
  401. var timestamp = +new Date();
  402. if (timestamp - this.endTime > this.options.momentumLimitTime && absDistY < this.options.momentumLimitDistance && absDistX < this.options.momentumLimitDistance) {
  403. return;
  404. }
  405. if (!this.directionLocked && !this.options.freeScroll) {
  406. if (absDistX > absDistY + this.options.directionLockThreshold) {
  407. this.directionLocked = 'h';
  408. } else if (absDistY >= absDistX + this.options.directionLockThreshold) {
  409. this.directionLocked = 'v';
  410. } else {
  411. this.directionLocked = 'n';
  412. }
  413. }
  414. if (this.directionLocked === 'h') {
  415. if (this.options.eventPassthrough === 'vertical') {
  416. e.preventDefault();
  417. } else if (this.options.eventPassthrough === 'horizontal') {
  418. this.initiated = false;
  419. return;
  420. }
  421. deltaY = 0;
  422. } else if (this.directionLocked === 'v') {
  423. if (this.options.eventPassthrough === 'horizontal') {
  424. e.preventDefault();
  425. } else if (this.options.eventPassthrough === 'vertical') {
  426. this.initiated = false;
  427. return;
  428. }
  429. deltaX = 0;
  430. }
  431. deltaX = this.hasHorizontalScroll ? deltaX : 0;
  432. deltaY = this.hasVerticalScroll ? deltaY : 0;
  433. var newX = this.x + deltaX;
  434. var newY = this.y + deltaY;
  435. if (newX > 0 || newX < this.maxScrollX) {
  436. if (this.options.bounce) {
  437. newX = this.x + deltaX / 3;
  438. } else {
  439. newX = newX > 0 ? 0 : this.maxScrollX;
  440. }
  441. }
  442. if (newY > 0 || newY < this.maxScrollY) {
  443. if (this.options.bounce) {
  444. newY = this.y + deltaY / 3;
  445. } else {
  446. newY = newY > 0 ? 0 : this.maxScrollY;
  447. }
  448. }
  449. this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
  450. this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
  451. if (!this.moved) {
  452. this.moved = true;
  453. this.trigger('scrollStart');
  454. }
  455. this._translate(newX, newY);
  456. if (timestamp - this.startTime > this.options.momentumLimitTime) {
  457. this.startTime = timestamp;
  458. this.startX = this.x;
  459. this.startY = this.y;
  460. if (this.options.probeType === 1) {
  461. this.trigger('scroll', {
  462. x: this.x,
  463. y: this.y
  464. });
  465. }
  466. }
  467. if (this.options.probeType > 1) {
  468. this.trigger('scroll', {
  469. x: this.x,
  470. y: this.y
  471. });
  472. }
  473. var scrollLeft = document.documentElement.scrollLeft || window.pageXOffset || document.body.scrollLeft;
  474. var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  475. var pX = this.pointX - scrollLeft;
  476. var pY = this.pointY - scrollTop;
  477. if (pX > document.documentElement.clientWidth - this.options.momentumLimitDistance || pX < this.options.momentumLimitDistance || pY < this.options.momentumLimitDistance || pY > document.documentElement.clientHeight - this.options.momentumLimitDistance) {
  478. this._end(e);
  479. }
  480. }
  481. }, {
  482. key: '_end',
  483. value: function _end(e) {
  484. if (!this.enabled || _util.eventType[e.type] !== this.initiated) {
  485. return;
  486. }
  487. this.initiated = false;
  488. if (this.options.preventDefault && !(0, _util.preventDefaultException)(e.target, this.options.preventDefaultException)) {
  489. e.preventDefault();
  490. }
  491. this.trigger('touchend', {
  492. x: this.x,
  493. y: this.y
  494. });
  495. if (this.resetPosition(this.options.bounceTime, _util.ease.bounce)) {
  496. return;
  497. }
  498. this.isInTransition = false;
  499. var newX = Math.round(this.x);
  500. var newY = Math.round(this.y);
  501. if (!this.moved) {
  502. if (this.options.wheel) {
  503. if (this.target && this.target.className === 'wheel-scroll') {
  504. var index = Math.abs(Math.round(newY / this.itemHeight));
  505. var _offset = Math.round((this.pointY + (0, _util.offset)(this.target).top - this.itemHeight / 2) / this.itemHeight);
  506. this.target = this.items[index + _offset];
  507. }
  508. this.scrollToElement(this.target, this.options.adjustTime, true, true, _util.ease.swipe);
  509. } else {
  510. if (this.options.tap) {
  511. (0, _util.tap)(e, this.options.tap);
  512. }
  513. if (this.options.click) {
  514. (0, _util.click)(e);
  515. }
  516. }
  517. this.trigger('scrollCancel');
  518. return;
  519. }
  520. this.scrollTo(newX, newY);
  521. this.endTime = +new Date();
  522. var duration = this.endTime - this.startTime;
  523. var absDistX = Math.abs(newX - this.startX);
  524. var absDistY = Math.abs(newY - this.startY);
  525. if (this._events.flick && duration < this.options.momentumLimitTime && absDistX < this.options.momentumLimitDistance && absDistY < this.options.momentumLimitDistance) {
  526. this.trigger('flick');
  527. return;
  528. }
  529. var time = 0;
  530. if (this.options.momentum && duration < this.options.momentumLimitTime && (absDistY > this.options.momentumLimitDistance || absDistX > this.options.momentumLimitDistance)) {
  531. var momentumX = this.hasHorizontalScroll ? (0, _util.momentum)(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options) : { destination: newX, duration: 0 };
  532. var momentumY = this.hasVerticalScroll ? (0, _util.momentum)(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options) : { destination: newY, duration: 0 };
  533. newX = momentumX.destination;
  534. newY = momentumY.destination;
  535. time = Math.max(momentumX.duration, momentumY.duration);
  536. this.isInTransition = 1;
  537. } else {
  538. if (this.options.wheel) {
  539. newY = Math.round(newY / this.itemHeight) * this.itemHeight;
  540. time = this.options.adjustTime;
  541. }
  542. }
  543. var easing = _util.ease.swipe;
  544. if (this.options.snap) {
  545. var snap = this._nearestSnap(newX, newY);
  546. this.currentPage = snap;
  547. time = this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(newX - snap.x), 1000), Math.min(Math.abs(newY - snap.y), 1000)), 300);
  548. newX = snap.x;
  549. newY = snap.y;
  550. this.directionX = 0;
  551. this.directionY = 0;
  552. easing = _util.ease.bounce;
  553. }
  554. if (newX !== this.x || newY !== this.y) {
  555. if (newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) {
  556. easing = _util.ease.swipeBounce;
  557. }
  558. this.scrollTo(newX, newY, time, easing);
  559. return;
  560. }
  561. if (this.options.wheel) {
  562. this.selectedIndex = Math.abs(this.y / this.itemHeight) | 0;
  563. }
  564. this.trigger('scrollEnd');
  565. }
  566. }, {
  567. key: '_resize',
  568. value: function _resize() {
  569. var _this3 = this;
  570. if (!this.enabled) {
  571. return;
  572. }
  573. clearTimeout(this.resizeTimeout);
  574. this.resizeTimeout = setTimeout(function () {
  575. _this3.refresh();
  576. }, this.options.resizePolling);
  577. }
  578. }, {
  579. key: '_startProbe',
  580. value: function _startProbe() {
  581. (0, _util.cancelAnimationFrame)(this.probeTimer);
  582. this.probeTimer = (0, _util.requestAnimationFrame)(probe);
  583. var me = this;
  584. function probe() {
  585. var pos = me.getComputedPosition();
  586. me.trigger('scroll', pos);
  587. if (me.isInTransition) {
  588. me.probeTimer = (0, _util.requestAnimationFrame)(probe);
  589. }
  590. }
  591. }
  592. }, {
  593. key: '_transitionTime',
  594. value: function _transitionTime() {
  595. var _this4 = this;
  596. var time = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
  597. this.scrollerStyle[_util.style.transitionDuration] = time + 'ms';
  598. if (this.options.wheel && !_util.isBadAndroid) {
  599. for (var i = 0; i < this.itemLen; i++) {
  600. this.items[i].style[_util.style.transitionDuration] = time + 'ms';
  601. }
  602. }
  603. if (!time && _util.isBadAndroid) {
  604. this.scrollerStyle[_util.style.transitionDuration] = '0.001s';
  605. (0, _util.requestAnimationFrame)(function () {
  606. if (_this4.scrollerStyle[_util.style.transitionDuration] === '0.0001ms') {
  607. _this4.scrollerStyle[_util.style.transitionDuration] = '0s';
  608. }
  609. });
  610. }
  611. }
  612. }, {
  613. key: '_transitionTimingFunction',
  614. value: function _transitionTimingFunction(easing) {
  615. this.scrollerStyle[_util.style.transitionTimingFunction] = easing;
  616. if (this.options.wheel && !_util.isBadAndroid) {
  617. for (var i = 0; i < this.itemLen; i++) {
  618. this.items[i].style[_util.style.transitionTimingFunction] = easing;
  619. }
  620. }
  621. }
  622. }, {
  623. key: '_transitionEnd',
  624. value: function _transitionEnd(e) {
  625. if (e.target !== this.scroller || !this.isInTransition) {
  626. return;
  627. }
  628. this._transitionTime();
  629. if (!this.resetPosition(this.options.bounceTime, _util.ease.bounce)) {
  630. this.isInTransition = false;
  631. this.trigger('scrollEnd');
  632. }
  633. }
  634. }, {
  635. key: '_translate',
  636. value: function _translate(x, y) {
  637. if (this.options.useTransform) {
  638. this.scrollerStyle[_util.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ;
  639. } else {
  640. x = Math.round(x);
  641. y = Math.round(y);
  642. this.scrollerStyle.left = x + 'px';
  643. this.scrollerStyle.top = y + 'px';
  644. }
  645. if (this.options.wheel && !_util.isBadAndroid) {
  646. for (var i = 0; i < this.itemLen; i++) {
  647. var deg = this.options.rotate * (y / this.itemHeight + i);
  648. this.items[i].style[_util.style.transform] = 'rotateX(' + deg + 'deg)';
  649. }
  650. }
  651. this.x = x;
  652. this.y = y;
  653. }
  654. }, {
  655. key: 'enable',
  656. value: function enable() {
  657. this.enabled = true;
  658. }
  659. }, {
  660. key: 'disable',
  661. value: function disable() {
  662. this.enabled = false;
  663. }
  664. }, {
  665. key: 'refresh',
  666. value: function refresh() {
  667. var rf = this.wrapper.offsetHeight;
  668. this.wrapperWidth = parseInt(this.wrapper.style.width) || this.wrapper.clientWidth;
  669. this.wrapperHeight = parseInt(this.wrapper.style.height) || this.wrapper.clientHeight;
  670. this.scrollerWidth = parseInt(this.scroller.style.width) || this.scroller.clientWidth;
  671. this.scrollerHeight = parseInt(this.scroller.style.height) || this.scroller.clientHeight;
  672. if (this.options.wheel) {
  673. this.items = this.scroller.children;
  674. this.options.itemHeight = this.itemHeight = this.items.length ? this.items[0].clientHeight : 0;
  675. if (this.selectedIndex === undefined) {
  676. this.selectedIndex = this.options.selectedIndex;
  677. }
  678. this.options.startY = -this.selectedIndex * this.itemHeight;
  679. this.itemLen = this.items.length;
  680. this.maxScrollX = 0;
  681. this.maxScrollY = -this.itemHeight * (this.itemLen - 1);
  682. } else {
  683. this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
  684. this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
  685. }
  686. this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
  687. this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
  688. if (!this.hasHorizontalScroll) {
  689. this.maxScrollX = 0;
  690. this.scrollerWidth = this.wrapperWidth;
  691. }
  692. if (!this.hasVerticalScroll) {
  693. this.maxScrollY = 0;
  694. this.scrollerHeight = this.wrapperHeight;
  695. }
  696. this.endTime = 0;
  697. this.directionX = 0;
  698. this.directionY = 0;
  699. this.wrapperOffset = (0, _util.offset)(this.wrapper);
  700. this.trigger('refresh');
  701. this.resetPosition();
  702. }
  703. }, {
  704. key: 'resetPosition',
  705. value: function resetPosition() {
  706. var time = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
  707. var easeing = arguments.length <= 1 || arguments[1] === undefined ? _util.ease.bounce : arguments[1];
  708. var x = this.x;
  709. if (!this.hasHorizontalScroll || x > 0) {
  710. x = 0;
  711. } else if (x < this.maxScrollX) {
  712. x = this.maxScrollX;
  713. }
  714. var y = this.y;
  715. if (!this.hasVerticalScroll || y > 0) {
  716. y = 0;
  717. } else if (y < this.maxScrollY) {
  718. y = this.maxScrollY;
  719. }
  720. if (x === this.x && y === this.y) {
  721. return false;
  722. }
  723. this.scrollTo(x, y, time, easeing);
  724. return true;
  725. }
  726. }, {
  727. key: 'wheelTo',
  728. value: function wheelTo(selectIndex) {
  729. if (this.options.wheel) {
  730. this.y = -selectIndex * this.itemHeight;
  731. this.scrollTo(0, this.y);
  732. }
  733. }
  734. }, {
  735. key: 'scrollBy',
  736. value: function scrollBy(x, y) {
  737. var time = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  738. var easing = arguments.length <= 3 || arguments[3] === undefined ? _util.ease.bounce : arguments[3];
  739. x = this.x + x;
  740. y = this.y + y;
  741. this.scrollTo(x, y, time, easing);
  742. }
  743. }, {
  744. key: 'scrollTo',
  745. value: function scrollTo(x, y, time) {
  746. var easing = arguments.length <= 3 || arguments[3] === undefined ? _util.ease.bounce : arguments[3];
  747. this.isInTransition = this.options.useTransition && time > 0 && (x !== this.x || y !== this.y);
  748. if (!time || this.options.useTransition) {
  749. this._transitionTimingFunction(easing.style);
  750. this._transitionTime(time);
  751. this._translate(x, y);
  752. if (time && this.options.probeType === 3) {
  753. this._startProbe();
  754. }
  755. if (this.options.wheel) {
  756. if (y > 0) {
  757. this.selectedIndex = 0;
  758. } else if (y < this.maxScrollY) {
  759. this.selectedIndex = this.itemLen - 1;
  760. } else {
  761. this.selectedIndex = Math.abs(y / this.itemHeight) | 0;
  762. }
  763. }
  764. }
  765. }
  766. }, {
  767. key: 'getSelectedIndex',
  768. value: function getSelectedIndex() {
  769. return this.options.wheel && this.selectedIndex;
  770. }
  771. }, {
  772. key: 'getCurrentPage',
  773. value: function getCurrentPage() {
  774. return this.options.snap && this.currentPage;
  775. }
  776. }, {
  777. key: 'scrollToElement',
  778. value: function scrollToElement(el, time, offsetX, offsetY, easing) {
  779. if (!el) {
  780. return;
  781. }
  782. el = el.nodeType ? el : this.scroller.querySelector(el);
  783. if (this.options.wheel && el.className !== 'wheel-item') {
  784. return;
  785. }
  786. var pos = (0, _util.offset)(el);
  787. pos.left -= this.wrapperOffset.left;
  788. pos.top -= this.wrapperOffset.top;
  789. if (offsetX === true) {
  790. offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2);
  791. }
  792. if (offsetY === true) {
  793. offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2);
  794. }
  795. pos.left -= offsetX || 0;
  796. pos.top -= offsetY || 0;
  797. pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
  798. pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;
  799. if (this.options.wheel) {
  800. pos.top = Math.round(pos.top / this.itemHeight) * this.itemHeight;
  801. }
  802. time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x - pos.left), Math.abs(this.y - pos.top)) : time;
  803. this.scrollTo(pos.left, pos.top, time, easing);
  804. }
  805. }, {
  806. key: 'getComputedPosition',
  807. value: function getComputedPosition() {
  808. var matrix = window.getComputedStyle(this.scroller, null);
  809. var x = void 0;
  810. var y = void 0;
  811. if (this.options.useTransform) {
  812. matrix = matrix[_util.style.transform].split(')')[0].split(', ');
  813. x = +(matrix[12] || matrix[4]);
  814. y = +(matrix[13] || matrix[5]);
  815. } else {
  816. x = +matrix.left.replace(/[^-\d.]/g, '');
  817. y = +matrix.top.replace(/[^-\d.]/g, '');
  818. }
  819. return {
  820. x: x,
  821. y: y
  822. };
  823. }
  824. }, {
  825. key: 'goToPage',
  826. value: function goToPage(x, y, time) {
  827. var easing = arguments.length <= 3 || arguments[3] === undefined ? _util.ease.bounce : arguments[3];
  828. if (x >= this.pages.length) {
  829. x = this.pages.length - 1;
  830. } else if (x < 0) {
  831. x = 0;
  832. }
  833. if (y >= this.pages[x].length) {
  834. y = this.pages[x].length - 1;
  835. } else if (y < 0) {
  836. y = 0;
  837. }
  838. var posX = this.pages[x][y].x;
  839. var posY = this.pages[x][y].y;
  840. time = time === undefined ? this.options.snapSpeed || Math.max(Math.max(Math.min(Math.abs(posX - this.x), 1000), Math.min(Math.abs(posY - this.y), 1000)), 300) : time;
  841. this.currentPage = {
  842. x: posX,
  843. y: posY,
  844. pageX: x,
  845. pageY: y
  846. };
  847. this.scrollTo(posX, posY, time, easing);
  848. }
  849. }, {
  850. key: 'next',
  851. value: function next(time, easing) {
  852. var x = this.currentPage.pageX;
  853. var y = this.currentPage.pageY;
  854. x++;
  855. if (x >= this.pages.length && this.hasVerticalScroll) {
  856. x = 0;
  857. y++;
  858. }
  859. this.goToPage(x, y, time, easing);
  860. }
  861. }, {
  862. key: 'prev',
  863. value: function prev(time, easing) {
  864. var x = this.currentPage.pageX;
  865. var y = this.currentPage.pageY;
  866. x--;
  867. if (x < 0 && this.hasVerticalScroll) {
  868. x = 0;
  869. y--;
  870. }
  871. this.goToPage(x, y, time, easing);
  872. }
  873. }, {
  874. key: 'destroy',
  875. value: function destroy() {
  876. this._removeEvents();
  877. this.trigger('destroy');
  878. }
  879. }, {
  880. key: 'handleEvent',
  881. value: function handleEvent(e) {
  882. switch (e.type) {
  883. case 'touchstart':
  884. case 'mousedown':
  885. this._start(e);
  886. break;
  887. case 'touchmove':
  888. case 'mousemove':
  889. this._move(e);
  890. break;
  891. case 'touchend':
  892. case 'mouseup':
  893. case 'touchcancel':
  894. case 'mousecancel':
  895. this._end(e);
  896. break;
  897. case 'orientationchange':
  898. case 'resize':
  899. this._resize();
  900. break;
  901. case 'transitionend':
  902. case 'webkitTransitionEnd':
  903. case 'oTransitionEnd':
  904. case 'MSTransitionEnd':
  905. this._transitionEnd(e);
  906. break;
  907. case 'click':
  908. if (this.enabled && !e._constructed && !/(SELECT|INPUT|TEXTAREA)/i.test(e.target.tagName)) {
  909. e.preventDefault();
  910. e.stopPropagation();
  911. }
  912. break;
  913. }
  914. }
  915. }]);
  916. return BScroll;
  917. }(_util.EventEmitter);
  918. ;
  919. /***/ },
  920. /* 2 */
  921. /***/ function(module, exports, __webpack_require__) {
  922. 'use strict';
  923. Object.defineProperty(exports, "__esModule", {
  924. value: true
  925. });
  926. var _dom = __webpack_require__(3);
  927. Object.keys(_dom).forEach(function (key) {
  928. if (key === "default" || key === "__esModule") return;
  929. Object.defineProperty(exports, key, {
  930. enumerable: true,
  931. get: function get() {
  932. return _dom[key];
  933. }
  934. });
  935. });
  936. var _env = __webpack_require__(4);
  937. Object.keys(_env).forEach(function (key) {
  938. if (key === "default" || key === "__esModule") return;
  939. Object.defineProperty(exports, key, {
  940. enumerable: true,
  941. get: function get() {
  942. return _env[key];
  943. }
  944. });
  945. });
  946. var _ease = __webpack_require__(5);
  947. Object.keys(_ease).forEach(function (key) {
  948. if (key === "default" || key === "__esModule") return;
  949. Object.defineProperty(exports, key, {
  950. enumerable: true,
  951. get: function get() {
  952. return _ease[key];
  953. }
  954. });
  955. });
  956. var _eventEmitter = __webpack_require__(6);
  957. Object.keys(_eventEmitter).forEach(function (key) {
  958. if (key === "default" || key === "__esModule") return;
  959. Object.defineProperty(exports, key, {
  960. enumerable: true,
  961. get: function get() {
  962. return _eventEmitter[key];
  963. }
  964. });
  965. });
  966. var _momentum = __webpack_require__(7);
  967. Object.keys(_momentum).forEach(function (key) {
  968. if (key === "default" || key === "__esModule") return;
  969. Object.defineProperty(exports, key, {
  970. enumerable: true,
  971. get: function get() {
  972. return _momentum[key];
  973. }
  974. });
  975. });
  976. var _lang = __webpack_require__(8);
  977. Object.keys(_lang).forEach(function (key) {
  978. if (key === "default" || key === "__esModule") return;
  979. Object.defineProperty(exports, key, {
  980. enumerable: true,
  981. get: function get() {
  982. return _lang[key];
  983. }
  984. });
  985. });
  986. /***/ },
  987. /* 3 */
  988. /***/ function(module, exports) {
  989. 'use strict';
  990. Object.defineProperty(exports, "__esModule", {
  991. value: true
  992. });
  993. exports.addEvent = addEvent;
  994. exports.removeEvent = removeEvent;
  995. exports.offset = offset;
  996. exports.getRect = getRect;
  997. exports.preventDefaultException = preventDefaultException;
  998. exports.tap = tap;
  999. exports.click = click;
  1000. exports.prepend = prepend;
  1001. exports.before = before;
  1002. var elementStyle = document.createElement('div').style;
  1003. var vendor = function () {
  1004. var transformNames = {
  1005. webkit: 'webkitTransform',
  1006. Moz: 'MozTransform',
  1007. O: 'OTransform',
  1008. ms: 'msTransform',
  1009. standard: 'transform'
  1010. };
  1011. for (var key in transformNames) {
  1012. if (elementStyle[transformNames[key]] !== undefined) {
  1013. return key;
  1014. }
  1015. }
  1016. return false;
  1017. }();
  1018. function prefixStyle(style) {
  1019. if (vendor === false) {
  1020. return false;
  1021. }
  1022. if (vendor === 'standard') {
  1023. return style;
  1024. }
  1025. return vendor + style.charAt(0).toUpperCase() + style.substr(1);
  1026. }
  1027. function addEvent(el, type, fn, capture) {
  1028. el.addEventListener(type, fn, { passive: false, capture: !!capture });
  1029. };
  1030. function removeEvent(el, type, fn, capture) {
  1031. el.removeEventListener(type, fn, !!capture);
  1032. };
  1033. function offset(el) {
  1034. var left = 0;
  1035. var top = 0;
  1036. while (el) {
  1037. left -= el.offsetLeft;
  1038. top -= el.offsetTop;
  1039. el = el.offsetParent;
  1040. }
  1041. return {
  1042. left: left,
  1043. top: top
  1044. };
  1045. };
  1046. var transform = prefixStyle('transform');
  1047. var hasPerspective = exports.hasPerspective = prefixStyle('perspective') in elementStyle;
  1048. var hasTouch = exports.hasTouch = 'ontouchstart' in window;
  1049. var hasTransform = exports.hasTransform = transform !== false;
  1050. var hasTransition = exports.hasTransition = prefixStyle('transition') in elementStyle;
  1051. var style = exports.style = {
  1052. transform: transform,
  1053. transitionTimingFunction: prefixStyle('transitionTimingFunction'),
  1054. transitionDuration: prefixStyle('transitionDuration'),
  1055. transitionDelay: prefixStyle('transitionDelay'),
  1056. transformOrigin: prefixStyle('transformOrigin'),
  1057. transitionEnd: prefixStyle('transitionEnd')
  1058. };
  1059. var TOUCH_EVENT = 1;
  1060. var MOUSE_EVENT = 2;
  1061. var eventType = exports.eventType = {
  1062. touchstart: TOUCH_EVENT,
  1063. touchmove: TOUCH_EVENT,
  1064. touchend: TOUCH_EVENT,
  1065. mousedown: MOUSE_EVENT,
  1066. mousemove: MOUSE_EVENT,
  1067. mouseup: MOUSE_EVENT
  1068. };
  1069. function getRect(el) {
  1070. if (el instanceof window.SVGElement) {
  1071. var rect = el.getBoundingClientRect();
  1072. return {
  1073. top: rect.top,
  1074. left: rect.left,
  1075. width: rect.width,
  1076. height: rect.height
  1077. };
  1078. } else {
  1079. return {
  1080. top: el.offsetTop,
  1081. left: el.offsetLeft,
  1082. width: el.offsetWidth,
  1083. height: el.offsetHeight
  1084. };
  1085. }
  1086. };
  1087. function preventDefaultException(el, exceptions) {
  1088. for (var i in exceptions) {
  1089. if (exceptions[i].test(el[i])) {
  1090. return true;
  1091. }
  1092. }
  1093. return false;
  1094. }
  1095. function tap(e, eventName) {
  1096. var ev = document.createEvent('Event');
  1097. ev.initEvent(eventName, true, true);
  1098. ev.pageX = e.pageX;
  1099. ev.pageY = e.pageY;
  1100. e.target.dispatchEvent(ev);
  1101. };
  1102. function click(e) {
  1103. var target = e.target;
  1104. if (!/(SELECT|INPUT|TEXTAREA)/i.test(target.tagName)) {
  1105. var ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
  1106. ev.initEvent('click', true, true);
  1107. ev._constructed = true;
  1108. target.dispatchEvent(ev);
  1109. }
  1110. };
  1111. function prepend(el, target) {
  1112. if (target.firstChild) {
  1113. before(el, target.firstChild);
  1114. } else {
  1115. target.appendChild(el);
  1116. }
  1117. }
  1118. function before(el, target) {
  1119. target.parentNode.insertBefore(el, target);
  1120. }
  1121. /***/ },
  1122. /* 4 */
  1123. /***/ function(module, exports) {
  1124. "use strict";
  1125. Object.defineProperty(exports, "__esModule", {
  1126. value: true
  1127. });
  1128. var isBadAndroid = exports.isBadAndroid = /Android /.test(window.navigator.appVersion) && !/Chrome\/\d/.test(window.navigator.appVersion);
  1129. /***/ },
  1130. /* 5 */
  1131. /***/ function(module, exports) {
  1132. 'use strict';
  1133. Object.defineProperty(exports, "__esModule", {
  1134. value: true
  1135. });
  1136. var ease = exports.ease = {
  1137. swipe: {
  1138. style: 'cubic-bezier(0.23, 1, 0.32, 1)',
  1139. fn: function fn(t) {
  1140. return 1 + --t * t * t * t * t;
  1141. }
  1142. },
  1143. swipeBounce: {
  1144. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  1145. fn: function fn(t) {
  1146. return t * (2 - t);
  1147. }
  1148. },
  1149. bounce: {
  1150. style: 'cubic-bezier(0.165, 0.84, 0.44, 1)',
  1151. fn: function fn(t) {
  1152. return 1 - --t * t * t * t;
  1153. }
  1154. }
  1155. };
  1156. /***/ },
  1157. /* 6 */
  1158. /***/ function(module, exports) {
  1159. "use strict";
  1160. Object.defineProperty(exports, "__esModule", {
  1161. value: true
  1162. });
  1163. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  1164. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1165. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  1166. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1167. var EventEmitter = exports.EventEmitter = function () {
  1168. function EventEmitter() {
  1169. _classCallCheck(this, EventEmitter);
  1170. this._events = {};
  1171. }
  1172. _createClass(EventEmitter, [{
  1173. key: "on",
  1174. value: function on(type, fn) {
  1175. var context = arguments.length <= 2 || arguments[2] === undefined ? this : arguments[2];
  1176. if (!this._events[type]) {
  1177. this._events[type] = [];
  1178. }
  1179. this._events[type].push([fn, context]);
  1180. }
  1181. }, {
  1182. key: "once",
  1183. value: function once(type, fn) {
  1184. var context = arguments.length <= 2 || arguments[2] === undefined ? this : arguments[2];
  1185. var fired = false;
  1186. function magic() {
  1187. this.off(type, magic);
  1188. if (!fired) {
  1189. fired = true;
  1190. fn.apply(context, arguments);
  1191. }
  1192. }
  1193. this.on(type, magic);
  1194. }
  1195. }, {
  1196. key: "off",
  1197. value: function off(type, fn) {
  1198. var _events = this._events[type];
  1199. if (!_events) {
  1200. return;
  1201. }
  1202. var count = _events.length;
  1203. while (count--) {
  1204. if (_events[count][0] === fn) {
  1205. _events[count][0] = undefined;
  1206. }
  1207. }
  1208. }
  1209. }, {
  1210. key: "trigger",
  1211. value: function trigger(type) {
  1212. var events = this._events[type];
  1213. if (!events) {
  1214. return;
  1215. }
  1216. var len = events.length;
  1217. var eventsCopy = [].concat(_toConsumableArray(events));
  1218. for (var i = 0; i < len; i++) {
  1219. var event = eventsCopy[i];
  1220. var _event = _slicedToArray(event, 2);
  1221. var fn = _event[0];
  1222. var context = _event[1];
  1223. if (fn) {
  1224. fn.apply(context, [].slice.call(arguments, 1));
  1225. }
  1226. }
  1227. }
  1228. }]);
  1229. return EventEmitter;
  1230. }();
  1231. /***/ },
  1232. /* 7 */
  1233. /***/ function(module, exports) {
  1234. "use strict";
  1235. Object.defineProperty(exports, "__esModule", {
  1236. value: true
  1237. });
  1238. exports.momentum = momentum;
  1239. function momentum(current, start, time, lowerMargin, wrapperSize, options) {
  1240. var distance = current - start;
  1241. var speed = Math.abs(distance) / time;
  1242. var deceleration = options.deceleration;
  1243. var itemHeight = options.itemHeight;
  1244. var swipeBounceTime = options.swipeBounceTime;
  1245. var bounceTime = options.bounceTime;
  1246. var duration = options.swipeTime;
  1247. var rate = options.wheel ? 4 : 15;
  1248. var destination = current + speed / deceleration * (distance < 0 ? -1 : 1);
  1249. if (options.wheel && itemHeight) {
  1250. destination = Math.round(destination / itemHeight) * itemHeight;
  1251. }
  1252. if (destination < lowerMargin) {
  1253. destination = wrapperSize ? lowerMargin - wrapperSize / rate * speed : lowerMargin;
  1254. duration = swipeBounceTime - bounceTime;
  1255. } else if (destination > 0) {
  1256. destination = wrapperSize ? wrapperSize / rate * speed : 0;
  1257. duration = swipeBounceTime - bounceTime;
  1258. }
  1259. return {
  1260. destination: Math.round(destination),
  1261. duration: duration
  1262. };
  1263. };
  1264. /***/ },
  1265. /* 8 */
  1266. /***/ function(module, exports) {
  1267. "use strict";
  1268. Object.defineProperty(exports, "__esModule", {
  1269. value: true
  1270. });
  1271. exports.extend = extend;
  1272. function extend(target, source) {
  1273. for (var key in source) {
  1274. target[key] = source[key];
  1275. }
  1276. };
  1277. var DEFAULT_INTERVAL = 100 / 60;
  1278. var requestAnimationFrame = exports.requestAnimationFrame = function () {
  1279. return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || function (callback) {
  1280. return window.setTimeout(callback, (callback.interval || DEFAULT_INTERVAL) / 2);
  1281. };
  1282. }();
  1283. var cancelAnimationFrame = exports.cancelAnimationFrame = function () {
  1284. return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || function (id) {
  1285. window.clearTimeout(id);
  1286. };
  1287. }();
  1288. /***/ }
  1289. /******/ ])
  1290. });
  1291. ;