jquery-asScrollable.es.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /**
  2. * jQuery asScrollable v0.4.10
  3. * https://github.com/amazingSurge/jquery-asScrollable
  4. *
  5. * Copyright (c) amazingSurge
  6. * Released under the LGPL-3.0 license
  7. */
  8. import $ from 'jquery';
  9. var DEFAULTS = {
  10. namespace: 'asScrollable',
  11. skin: null,
  12. contentSelector: null,
  13. containerSelector: null,
  14. enabledClass: 'is-enabled',
  15. disabledClass: 'is-disabled',
  16. draggingClass: 'is-dragging',
  17. hoveringClass: 'is-hovering',
  18. scrollingClass: 'is-scrolling',
  19. direction: 'vertical', // vertical, horizontal, both, auto
  20. showOnHover: true,
  21. showOnBarHover: false,
  22. duration: 500,
  23. easing: 'ease-in', // linear, ease, ease-in, ease-out, ease-in-out
  24. responsive: true,
  25. throttle: 20,
  26. scrollbar: {}
  27. };
  28. function getTime() {
  29. if (typeof window.performance !== 'undefined' && window.performance.now) {
  30. return window.performance.now();
  31. }
  32. return Date.now();
  33. }
  34. function isPercentage(n) {
  35. return typeof n === 'string' && n.indexOf('%') !== -1;
  36. }
  37. function conventToPercentage(n) {
  38. if (n < 0) {
  39. n = 0;
  40. } else if (n > 1) {
  41. n = 1;
  42. }
  43. return `${parseFloat(n).toFixed(4) * 100}%`;
  44. }
  45. function convertPercentageToFloat(n) {
  46. return parseFloat(n.slice(0, -1) / 100, 10);
  47. }
  48. let isFFLionScrollbar = (() => {
  49. 'use strict';
  50. let isOSXFF, ua, version;
  51. ua = window.navigator.userAgent;
  52. isOSXFF = /(?=.+Mac OS X)(?=.+Firefox)/.test(ua);
  53. if (!isOSXFF) {
  54. return false;
  55. }
  56. version = /Firefox\/\d{2}\./.exec(ua);
  57. if (version) {
  58. version = version[0].replace(/\D+/g, '');
  59. }
  60. return isOSXFF && +version > 23;
  61. })();
  62. const NAMESPACE$1 = 'asScrollable';
  63. let instanceId = 0;
  64. class AsScrollable {
  65. constructor(element, options) {
  66. this.$element = $(element);
  67. options = this.options = $.extend({}, DEFAULTS, options || {}, this.$element.data('options') || {});
  68. this.classes = {
  69. wrap: options.namespace,
  70. content: `${options.namespace}-content`,
  71. container: `${options.namespace}-container`,
  72. bar: `${options.namespace}-bar`,
  73. barHide: `${options.namespace}-bar-hide`,
  74. skin: options.skin
  75. };
  76. this.attributes = {
  77. vertical: {
  78. axis: 'Y',
  79. overflow: 'overflow-y',
  80. scroll: 'scrollTop',
  81. scrollLength: 'scrollHeight',
  82. pageOffset: 'pageYOffset',
  83. ffPadding: 'padding-right',
  84. length: 'height',
  85. clientLength: 'clientHeight',
  86. offset: 'offsetHeight',
  87. crossLength: 'width',
  88. crossClientLength: 'clientWidth',
  89. crossOffset: 'offsetWidth'
  90. },
  91. horizontal: {
  92. axis: 'X',
  93. overflow: 'overflow-x',
  94. scroll: 'scrollLeft',
  95. scrollLength: 'scrollWidth',
  96. pageOffset: 'pageXOffset',
  97. ffPadding: 'padding-bottom',
  98. length: 'width',
  99. clientLength: 'clientWidth',
  100. offset: 'offsetWidth',
  101. crossLength: 'height',
  102. crossClientLength: 'clientHeight',
  103. crossOffset: 'offsetHeight'
  104. }
  105. };
  106. // Current state information.
  107. this._states = {};
  108. // Supported direction
  109. this.horizontal = null;
  110. this.vertical = null;
  111. this.$bar = null;
  112. // Current timeout
  113. this._frameId = null;
  114. this._timeoutId = null;
  115. this.instanceId = (++instanceId);
  116. this.easing = $.asScrollbar.getEasing(this.options.easing) || $.asScrollbar.getEasing('ease');
  117. this.init();
  118. }
  119. init() {
  120. let position = this.$element.css('position');
  121. if (this.options.containerSelector) {
  122. this.$container = this.$element.find(this.options.containerSelector);
  123. this.$wrap = this.$element;
  124. if (position === 'static') {
  125. this.$wrap.css('position', 'relative');
  126. }
  127. } else {
  128. this.$container = this.$element.wrap('<div>');
  129. this.$wrap = this.$container.parent();
  130. this.$wrap.height(this.$element.height());
  131. if (position !== 'static') {
  132. this.$wrap.css('position', position);
  133. } else {
  134. this.$wrap.css('position', 'relative');
  135. }
  136. }
  137. if (this.options.contentSelector) {
  138. this.$content = this.$container.find(this.options.contentSelector);
  139. } else {
  140. this.$content = this.$container.wrap('<div>');
  141. this.$container = this.$content.parent();
  142. }
  143. switch (this.options.direction) {
  144. case 'vertical': {
  145. this.vertical = true;
  146. break;
  147. }
  148. case 'horizontal': {
  149. this.horizontal = true;
  150. break;
  151. }
  152. case 'both': {
  153. this.horizontal = true;
  154. this.vertical = true;
  155. break;
  156. }
  157. case 'auto': {
  158. let overflowX = this.$element.css('overflow-x'),
  159. overflowY = this.$element.css('overflow-y');
  160. if (overflowX === 'scroll' || overflowX === 'auto') {
  161. this.horizontal = true;
  162. }
  163. if (overflowY === 'scroll' || overflowY === 'auto') {
  164. this.vertical = true;
  165. }
  166. break;
  167. }
  168. default: {
  169. break;
  170. }
  171. }
  172. if (!this.vertical && !this.horizontal) {
  173. return;
  174. }
  175. this.$wrap.addClass(this.classes.wrap);
  176. this.$container.addClass(this.classes.container);
  177. this.$content.addClass(this.classes.content);
  178. if (this.options.skin) {
  179. this.$wrap.addClass(this.classes.skin);
  180. }
  181. this.$wrap.addClass(this.options.enabledClass);
  182. if (this.vertical) {
  183. this.$wrap.addClass(`${this.classes.wrap}-vertical`);
  184. this.initLayout('vertical');
  185. this.createBar('vertical');
  186. }
  187. if (this.horizontal) {
  188. this.$wrap.addClass(`${this.classes.wrap}-horizontal`);
  189. this.initLayout('horizontal');
  190. this.createBar('horizontal');
  191. }
  192. this.bindEvents();
  193. this.trigger('ready');
  194. }
  195. bindEvents() {
  196. if (this.options.responsive) {
  197. $(window).on(this.eventNameWithId('orientationchange'), () => {
  198. this.update();
  199. });
  200. $(window).on(this.eventNameWithId('resize'), this.throttle(() => {
  201. this.update();
  202. }, this.options.throttle));
  203. }
  204. if (!this.horizontal && !this.vertical) {
  205. return;
  206. }
  207. let that = this;
  208. this.$wrap.on(this.eventName('mouseenter'), () => {
  209. that.$wrap.addClass(this.options.hoveringClass);
  210. that.enter('hovering');
  211. that.trigger('hover');
  212. });
  213. this.$wrap.on(this.eventName('mouseleave'), () => {
  214. that.$wrap.removeClass(this.options.hoveringClass);
  215. if (!that.is('hovering')) {
  216. return;
  217. }
  218. that.leave('hovering');
  219. that.trigger('hovered');
  220. });
  221. if (this.options.showOnHover) {
  222. if (this.options.showOnBarHover) {
  223. this.$bar.on('asScrollbar::hover', () => {
  224. if(that.horizontal){
  225. that.showBar('horizontal');
  226. }
  227. if(that.vertical){
  228. that.showBar('vertical');
  229. }
  230. }).on('asScrollbar::hovered', () => {
  231. if(that.horizontal){
  232. that.hideBar('horizontal');
  233. }
  234. if(that.vertical){
  235. that.hideBar('vertical');
  236. }
  237. });
  238. } else {
  239. this.$element.on(`${NAMESPACE$1}::hover`, $.proxy(this.showBar, this));
  240. this.$element.on(`${NAMESPACE$1}::hovered`, $.proxy(this.hideBar, this));
  241. }
  242. }
  243. this.$container.on(this.eventName('scroll'), () => {
  244. if (that.horizontal) {
  245. let oldLeft = that.offsetLeft;
  246. that.offsetLeft = that.getOffset('horizontal');
  247. if (oldLeft !== that.offsetLeft) {
  248. that.trigger('scroll', that.getPercentOffset('horizontal'), 'horizontal');
  249. if (that.offsetLeft === 0) {
  250. that.trigger('scrolltop', 'horizontal');
  251. }
  252. if (that.offsetLeft === that.getScrollLength('horizontal')) {
  253. that.trigger('scrollend', 'horizontal');
  254. }
  255. }
  256. }
  257. if (that.vertical) {
  258. let oldTop = that.offsetTop;
  259. that.offsetTop = that.getOffset('vertical');
  260. if (oldTop !== that.offsetTop) {
  261. that.trigger('scroll', that.getPercentOffset('vertical'), 'vertical');
  262. if (that.offsetTop === 0) {
  263. that.trigger('scrolltop', 'vertical');
  264. }
  265. if (that.offsetTop === that.getScrollLength('vertical')) {
  266. that.trigger('scrollend', 'vertical');
  267. }
  268. }
  269. }
  270. });
  271. this.$element.on(`${NAMESPACE$1}::scroll`, (e, api, value, direction) => {
  272. if (!that.is('scrolling')) {
  273. that.enter('scrolling');
  274. that.$wrap.addClass(that.options.scrollingClass);
  275. }
  276. let bar = api.getBarApi(direction);
  277. bar.moveTo(conventToPercentage(value), false, true);
  278. clearTimeout(that._timeoutId);
  279. that._timeoutId = setTimeout(() => {
  280. that.$wrap.removeClass(that.options.scrollingClass);
  281. that.leave('scrolling');
  282. }, 200);
  283. });
  284. this.$bar.on('asScrollbar::change', (e, api, value) => {
  285. if(typeof e.target.direction === 'string') {
  286. that.scrollTo(e.target.direction, conventToPercentage(value), false, true);
  287. }
  288. });
  289. this.$bar.on('asScrollbar::drag', () => {
  290. that.$wrap.addClass(that.options.draggingClass);
  291. }).on('asScrollbar::dragged', () => {
  292. that.$wrap.removeClass(that.options.draggingClass);
  293. });
  294. }
  295. unbindEvents() {
  296. this.$wrap.off(this.eventName());
  297. this.$element.off(`${NAMESPACE$1}::scroll`).off(`${NAMESPACE$1}::hover`).off(`${NAMESPACE$1}::hovered`);
  298. this.$container.off(this.eventName());
  299. $(window).off(this.eventNameWithId());
  300. }
  301. initLayout(direction) {
  302. if (direction === 'vertical') {
  303. this.$container.css('height', this.$wrap.height());
  304. }
  305. let attributes = this.attributes[direction],
  306. container = this.$container[0];
  307. // this.$container.css(attributes.overflow, 'scroll');
  308. let parentLength = container.parentNode[attributes.crossClientLength],
  309. scrollbarWidth = this.getBrowserScrollbarWidth(direction);
  310. this.$content.css(attributes.crossLength, `${parentLength}px`);
  311. this.$container.css(attributes.crossLength, `${scrollbarWidth + parentLength}px`);
  312. if (scrollbarWidth === 0 && isFFLionScrollbar) {
  313. this.$container.css(attributes.ffPadding, 16);
  314. }
  315. }
  316. createBar(direction) {
  317. let options = $.extend(this.options.scrollbar, {
  318. namespace: this.classes.bar,
  319. direction: direction,
  320. useCssTransitions: false,
  321. keyboard: false
  322. });
  323. let $bar = $('<div>');
  324. $bar.asScrollbar(options);
  325. if (this.options.showOnHover) {
  326. $bar.addClass(this.classes.barHide);
  327. }
  328. $bar.appendTo(this.$wrap);
  329. this[`$${direction}`] = $bar;
  330. if (this.$bar === null) {
  331. this.$bar = $bar;
  332. } else {
  333. this.$bar = this.$bar.add($bar);
  334. }
  335. this.updateBarHandle(direction);
  336. }
  337. trigger(eventType, ...params) {
  338. const data = [this].concat(params);
  339. // event
  340. this.$element.trigger(`${NAMESPACE$1}::${eventType}`, data);
  341. // callback
  342. eventType = eventType.replace(/\b\w+\b/g, (word) => {
  343. return word.substring(0, 1).toUpperCase() + word.substring(1);
  344. });
  345. const onFunction = `on${eventType}`;
  346. if (typeof this.options[onFunction] === 'function') {
  347. this.options[onFunction].apply(this, params);
  348. }
  349. }
  350. /**
  351. * Checks whether the carousel is in a specific state or not.
  352. */
  353. is(state) {
  354. return this._states[state] && this._states[state] > 0;
  355. }
  356. /**
  357. * Enters a state.
  358. */
  359. enter(state) {
  360. if (this._states[state] === undefined) {
  361. this._states[state] = 0;
  362. }
  363. // this._states[state]++;
  364. this._states[state] = 1;
  365. }
  366. /**
  367. * Leaves a state.
  368. */
  369. leave(state) {
  370. // this._states[state]--;
  371. this._states[state] = -1;
  372. }
  373. eventName(events) {
  374. if (typeof events !== 'string' || events === '') {
  375. return `.${this.options.namespace}`;
  376. }
  377. events = events.split(' ');
  378. let length = events.length;
  379. for (let i = 0; i < length; i++) {
  380. events[i] = `${events[i]}.${this.options.namespace}`;
  381. }
  382. return events.join(' ');
  383. }
  384. eventNameWithId(events) {
  385. if (typeof events !== 'string' || events === '') {
  386. return `.${this.options.namespace}-${this.instanceId}`;
  387. }
  388. events = events.split(' ');
  389. let length = events.length;
  390. for (let i = 0; i < length; i++) {
  391. events[i] = `${events[i]}.${this.options.namespace}-${this.instanceId}`;
  392. }
  393. return events.join(' ');
  394. }
  395. /**
  396. * _throttle
  397. * @description Borrowed from Underscore.js
  398. */
  399. throttle(func, wait) {
  400. const _now = Date.now || function() {
  401. return new Date().getTime();
  402. };
  403. let timeout;
  404. let context;
  405. let args;
  406. let result;
  407. let previous = 0;
  408. let later = function() {
  409. previous = _now();
  410. timeout = null;
  411. result = func.apply(context, args);
  412. if (!timeout) {
  413. context = args = null;
  414. }
  415. };
  416. return (...params) => {
  417. /*eslint consistent-this: "off"*/
  418. let now = _now();
  419. let remaining = wait - (now - previous);
  420. context = this;
  421. args = params;
  422. if (remaining <= 0 || remaining > wait) {
  423. if (timeout) {
  424. clearTimeout(timeout);
  425. timeout = null;
  426. }
  427. previous = now;
  428. result = func.apply(context, args);
  429. if (!timeout) {
  430. context = args = null;
  431. }
  432. } else if (!timeout) {
  433. timeout = setTimeout(later, remaining);
  434. }
  435. return result;
  436. };
  437. }
  438. getBrowserScrollbarWidth(direction) {
  439. let attributes = this.attributes[direction],
  440. outer, outerStyle;
  441. if (attributes.scrollbarWidth) {
  442. return attributes.scrollbarWidth;
  443. }
  444. outer = document.createElement('div');
  445. outerStyle = outer.style;
  446. outerStyle.position = 'absolute';
  447. outerStyle.width = '100px';
  448. outerStyle.height = '100px';
  449. outerStyle.overflow = 'scroll';
  450. outerStyle.top = '-9999px';
  451. document.body.appendChild(outer);
  452. attributes.scrollbarWidth = outer[attributes.offset] - outer[attributes.clientLength];
  453. document.body.removeChild(outer);
  454. return attributes.scrollbarWidth;
  455. }
  456. getOffset(direction) {
  457. let attributes = this.attributes[direction],
  458. container = this.$container[0];
  459. return (container[attributes.pageOffset] || container[attributes.scroll]);
  460. }
  461. getPercentOffset(direction) {
  462. return this.getOffset(direction) / this.getScrollLength(direction);
  463. }
  464. getContainerLength(direction) {
  465. return this.$container[0][this.attributes[direction].clientLength];
  466. }
  467. getScrollLength(direction) {
  468. let scrollLength = this.$content[0][this.attributes[direction].scrollLength];
  469. return scrollLength - this.getContainerLength(direction);
  470. }
  471. scrollTo(direction, value, trigger, sync) {
  472. let type = typeof value;
  473. if (type === 'string') {
  474. if (isPercentage(value)) {
  475. value = convertPercentageToFloat(value) * this.getScrollLength(direction);
  476. }
  477. value = parseFloat(value);
  478. type = 'number';
  479. }
  480. if (type !== 'number') {
  481. return;
  482. }
  483. this.move(direction, value, trigger, sync);
  484. }
  485. scrollBy(direction, value, trigger, sync) {
  486. let type = typeof value;
  487. if (type === 'string') {
  488. if (isPercentage(value)) {
  489. value = convertPercentageToFloat(value) * this.getScrollLength(direction);
  490. }
  491. value = parseFloat(value);
  492. type = 'number';
  493. }
  494. if (type !== 'number') {
  495. return;
  496. }
  497. this.move(direction, this.getOffset(direction) + value, trigger, sync);
  498. }
  499. move(direction, value, trigger, sync) {
  500. if (this[direction] !== true || typeof value !== 'number') {
  501. return;
  502. }
  503. this.enter('moving');
  504. if (value < 0) {
  505. value = 0;
  506. } else if (value > this.getScrollLength(direction)) {
  507. value = this.getScrollLength(direction);
  508. }
  509. let attributes = this.attributes[direction];
  510. var that = this;
  511. let callback = () => {
  512. that.leave('moving');
  513. };
  514. if (sync) {
  515. this.$container[0][attributes.scroll] = value;
  516. if (trigger !== false) {
  517. this.trigger('change', value / this.getScrollLength(direction), direction);
  518. }
  519. callback();
  520. } else {
  521. this.enter('animating');
  522. let startTime = getTime();
  523. let start = this.getOffset(direction);
  524. let end = value;
  525. let run = (time) => {
  526. let percent = (time - startTime) / that.options.duration;
  527. if (percent > 1) {
  528. percent = 1;
  529. }
  530. percent = that.easing.fn(percent);
  531. let current = parseFloat(start + percent * (end - start), 10);
  532. that.$container[0][attributes.scroll] = current;
  533. if (trigger !== false) {
  534. that.trigger('change', value / that.getScrollLength(direction), direction);
  535. }
  536. if (percent === 1) {
  537. window.cancelAnimationFrame(that._frameId);
  538. that._frameId = null;
  539. that.leave('animating');
  540. callback();
  541. } else {
  542. that._frameId = window.requestAnimationFrame(run);
  543. }
  544. };
  545. this._frameId = window.requestAnimationFrame(run);
  546. }
  547. }
  548. scrollXto(value, trigger, sync) {
  549. return this.scrollTo('horizontal', value, trigger, sync);
  550. }
  551. scrollYto(value, trigger, sync) {
  552. return this.scrollTo('vertical', value, trigger, sync);
  553. }
  554. scrollXby(value, trigger, sync) {
  555. return this.scrollBy('horizontal', value, trigger, sync);
  556. }
  557. scrollYby(value, trigger, sync) {
  558. return this.scrollBy('vertical', value, trigger, sync);
  559. }
  560. getBar(direction) {
  561. if (direction && this[`$${direction}`]) {
  562. return this[`$${direction}`];
  563. }
  564. return this.$bar;
  565. }
  566. getBarApi(direction) {
  567. return this.getBar(direction).data('asScrollbar');
  568. }
  569. getBarX() {
  570. return this.getBar('horizontal');
  571. }
  572. getBarY() {
  573. return this.getBar('vertical');
  574. }
  575. showBar(direction) {
  576. this.getBar(direction).removeClass(this.classes.barHide);
  577. }
  578. hideBar(direction) {
  579. this.getBar(direction).addClass(this.classes.barHide);
  580. }
  581. updateBarHandle(direction) {
  582. let api = this.getBarApi(direction);
  583. if (!api) {
  584. return;
  585. }
  586. let containerLength = this.getContainerLength(direction),
  587. scrollLength = this.getScrollLength(direction);
  588. if (scrollLength > 0) {
  589. if (api.is('disabled')) {
  590. api.enable();
  591. }
  592. api.setHandleLength(api.getBarLength() * containerLength / (scrollLength + containerLength), true);
  593. } else {
  594. api.disable();
  595. }
  596. }
  597. disable() {
  598. if (!this.is('disabled')) {
  599. this.enter('disabled');
  600. this.$wrap.addClass(this.options.disabledClass).removeClass(this.options.enabledClass);
  601. this.unbindEvents();
  602. this.unStyle();
  603. }
  604. this.trigger('disable');
  605. }
  606. enable() {
  607. if (this.is('disabled')) {
  608. this.leave('disabled');
  609. this.$wrap.addClass(this.options.enabledClass).removeClass(this.options.disabledClass);
  610. this.bindEvents();
  611. this.update();
  612. }
  613. this.trigger('enable');
  614. }
  615. update() {
  616. if (this.is('disabled')) {
  617. return;
  618. }
  619. if(this.$element.is(':visible')) {
  620. if (this.vertical) {
  621. this.initLayout('vertical');
  622. this.updateBarHandle('vertical');
  623. }
  624. if (this.horizontal) {
  625. this.initLayout('horizontal');
  626. this.updateBarHandle('horizontal');
  627. }
  628. }
  629. }
  630. unStyle() {
  631. if (this.horizontal) {
  632. this.$container.css({
  633. height: '',
  634. 'padding-bottom': ''
  635. });
  636. this.$content.css({
  637. height: ''
  638. });
  639. }
  640. if (this.vertical) {
  641. this.$container.css({
  642. width: '',
  643. height: '',
  644. 'padding-right': ''
  645. });
  646. this.$content.css({
  647. width: ''
  648. });
  649. }
  650. if (!this.options.containerSelector) {
  651. this.$wrap.css({
  652. height: ''
  653. });
  654. }
  655. }
  656. destroy() {
  657. this.$wrap.removeClass(`${this.classes.wrap}-vertical`)
  658. .removeClass(`${this.classes.wrap}-horizontal`)
  659. .removeClass(this.classes.wrap)
  660. .removeClass(this.options.enabledClass)
  661. .removeClass(this.classes.disabledClass);
  662. this.unStyle();
  663. if (this.$bar) {
  664. this.$bar.remove();
  665. }
  666. this.unbindEvents();
  667. if (this.options.containerSelector) {
  668. this.$container.removeClass(this.classes.container);
  669. } else {
  670. this.$container.unwrap();
  671. }
  672. if (!this.options.contentSelector) {
  673. this.$content.unwrap();
  674. }
  675. this.$content.removeClass(this.classes.content);
  676. this.$element.data(NAMESPACE$1, null);
  677. this.trigger('destroy');
  678. }
  679. static setDefaults(options) {
  680. $.extend(DEFAULTS, $.isPlainObject(options) && options);
  681. }
  682. }
  683. var info = {
  684. version:'0.4.10'
  685. };
  686. const NAMESPACE = 'asScrollable';
  687. const OtherAsScrollable = $.fn.asScrollable;
  688. const jQueryAsScrollable = function(options, ...args) {
  689. if (typeof options === 'string') {
  690. let method = options;
  691. if (/^_/.test(method)) {
  692. return false;
  693. } else if ((/^(get)/.test(method))) {
  694. let instance = this.first().data(NAMESPACE);
  695. if (instance && typeof instance[method] === 'function') {
  696. return instance[method](...args);
  697. }
  698. } else {
  699. return this.each(function() {
  700. let instance = $.data(this, NAMESPACE);
  701. if (instance && typeof instance[method] === 'function') {
  702. instance[method](...args);
  703. }
  704. });
  705. }
  706. }
  707. return this.each(function() {
  708. if (!$(this).data(NAMESPACE)) {
  709. $(this).data(NAMESPACE, new AsScrollable(this, options));
  710. }
  711. });
  712. };
  713. $.fn.asScrollable = jQueryAsScrollable;
  714. $.asScrollable = $.extend({
  715. setDefaults: AsScrollable.setDefaults,
  716. noConflict: function() {
  717. $.fn.asScrollable = OtherAsScrollable;
  718. return jQueryAsScrollable;
  719. }
  720. }, info);