25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { __extends } from "tslib";
  2. import './polyfills';
  3. import { scrollbarMap, Scrollbar, } from './scrollbar';
  4. import { addPlugins, ScrollbarPlugin, } from './plugin';
  5. import { attachStyle, detachStyle, } from './style';
  6. export { ScrollbarPlugin };
  7. /*!
  8. * cast `I.Scrollbar` to `Scrollbar` to avoid error
  9. *
  10. * `I.Scrollbar` is not assignable to `Scrollbar`:
  11. * "privateProp" is missing in `I.Scrollbar`
  12. *
  13. * @see https://github.com/Microsoft/TypeScript/issues/2672
  14. */
  15. var SmoothScrollbar = /** @class */ (function (_super) {
  16. __extends(SmoothScrollbar, _super);
  17. function SmoothScrollbar() {
  18. return _super !== null && _super.apply(this, arguments) || this;
  19. }
  20. /**
  21. * Initializes a scrollbar on the given element.
  22. *
  23. * @param elem The DOM element that you want to initialize scrollbar to
  24. * @param [options] Initial options
  25. */
  26. SmoothScrollbar.init = function (elem, options) {
  27. if (!elem || elem.nodeType !== 1) {
  28. throw new TypeError("expect element to be DOM Element, but got " + elem);
  29. }
  30. // attach stylesheet
  31. attachStyle();
  32. if (scrollbarMap.has(elem)) {
  33. return scrollbarMap.get(elem);
  34. }
  35. return new Scrollbar(elem, options);
  36. };
  37. /**
  38. * Automatically init scrollbar on all elements base on the selector `[data-scrollbar]`
  39. *
  40. * @param options Initial options
  41. */
  42. SmoothScrollbar.initAll = function (options) {
  43. return Array.from(document.querySelectorAll('[data-scrollbar]'), function (elem) {
  44. return SmoothScrollbar.init(elem, options);
  45. });
  46. };
  47. /**
  48. * Check if there is a scrollbar on given element
  49. *
  50. * @param elem The DOM element that you want to check
  51. */
  52. SmoothScrollbar.has = function (elem) {
  53. return scrollbarMap.has(elem);
  54. };
  55. /**
  56. * Gets scrollbar on the given element.
  57. * If no scrollbar instance exsits, returns `undefined`
  58. *
  59. * @param elem The DOM element that you want to check.
  60. */
  61. SmoothScrollbar.get = function (elem) {
  62. return scrollbarMap.get(elem);
  63. };
  64. /**
  65. * Returns an array that contains all scrollbar instances
  66. */
  67. SmoothScrollbar.getAll = function () {
  68. return Array.from(scrollbarMap.values());
  69. };
  70. /**
  71. * Removes scrollbar on the given element
  72. */
  73. SmoothScrollbar.destroy = function (elem) {
  74. var scrollbar = scrollbarMap.get(elem);
  75. if (scrollbar) {
  76. scrollbar.destroy();
  77. }
  78. };
  79. /**
  80. * Removes all scrollbar instances from current document
  81. */
  82. SmoothScrollbar.destroyAll = function () {
  83. scrollbarMap.forEach(function (scrollbar) {
  84. scrollbar.destroy();
  85. });
  86. };
  87. /**
  88. * Attaches plugins to scrollbars
  89. *
  90. * @param ...Plugins Scrollbar plugin classes
  91. */
  92. SmoothScrollbar.use = function () {
  93. var Plugins = [];
  94. for (var _i = 0; _i < arguments.length; _i++) {
  95. Plugins[_i] = arguments[_i];
  96. }
  97. return addPlugins.apply(void 0, Plugins);
  98. };
  99. /**
  100. * Attaches default style sheets to current document.
  101. * You don't need to call this method manually unless
  102. * you removed the default styles via `Scrollbar.detachStyle()`
  103. */
  104. SmoothScrollbar.attachStyle = function () {
  105. return attachStyle();
  106. };
  107. /**
  108. * Removes default styles from current document.
  109. * Use this method when you want to use your own css for scrollbars.
  110. */
  111. SmoothScrollbar.detachStyle = function () {
  112. return detachStyle();
  113. };
  114. SmoothScrollbar.version = "8.5.2";
  115. SmoothScrollbar.ScrollbarPlugin = ScrollbarPlugin;
  116. return SmoothScrollbar;
  117. }(Scrollbar));
  118. export default SmoothScrollbar;
  119. //# sourceMappingURL=index.js.map