jquery-asHoverScroll.js 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. /**
  2. * jQuery asHoverScroll v0.3.7
  3. * https://github.com/amazingSurge/jquery-asHoverScroll
  4. *
  5. * Copyright (c) amazingSurge
  6. * Released under the LGPL-3.0 license
  7. */
  8. (function(global, factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. define(['jquery'], factory);
  11. } else if (typeof exports !== 'undefined') {
  12. factory(require('jquery'));
  13. } else {
  14. var mod = {
  15. exports: {}
  16. };
  17. factory(global.jQuery);
  18. global.jqueryAsHoverScrollEs = mod.exports;
  19. }
  20. })(this, function(_jquery) {
  21. 'use strict';
  22. var _jquery2 = _interopRequireDefault(_jquery);
  23. function _interopRequireDefault(obj) {
  24. return obj && obj.__esModule
  25. ? obj
  26. : {
  27. default: obj
  28. };
  29. }
  30. function _classCallCheck(instance, Constructor) {
  31. if (!(instance instanceof Constructor)) {
  32. throw new TypeError('Cannot call a class as a function');
  33. }
  34. }
  35. var _createClass = (function() {
  36. function defineProperties(target, props) {
  37. for (var i = 0; i < props.length; i++) {
  38. var descriptor = props[i];
  39. descriptor.enumerable = descriptor.enumerable || false;
  40. descriptor.configurable = true;
  41. if ('value' in descriptor) descriptor.writable = true;
  42. Object.defineProperty(target, descriptor.key, descriptor);
  43. }
  44. }
  45. return function(Constructor, protoProps, staticProps) {
  46. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  47. if (staticProps) defineProperties(Constructor, staticProps);
  48. return Constructor;
  49. };
  50. })();
  51. var DEFAULTS = {
  52. namespace: 'asHoverScroll',
  53. list: '> ul',
  54. item: '> li',
  55. exception: null,
  56. direction: 'vertical',
  57. fixed: false,
  58. mouseMove: true,
  59. touchScroll: true,
  60. pointerScroll: true,
  61. useCssTransforms: true,
  62. useCssTransforms3d: true,
  63. boundary: 10,
  64. throttle: 20,
  65. onEnter: function onEnter() {
  66. $(this)
  67. .siblings()
  68. .removeClass('is-active');
  69. $(this).addClass('is-active');
  70. },
  71. onLeave: function onLeave() {
  72. $(this).removeClass('is-active');
  73. }
  74. };
  75. /**
  76. * Css features detect
  77. **/
  78. var support = {};
  79. (function(support) {
  80. /**
  81. * Borrowed from Owl carousel
  82. **/
  83. 'use strict';
  84. var events = {
  85. transition: {
  86. end: {
  87. WebkitTransition: 'webkitTransitionEnd',
  88. MozTransition: 'transitionend',
  89. OTransition: 'oTransitionEnd',
  90. transition: 'transitionend'
  91. }
  92. },
  93. animation: {
  94. end: {
  95. WebkitAnimation: 'webkitAnimationEnd',
  96. MozAnimation: 'animationend',
  97. OAnimation: 'oAnimationEnd',
  98. animation: 'animationend'
  99. }
  100. }
  101. },
  102. prefixes = ['webkit', 'Moz', 'O', 'ms'],
  103. style = (0, _jquery2.default)('<support>').get(0).style,
  104. tests = {
  105. csstransforms: function csstransforms() {
  106. return Boolean(test('transform'));
  107. },
  108. csstransforms3d: function csstransforms3d() {
  109. return Boolean(test('perspective'));
  110. },
  111. csstransitions: function csstransitions() {
  112. return Boolean(test('transition'));
  113. },
  114. cssanimations: function cssanimations() {
  115. return Boolean(test('animation'));
  116. }
  117. };
  118. var test = function test(property, prefixed) {
  119. var result = false,
  120. upper = property.charAt(0).toUpperCase() + property.slice(1);
  121. if (style[property] !== undefined) {
  122. result = property;
  123. }
  124. if (!result) {
  125. _jquery2.default.each(prefixes, function(i, prefix) {
  126. if (style[prefix + upper] !== undefined) {
  127. result = '-' + prefix.toLowerCase() + '-' + upper;
  128. return false;
  129. }
  130. return true;
  131. });
  132. }
  133. if (prefixed) {
  134. return result;
  135. }
  136. if (result) {
  137. return true;
  138. }
  139. return false;
  140. };
  141. var prefixed = function prefixed(property) {
  142. return test(property, true);
  143. };
  144. if (tests.csstransitions()) {
  145. /*eslint no-new-wrappers: "off"*/
  146. support.transition = new String(prefixed('transition'));
  147. support.transition.end = events.transition.end[support.transition];
  148. }
  149. if (tests.cssanimations()) {
  150. /*eslint no-new-wrappers: "off"*/
  151. support.animation = new String(prefixed('animation'));
  152. support.animation.end = events.animation.end[support.animation];
  153. }
  154. if (tests.csstransforms()) {
  155. /*eslint no-new-wrappers: "off"*/
  156. support.transform = new String(prefixed('transform'));
  157. support.transform3d = tests.csstransforms3d();
  158. }
  159. if (
  160. 'ontouchstart' in window ||
  161. (window.DocumentTouch && document instanceof window.DocumentTouch)
  162. ) {
  163. support.touch = true;
  164. } else {
  165. support.touch = false;
  166. }
  167. if (window.PointerEvent || window.MSPointerEvent) {
  168. support.pointer = true;
  169. } else {
  170. support.pointer = false;
  171. }
  172. support.convertMatrixToArray = function(value) {
  173. if (value && value.substr(0, 6) === 'matrix') {
  174. return value
  175. .replace(/^.*\((.*)\)$/g, '$1')
  176. .replace(/px/g, '')
  177. .split(/, +/);
  178. }
  179. return false;
  180. };
  181. support.prefixPointerEvent = function(pointerEvent) {
  182. var charStart = 9,
  183. subStart = 10;
  184. return window.MSPointerEvent
  185. ? 'MSPointer' +
  186. pointerEvent.charAt(charStart).toUpperCase() +
  187. pointerEvent.substr(subStart)
  188. : pointerEvent;
  189. };
  190. })(support);
  191. var NAMESPACE$1 = 'asHoverScroll';
  192. var instanceId = 0;
  193. /**
  194. * Plugin constructor
  195. **/
  196. var asHoverScroll = (function() {
  197. function asHoverScroll(element, options) {
  198. _classCallCheck(this, asHoverScroll);
  199. this.element = element;
  200. this.$element = (0, _jquery2.default)(element);
  201. this.options = _jquery2.default.extend(
  202. {},
  203. DEFAULTS,
  204. options,
  205. this.$element.data()
  206. );
  207. this.$list = (0, _jquery2.default)(this.options.list, this.$element);
  208. this.classes = {
  209. disabled: this.options.namespace + '-disabled'
  210. };
  211. if (this.options.direction === 'vertical') {
  212. this.attributes = {
  213. page: 'pageY',
  214. axis: 'Y',
  215. position: 'top',
  216. length: 'height',
  217. offset: 'offsetTop',
  218. client: 'clientY',
  219. clientLength: 'clientHeight'
  220. };
  221. } else if (this.options.direction === 'horizontal') {
  222. this.attributes = {
  223. page: 'pageX',
  224. axis: 'X',
  225. position: 'left',
  226. length: 'width',
  227. offset: 'offsetLeft',
  228. client: 'clientX',
  229. clientLength: 'clientWidth'
  230. };
  231. }
  232. // Current state information.
  233. this._states = {};
  234. // Current state information for the touch operation.
  235. this._scroll = {
  236. time: null,
  237. pointer: null
  238. };
  239. this.instanceId = ++instanceId;
  240. this.trigger('init');
  241. this.init();
  242. }
  243. _createClass(
  244. asHoverScroll,
  245. [
  246. {
  247. key: 'init',
  248. value: function init() {
  249. this.initPosition();
  250. // init length data
  251. this.updateLength();
  252. this.bindEvents();
  253. }
  254. },
  255. {
  256. key: 'bindEvents',
  257. value: function bindEvents() {
  258. var _this = this;
  259. var that = this;
  260. var enterEvents = ['enter'];
  261. var leaveEvents = [];
  262. if (this.options.mouseMove) {
  263. this.$element.on(
  264. this.eventName('mousemove'),
  265. _jquery2.default.proxy(this.onMove, this)
  266. );
  267. enterEvents.push('mouseenter');
  268. leaveEvents.push('mouseleave');
  269. }
  270. if (this.options.touchScroll && support.touch) {
  271. this.$element.on(
  272. this.eventName('touchstart'),
  273. _jquery2.default.proxy(this.onScrollStart, this)
  274. );
  275. this.$element.on(
  276. this.eventName('touchcancel'),
  277. _jquery2.default.proxy(this.onScrollEnd, this)
  278. );
  279. }
  280. if (this.options.pointerScroll && support.pointer) {
  281. this.$element.on(
  282. this.eventName(support.prefixPointerEvent('pointerdown')),
  283. _jquery2.default.proxy(this.onScrollStart, this)
  284. );
  285. // fixed by FreMaNgo
  286. // this.$element.on(this.eventName(support.prefixPointerEvent('pointerdown')),(e) => {
  287. // let isUp = false;
  288. // this.$element.one('pointerup', () => {
  289. // isUp = true;
  290. // });
  291. // window.setTimeout(() => {
  292. // if(isUp){
  293. // return false;
  294. // }else{
  295. // this.$element.off('pointerup');
  296. // $.proxy(this.onScrollStart, this)(e);
  297. // }
  298. // }, 100)
  299. // });
  300. // fixed by FreMaNgo -- END
  301. this.$element.on(
  302. this.eventName(support.prefixPointerEvent('pointercancel')),
  303. _jquery2.default.proxy(this.onScrollEnd, this)
  304. );
  305. }
  306. this.$list.on(
  307. this.eventName(enterEvents.join(' ')),
  308. this.options.item,
  309. function() {
  310. if (!that.is('scrolling')) {
  311. that.options.onEnter.call(_this);
  312. }
  313. }
  314. );
  315. this.$list.on(
  316. this.eventName(leaveEvents.join(' ')),
  317. this.options.item,
  318. function() {
  319. if (!that.is('scrolling')) {
  320. that.options.onLeave.call(_this);
  321. }
  322. }
  323. );
  324. (0, _jquery2.default)(window).on(
  325. this.eventNameWithId('orientationchange'),
  326. function() {
  327. that.update();
  328. }
  329. );
  330. (0, _jquery2.default)(window).on(
  331. this.eventNameWithId('resize'),
  332. this.throttle(function() {
  333. that.update();
  334. }, this.options.throttle)
  335. );
  336. }
  337. },
  338. {
  339. key: 'unbindEvents',
  340. value: function unbindEvents() {
  341. this.$element.off(this.eventName());
  342. this.$list.off(this.eventName());
  343. (0, _jquery2.default)(window).off(this.eventNameWithId());
  344. }
  345. },
  346. {
  347. key: 'onScrollStart',
  348. value: function onScrollStart(event) {
  349. var _this2 = this;
  350. var that = this;
  351. if (this.is('scrolling')) {
  352. return;
  353. }
  354. if (event.which === 3) {
  355. return;
  356. }
  357. if (
  358. (0, _jquery2.default)(event.target).closest(
  359. this.options.exception
  360. ).length > 0
  361. ) {
  362. return;
  363. }
  364. this._scroll.time = new Date().getTime();
  365. this._scroll.pointer = this.pointer(event);
  366. this._scroll.start = this.getPosition();
  367. this._scroll.moved = false;
  368. var callback = function callback() {
  369. _this2.enter('scrolling');
  370. _this2.trigger('scroll');
  371. };
  372. if (this.options.touchScroll && support.touch) {
  373. (0, _jquery2.default)(document).on(
  374. this.eventName('touchend'),
  375. _jquery2.default.proxy(this.onScrollEnd, this)
  376. );
  377. (0, _jquery2.default)(document).one(
  378. this.eventName('touchmove'),
  379. _jquery2.default.proxy(function() {
  380. if (!this.is('scrolling')) {
  381. (0, _jquery2.default)(document).on(
  382. that.eventName('touchmove'),
  383. _jquery2.default.proxy(this.onScrollMove, this)
  384. );
  385. callback();
  386. }
  387. }, this)
  388. );
  389. }
  390. if (this.options.pointerScroll && support.pointer) {
  391. (0, _jquery2.default)(document).on(
  392. this.eventName(support.prefixPointerEvent('pointerup')),
  393. _jquery2.default.proxy(this.onScrollEnd, this)
  394. );
  395. (0, _jquery2.default)(document).one(
  396. this.eventName(support.prefixPointerEvent('pointermove')),
  397. _jquery2.default.proxy(function() {
  398. if (!this.is('scrolling')) {
  399. (0, _jquery2.default)(document).on(
  400. that.eventName(support.prefixPointerEvent('pointermove')),
  401. _jquery2.default.proxy(this.onScrollMove, this)
  402. );
  403. callback();
  404. }
  405. }, this)
  406. );
  407. }
  408. (0, _jquery2.default)(document).on(
  409. this.eventName('blur'),
  410. _jquery2.default.proxy(this.onScrollEnd, this)
  411. );
  412. event.preventDefault();
  413. }
  414. },
  415. {
  416. key: 'onScrollMove',
  417. value: function onScrollMove(event) {
  418. this._scroll.updated = this.pointer(event);
  419. var distance = this.distance(
  420. this._scroll.pointer,
  421. this._scroll.updated
  422. );
  423. if (
  424. Math.abs(this._scroll.pointer.x - this._scroll.updated.x) > 10 ||
  425. Math.abs(this._scroll.pointer.y - this._scroll.updated.y) > 10
  426. ) {
  427. this._scroll.moved = true;
  428. }
  429. if (!this.is('scrolling')) {
  430. return;
  431. }
  432. event.preventDefault();
  433. var postion = this._scroll.start + distance;
  434. if (this.canScroll()) {
  435. if (postion > 0) {
  436. postion = 0;
  437. } else if (postion < this.containerLength - this.listLength) {
  438. postion = this.containerLength - this.listLength;
  439. }
  440. this.updatePosition(postion);
  441. }
  442. }
  443. },
  444. {
  445. key: 'onScrollEnd',
  446. value: function onScrollEnd(event) {
  447. if (!this._scroll.moved) {
  448. (0, _jquery2.default)(event.target).trigger('tap');
  449. }
  450. // if (!this.is('scrolling')) {
  451. // return;
  452. // }
  453. if (this.options.touchScroll && support.touch) {
  454. (0, _jquery2.default)(document).off(
  455. this.eventName('touchmove touchend')
  456. );
  457. }
  458. if (this.options.pointerScroll && support.pointer) {
  459. (0, _jquery2.default)(document).off(
  460. this.eventName(
  461. support.prefixPointerEvent('pointermove pointerup')
  462. )
  463. );
  464. }
  465. (0, _jquery2.default)(document).off(this.eventName('blur'));
  466. // touch will trigger mousemove event after 300ms delay. So we need avoid it
  467. // setTimeout(() => {
  468. this.leave('scrolling');
  469. this.trigger('scrolled');
  470. // }, 500);
  471. }
  472. },
  473. {
  474. key: 'pointer',
  475. value: function pointer(event) {
  476. var result = {
  477. x: null,
  478. y: null
  479. };
  480. event = this.getEvent(event);
  481. if (event.pageX && !this.options.fixed) {
  482. result.x = event.pageX;
  483. result.y = event.pageY;
  484. } else {
  485. result.x = event.clientX;
  486. result.y = event.clientY;
  487. }
  488. return result;
  489. }
  490. },
  491. {
  492. key: 'getEvent',
  493. value: function getEvent(event) {
  494. event = event.originalEvent || event || window.event;
  495. event =
  496. event.touches && event.touches.length
  497. ? event.touches[0]
  498. : event.changedTouches && event.changedTouches.length
  499. ? event.changedTouches[0]
  500. : event;
  501. return event;
  502. }
  503. },
  504. {
  505. key: 'distance',
  506. value: function distance(first, second) {
  507. if (this.options.direction === 'vertical') {
  508. return second.y - first.y;
  509. }
  510. return second.x - first.x;
  511. }
  512. },
  513. {
  514. key: 'onMove',
  515. value: function onMove(event) {
  516. event = this.getEvent(event);
  517. if (this.is('scrolling')) {
  518. return;
  519. }
  520. if (this.isMatchScroll(event)) {
  521. var pointer = void 0;
  522. var distance = void 0;
  523. var offset = void 0;
  524. if (event[this.attributes.page] && !this.options.fixed) {
  525. pointer = event[this.attributes.page];
  526. } else {
  527. pointer = event[this.attributes.client];
  528. }
  529. offset = pointer - this.element[this.attributes.offset];
  530. if (offset < this.options.boundary) {
  531. distance = 0;
  532. } else {
  533. distance = (offset - this.options.boundary) * this.multiplier;
  534. if (distance > this.listLength - this.containerLength) {
  535. distance = this.listLength - this.containerLength;
  536. }
  537. }
  538. this.updatePosition(-distance);
  539. }
  540. }
  541. },
  542. {
  543. key: 'isMatchScroll',
  544. value: function isMatchScroll(event) {
  545. if (!this.is('disabled') && this.canScroll()) {
  546. if (this.options.exception) {
  547. if (
  548. (0, _jquery2.default)(event.target).closest(
  549. this.options.exception
  550. ).length === 0
  551. ) {
  552. return true;
  553. }
  554. return false;
  555. }
  556. return true;
  557. }
  558. return false;
  559. }
  560. },
  561. {
  562. key: 'canScroll',
  563. value: function canScroll() {
  564. return this.listLength > this.containerLength;
  565. }
  566. },
  567. {
  568. key: 'getContainerLength',
  569. value: function getContainerLength() {
  570. return this.element[this.attributes.clientLength];
  571. }
  572. },
  573. {
  574. key: 'getListhLength',
  575. value: function getListhLength() {
  576. return this.$list[0][this.attributes.clientLength];
  577. }
  578. },
  579. {
  580. key: 'updateLength',
  581. value: function updateLength() {
  582. this.containerLength = this.getContainerLength();
  583. this.listLength = this.getListhLength();
  584. this.multiplier =
  585. (this.listLength - this.containerLength) /
  586. (this.containerLength - 2 * this.options.boundary);
  587. }
  588. },
  589. {
  590. key: 'initPosition',
  591. value: function initPosition() {
  592. var style = this.makePositionStyle(0);
  593. this.$list.css(style);
  594. }
  595. },
  596. {
  597. key: 'getPosition',
  598. value: function getPosition() {
  599. var value = void 0;
  600. if (this.options.useCssTransforms && support.transform) {
  601. if (this.options.useCssTransforms3d && support.transform3d) {
  602. value = support.convertMatrixToArray(
  603. this.$list.css(support.transform)
  604. );
  605. } else {
  606. value = support.convertMatrixToArray(
  607. this.$list.css(support.transform)
  608. );
  609. }
  610. if (!value) {
  611. return 0;
  612. }
  613. if (this.attributes.axis === 'X') {
  614. value = value[12] || value[4];
  615. } else {
  616. value = value[13] || value[5];
  617. }
  618. } else {
  619. value = this.$list.css(this.attributes.position);
  620. }
  621. return parseFloat(value.replace('px', ''));
  622. }
  623. },
  624. {
  625. key: 'makePositionStyle',
  626. value: function makePositionStyle(value) {
  627. var property = void 0;
  628. var x = '0px';
  629. var y = '0px';
  630. if (this.options.useCssTransforms && support.transform) {
  631. if (this.attributes.axis === 'X') {
  632. x = value + 'px';
  633. } else {
  634. y = value + 'px';
  635. }
  636. property = support.transform.toString();
  637. if (this.options.useCssTransforms3d && support.transform3d) {
  638. value = 'translate3d(' + x + ',' + y + ',0px)';
  639. } else {
  640. value = 'translate(' + x + ',' + y + ')';
  641. }
  642. } else {
  643. property = this.attributes.position;
  644. }
  645. var temp = {};
  646. temp[property] = value;
  647. return temp;
  648. }
  649. },
  650. {
  651. key: 'updatePosition',
  652. value: function updatePosition(value) {
  653. var style = this.makePositionStyle(value);
  654. this.$list.css(style);
  655. }
  656. },
  657. {
  658. key: 'update',
  659. value: function update() {
  660. if (!this.is('disabled')) {
  661. this.updateLength();
  662. if (!this.canScroll()) {
  663. this.initPosition();
  664. }
  665. }
  666. }
  667. },
  668. {
  669. key: 'eventName',
  670. value: function eventName(events) {
  671. if (typeof events !== 'string' || events === '') {
  672. return '.' + NAMESPACE$1;
  673. }
  674. events = events.split(' ');
  675. var length = events.length;
  676. for (var i = 0; i < length; i++) {
  677. events[i] = events[i] + '.' + NAMESPACE$1;
  678. }
  679. return events.join(' ');
  680. }
  681. },
  682. {
  683. key: 'eventNameWithId',
  684. value: function eventNameWithId(events) {
  685. if (typeof events !== 'string' || events === '') {
  686. return '.' + this.options.namespace + '-' + this.instanceId;
  687. }
  688. events = events.split(' ');
  689. var length = events.length;
  690. for (var i = 0; i < length; i++) {
  691. events[i] =
  692. events[i] +
  693. '.' +
  694. this.options.namespace +
  695. '-' +
  696. this.instanceId;
  697. }
  698. return events.join(' ');
  699. }
  700. },
  701. {
  702. key: 'trigger',
  703. value: function trigger(eventType) {
  704. for (
  705. var _len = arguments.length,
  706. params = Array(_len > 1 ? _len - 1 : 0),
  707. _key = 1;
  708. _key < _len;
  709. _key++
  710. ) {
  711. params[_key - 1] = arguments[_key];
  712. }
  713. var data = [this].concat(params);
  714. // event
  715. this.$element.trigger(NAMESPACE$1 + '::' + eventType, data);
  716. // callback
  717. eventType = eventType.replace(/\b\w+\b/g, function(word) {
  718. return word.substring(0, 1).toUpperCase() + word.substring(1);
  719. });
  720. var onFunction = 'on' + eventType;
  721. if (typeof this.options[onFunction] === 'function') {
  722. this.options[onFunction].apply(this, params);
  723. }
  724. }
  725. },
  726. {
  727. key: 'is',
  728. value: function is(state) {
  729. return this._states[state] && this._states[state] > 0;
  730. }
  731. },
  732. {
  733. key: 'enter',
  734. value: function enter(state) {
  735. if (this._states[state] === undefined) {
  736. this._states[state] = 0;
  737. }
  738. this._states[state] = 1;
  739. }
  740. },
  741. {
  742. key: 'leave',
  743. value: function leave(state) {
  744. this._states[state] = 0;
  745. }
  746. },
  747. {
  748. key: 'throttle',
  749. value: function throttle(func, wait) {
  750. var _this3 = this;
  751. var _now =
  752. Date.now ||
  753. function() {
  754. return new Date().getTime();
  755. };
  756. var timeout = void 0;
  757. var context = void 0;
  758. var args = void 0;
  759. var result = void 0;
  760. var previous = 0;
  761. var later = function later() {
  762. previous = _now();
  763. timeout = null;
  764. result = func.apply(context, args);
  765. if (!timeout) {
  766. context = args = null;
  767. }
  768. };
  769. return function() {
  770. for (
  771. var _len2 = arguments.length, params = Array(_len2), _key2 = 0;
  772. _key2 < _len2;
  773. _key2++
  774. ) {
  775. params[_key2] = arguments[_key2];
  776. }
  777. /*eslint consistent-this: "off"*/
  778. var now = _now();
  779. var remaining = wait - (now - previous);
  780. context = _this3;
  781. args = params;
  782. if (remaining <= 0 || remaining > wait) {
  783. if (timeout) {
  784. clearTimeout(timeout);
  785. timeout = null;
  786. }
  787. previous = now;
  788. result = func.apply(context, args);
  789. if (!timeout) {
  790. context = args = null;
  791. }
  792. } else if (!timeout) {
  793. timeout = setTimeout(later, remaining);
  794. }
  795. return result;
  796. };
  797. }
  798. },
  799. {
  800. key: 'enable',
  801. value: function enable() {
  802. if (this.is('disabled')) {
  803. this.leave('disabled');
  804. this.$element.removeClass(this.classes.disabled);
  805. this.bindEvents();
  806. }
  807. this.trigger('enable');
  808. }
  809. },
  810. {
  811. key: 'disable',
  812. value: function disable() {
  813. if (!this.is('disabled')) {
  814. this.enter('disabled');
  815. this.initPosition();
  816. this.$element.addClass(this.classes.disabled);
  817. this.unbindEvents();
  818. }
  819. this.trigger('disable');
  820. }
  821. },
  822. {
  823. key: 'destroy',
  824. value: function destroy() {
  825. this.$element.removeClass(this.classes.disabled);
  826. this.unbindEvents();
  827. this.$element.data(NAMESPACE$1, null);
  828. this.trigger('destroy');
  829. }
  830. }
  831. ],
  832. [
  833. {
  834. key: 'setDefaults',
  835. value: function setDefaults(options) {
  836. _jquery2.default.extend(
  837. DEFAULTS,
  838. _jquery2.default.isPlainObject(options) && options
  839. );
  840. }
  841. }
  842. ]
  843. );
  844. return asHoverScroll;
  845. })();
  846. var info = {
  847. version: '0.3.7'
  848. };
  849. var NAMESPACE = 'asHoverScroll';
  850. var OtherAsHoverScroll = _jquery2.default.fn.asHoverScroll;
  851. var jQueryAsHoverScroll = function jQueryAsHoverScroll(options) {
  852. for (
  853. var _len3 = arguments.length,
  854. args = Array(_len3 > 1 ? _len3 - 1 : 0),
  855. _key3 = 1;
  856. _key3 < _len3;
  857. _key3++
  858. ) {
  859. args[_key3 - 1] = arguments[_key3];
  860. }
  861. if (typeof options === 'string') {
  862. var method = options;
  863. if (/^_/.test(method)) {
  864. return false;
  865. } else if (/^(get)/.test(method)) {
  866. var instance = this.first().data(NAMESPACE);
  867. if (instance && typeof instance[method] === 'function') {
  868. return instance[method].apply(instance, args);
  869. }
  870. } else {
  871. return this.each(function() {
  872. var instance = _jquery2.default.data(this, NAMESPACE);
  873. if (instance && typeof instance[method] === 'function') {
  874. instance[method].apply(instance, args);
  875. }
  876. });
  877. }
  878. }
  879. return this.each(function() {
  880. if (!(0, _jquery2.default)(this).data(NAMESPACE)) {
  881. (0, _jquery2.default)(this).data(
  882. NAMESPACE,
  883. new asHoverScroll(this, options)
  884. );
  885. }
  886. });
  887. };
  888. _jquery2.default.fn.asHoverScroll = jQueryAsHoverScroll;
  889. _jquery2.default.asHoverScroll = _jquery2.default.extend(
  890. {
  891. setDefaults: asHoverScroll.setDefaults,
  892. noConflict: function noConflict() {
  893. _jquery2.default.fn.asHoverScroll = OtherAsHoverScroll;
  894. return jQueryAsHoverScroll;
  895. }
  896. },
  897. info
  898. );
  899. });