Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

207 строки
11 KiB

  1. /**
  2. * simplebar - v6.2.7
  3. * Scrollbars, simpler.
  4. * https://grsmto.github.io/simplebar/
  5. *
  6. * Made by Adrien Denat from a fork by Jonathan Nicol
  7. * Under MIT License
  8. */
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('simplebar-core')) :
  11. typeof define === 'function' && define.amd ? define(['exports', 'simplebar-core'], factory) :
  12. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SimpleBar = {}, global.SimpleBar));
  13. })(this, (function (exports, SimpleBarCore) { 'use strict';
  14. /******************************************************************************
  15. Copyright (c) Microsoft Corporation.
  16. Permission to use, copy, modify, and/or distribute this software for any
  17. purpose with or without fee is hereby granted.
  18. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  19. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  20. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  21. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  22. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  24. PERFORMANCE OF THIS SOFTWARE.
  25. ***************************************************************************** */
  26. /* global Reflect, Promise */
  27. var extendStatics = function(d, b) {
  28. extendStatics = Object.setPrototypeOf ||
  29. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  30. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  31. return extendStatics(d, b);
  32. };
  33. function __extends(d, b) {
  34. if (typeof b !== "function" && b !== null)
  35. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  36. extendStatics(d, b);
  37. function __() { this.constructor = d; }
  38. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  39. }
  40. var _a = SimpleBarCore.helpers, getOptions = _a.getOptions, addClasses = _a.addClasses, canUseDOM = _a.canUseDOM;
  41. var SimpleBar = /** @class */ (function (_super) {
  42. __extends(SimpleBar, _super);
  43. function SimpleBar() {
  44. var args = [];
  45. for (var _i = 0; _i < arguments.length; _i++) {
  46. args[_i] = arguments[_i];
  47. }
  48. var _this = _super.apply(this, args) || this;
  49. // // Save a reference to the instance, so we know this DOM node has already been instancied
  50. SimpleBar.instances.set(args[0], _this);
  51. return _this;
  52. }
  53. SimpleBar.initDOMLoadedElements = function () {
  54. document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  55. window.removeEventListener('load', this.initDOMLoadedElements);
  56. Array.prototype.forEach.call(document.querySelectorAll('[data-simplebar]'), function (el) {
  57. if (el.getAttribute('data-simplebar') !== 'init' &&
  58. !SimpleBar.instances.has(el))
  59. new SimpleBar(el, getOptions(el.attributes));
  60. });
  61. };
  62. SimpleBar.removeObserver = function () {
  63. var _a;
  64. (_a = SimpleBar.globalObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  65. };
  66. SimpleBar.prototype.initDOM = function () {
  67. var _this = this;
  68. var _a, _b, _c;
  69. // make sure this element doesn't have the elements yet
  70. if (!Array.prototype.filter.call(this.el.children, function (child) {
  71. return child.classList.contains(_this.classNames.wrapper);
  72. }).length) {
  73. // Prepare DOM
  74. this.wrapperEl = document.createElement('div');
  75. this.contentWrapperEl = document.createElement('div');
  76. this.offsetEl = document.createElement('div');
  77. this.maskEl = document.createElement('div');
  78. this.contentEl = document.createElement('div');
  79. this.placeholderEl = document.createElement('div');
  80. this.heightAutoObserverWrapperEl = document.createElement('div');
  81. this.heightAutoObserverEl = document.createElement('div');
  82. addClasses(this.wrapperEl, this.classNames.wrapper);
  83. addClasses(this.contentWrapperEl, this.classNames.contentWrapper);
  84. addClasses(this.offsetEl, this.classNames.offset);
  85. addClasses(this.maskEl, this.classNames.mask);
  86. addClasses(this.contentEl, this.classNames.contentEl);
  87. addClasses(this.placeholderEl, this.classNames.placeholder);
  88. addClasses(this.heightAutoObserverWrapperEl, this.classNames.heightAutoObserverWrapperEl);
  89. addClasses(this.heightAutoObserverEl, this.classNames.heightAutoObserverEl);
  90. while (this.el.firstChild) {
  91. this.contentEl.appendChild(this.el.firstChild);
  92. }
  93. this.contentWrapperEl.appendChild(this.contentEl);
  94. this.offsetEl.appendChild(this.contentWrapperEl);
  95. this.maskEl.appendChild(this.offsetEl);
  96. this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
  97. this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
  98. this.wrapperEl.appendChild(this.maskEl);
  99. this.wrapperEl.appendChild(this.placeholderEl);
  100. this.el.appendChild(this.wrapperEl);
  101. (_a = this.contentWrapperEl) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', this.options.tabIndex.toString());
  102. (_b = this.contentWrapperEl) === null || _b === void 0 ? void 0 : _b.setAttribute('role', 'region');
  103. (_c = this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-label', this.options.ariaLabel);
  104. }
  105. if (!this.axis.x.track.el || !this.axis.y.track.el) {
  106. var track = document.createElement('div');
  107. var scrollbar = document.createElement('div');
  108. addClasses(track, this.classNames.track);
  109. addClasses(scrollbar, this.classNames.scrollbar);
  110. track.appendChild(scrollbar);
  111. this.axis.x.track.el = track.cloneNode(true);
  112. addClasses(this.axis.x.track.el, this.classNames.horizontal);
  113. this.axis.y.track.el = track.cloneNode(true);
  114. addClasses(this.axis.y.track.el, this.classNames.vertical);
  115. this.el.appendChild(this.axis.x.track.el);
  116. this.el.appendChild(this.axis.y.track.el);
  117. }
  118. SimpleBarCore.prototype.initDOM.call(this);
  119. this.el.setAttribute('data-simplebar', 'init');
  120. };
  121. SimpleBar.prototype.unMount = function () {
  122. SimpleBarCore.prototype.unMount.call(this);
  123. SimpleBar.instances["delete"](this.el);
  124. };
  125. SimpleBar.initHtmlApi = function () {
  126. this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this);
  127. // MutationObserver is IE11+
  128. if (typeof MutationObserver !== 'undefined') {
  129. // Mutation observer to observe dynamically added elements
  130. this.globalObserver = new MutationObserver(SimpleBar.handleMutations);
  131. this.globalObserver.observe(document, { childList: true, subtree: true });
  132. }
  133. // Taken from jQuery `ready` function
  134. // Instantiate elements already present on the page
  135. if (document.readyState === 'complete' || // @ts-ignore: IE specific
  136. (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
  137. // Handle it asynchronously to allow scripts the opportunity to delay init
  138. window.setTimeout(this.initDOMLoadedElements);
  139. }
  140. else {
  141. document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  142. window.addEventListener('load', this.initDOMLoadedElements);
  143. }
  144. };
  145. SimpleBar.handleMutations = function (mutations) {
  146. mutations.forEach(function (mutation) {
  147. mutation.addedNodes.forEach(function (addedNode) {
  148. if (addedNode.nodeType === 1) {
  149. if (addedNode.hasAttribute('data-simplebar')) {
  150. !SimpleBar.instances.has(addedNode) &&
  151. document.documentElement.contains(addedNode) &&
  152. new SimpleBar(addedNode, getOptions(addedNode.attributes));
  153. }
  154. else {
  155. addedNode
  156. .querySelectorAll('[data-simplebar]')
  157. .forEach(function (el) {
  158. if (el.getAttribute('data-simplebar') !== 'init' &&
  159. !SimpleBar.instances.has(el) &&
  160. document.documentElement.contains(el))
  161. new SimpleBar(el, getOptions(el.attributes));
  162. });
  163. }
  164. }
  165. });
  166. mutation.removedNodes.forEach(function (removedNode) {
  167. var _a;
  168. if (removedNode.nodeType === 1) {
  169. if (removedNode.getAttribute('data-simplebar') === 'init') {
  170. !document.documentElement.contains(removedNode) &&
  171. ((_a = SimpleBar.instances.get(removedNode)) === null || _a === void 0 ? void 0 : _a.unMount());
  172. }
  173. else {
  174. Array.prototype.forEach.call(removedNode.querySelectorAll('[data-simplebar="init"]'), function (el) {
  175. var _a;
  176. !document.documentElement.contains(el) &&
  177. ((_a = SimpleBar.instances.get(el)) === null || _a === void 0 ? void 0 : _a.unMount());
  178. });
  179. }
  180. }
  181. });
  182. });
  183. };
  184. SimpleBar.instances = new WeakMap();
  185. return SimpleBar;
  186. }(SimpleBarCore));
  187. /**
  188. * HTML API
  189. * Called only in a browser env.
  190. */
  191. if (canUseDOM) {
  192. SimpleBar.initHtmlApi();
  193. }
  194. exports.default = SimpleBar;
  195. Object.defineProperty(exports, '__esModule', { value: true });
  196. }));