tab.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*!
  2. * Bootstrap tab.js v4.6.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
  8. typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tab = factory(global.jQuery, global.Util));
  10. })(this, (function ($, Util) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var $__default = /*#__PURE__*/_interopDefaultLegacy($);
  13. var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
  14. function _defineProperties(target, props) {
  15. for (var i = 0; i < props.length; i++) {
  16. var descriptor = props[i];
  17. descriptor.enumerable = descriptor.enumerable || false;
  18. descriptor.configurable = true;
  19. if ("value" in descriptor) descriptor.writable = true;
  20. Object.defineProperty(target, descriptor.key, descriptor);
  21. }
  22. }
  23. function _createClass(Constructor, protoProps, staticProps) {
  24. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  25. if (staticProps) _defineProperties(Constructor, staticProps);
  26. Object.defineProperty(Constructor, "prototype", {
  27. writable: false
  28. });
  29. return Constructor;
  30. }
  31. /**
  32. * Constants
  33. */
  34. var NAME = 'tab';
  35. var VERSION = '4.6.2';
  36. var DATA_KEY = 'bs.tab';
  37. var EVENT_KEY = "." + DATA_KEY;
  38. var DATA_API_KEY = '.data-api';
  39. var JQUERY_NO_CONFLICT = $__default["default"].fn[NAME];
  40. var CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu';
  41. var CLASS_NAME_ACTIVE = 'active';
  42. var CLASS_NAME_DISABLED = 'disabled';
  43. var CLASS_NAME_FADE = 'fade';
  44. var CLASS_NAME_SHOW = 'show';
  45. var EVENT_HIDE = "hide" + EVENT_KEY;
  46. var EVENT_HIDDEN = "hidden" + EVENT_KEY;
  47. var EVENT_SHOW = "show" + EVENT_KEY;
  48. var EVENT_SHOWN = "shown" + EVENT_KEY;
  49. var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
  50. var SELECTOR_DROPDOWN = '.dropdown';
  51. var SELECTOR_NAV_LIST_GROUP = '.nav, .list-group';
  52. var SELECTOR_ACTIVE = '.active';
  53. var SELECTOR_ACTIVE_UL = '> li > .active';
  54. var SELECTOR_DATA_TOGGLE = '[data-toggle="tab"], [data-toggle="pill"], [data-toggle="list"]';
  55. var SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
  56. var SELECTOR_DROPDOWN_ACTIVE_CHILD = '> .dropdown-menu .active';
  57. /**
  58. * Class definition
  59. */
  60. var Tab = /*#__PURE__*/function () {
  61. function Tab(element) {
  62. this._element = element;
  63. } // Getters
  64. var _proto = Tab.prototype;
  65. // Public
  66. _proto.show = function show() {
  67. var _this = this;
  68. if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $__default["default"](this._element).hasClass(CLASS_NAME_ACTIVE) || $__default["default"](this._element).hasClass(CLASS_NAME_DISABLED) || this._element.hasAttribute('disabled')) {
  69. return;
  70. }
  71. var target;
  72. var previous;
  73. var listElement = $__default["default"](this._element).closest(SELECTOR_NAV_LIST_GROUP)[0];
  74. var selector = Util__default["default"].getSelectorFromElement(this._element);
  75. if (listElement) {
  76. var itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? SELECTOR_ACTIVE_UL : SELECTOR_ACTIVE;
  77. previous = $__default["default"].makeArray($__default["default"](listElement).find(itemSelector));
  78. previous = previous[previous.length - 1];
  79. }
  80. var hideEvent = $__default["default"].Event(EVENT_HIDE, {
  81. relatedTarget: this._element
  82. });
  83. var showEvent = $__default["default"].Event(EVENT_SHOW, {
  84. relatedTarget: previous
  85. });
  86. if (previous) {
  87. $__default["default"](previous).trigger(hideEvent);
  88. }
  89. $__default["default"](this._element).trigger(showEvent);
  90. if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) {
  91. return;
  92. }
  93. if (selector) {
  94. target = document.querySelector(selector);
  95. }
  96. this._activate(this._element, listElement);
  97. var complete = function complete() {
  98. var hiddenEvent = $__default["default"].Event(EVENT_HIDDEN, {
  99. relatedTarget: _this._element
  100. });
  101. var shownEvent = $__default["default"].Event(EVENT_SHOWN, {
  102. relatedTarget: previous
  103. });
  104. $__default["default"](previous).trigger(hiddenEvent);
  105. $__default["default"](_this._element).trigger(shownEvent);
  106. };
  107. if (target) {
  108. this._activate(target, target.parentNode, complete);
  109. } else {
  110. complete();
  111. }
  112. };
  113. _proto.dispose = function dispose() {
  114. $__default["default"].removeData(this._element, DATA_KEY);
  115. this._element = null;
  116. } // Private
  117. ;
  118. _proto._activate = function _activate(element, container, callback) {
  119. var _this2 = this;
  120. var activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? $__default["default"](container).find(SELECTOR_ACTIVE_UL) : $__default["default"](container).children(SELECTOR_ACTIVE);
  121. var active = activeElements[0];
  122. var isTransitioning = callback && active && $__default["default"](active).hasClass(CLASS_NAME_FADE);
  123. var complete = function complete() {
  124. return _this2._transitionComplete(element, active, callback);
  125. };
  126. if (active && isTransitioning) {
  127. var transitionDuration = Util__default["default"].getTransitionDurationFromElement(active);
  128. $__default["default"](active).removeClass(CLASS_NAME_SHOW).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  129. } else {
  130. complete();
  131. }
  132. };
  133. _proto._transitionComplete = function _transitionComplete(element, active, callback) {
  134. if (active) {
  135. $__default["default"](active).removeClass(CLASS_NAME_ACTIVE);
  136. var dropdownChild = $__default["default"](active.parentNode).find(SELECTOR_DROPDOWN_ACTIVE_CHILD)[0];
  137. if (dropdownChild) {
  138. $__default["default"](dropdownChild).removeClass(CLASS_NAME_ACTIVE);
  139. }
  140. if (active.getAttribute('role') === 'tab') {
  141. active.setAttribute('aria-selected', false);
  142. }
  143. }
  144. $__default["default"](element).addClass(CLASS_NAME_ACTIVE);
  145. if (element.getAttribute('role') === 'tab') {
  146. element.setAttribute('aria-selected', true);
  147. }
  148. Util__default["default"].reflow(element);
  149. if (element.classList.contains(CLASS_NAME_FADE)) {
  150. element.classList.add(CLASS_NAME_SHOW);
  151. }
  152. var parent = element.parentNode;
  153. if (parent && parent.nodeName === 'LI') {
  154. parent = parent.parentNode;
  155. }
  156. if (parent && $__default["default"](parent).hasClass(CLASS_NAME_DROPDOWN_MENU)) {
  157. var dropdownElement = $__default["default"](element).closest(SELECTOR_DROPDOWN)[0];
  158. if (dropdownElement) {
  159. var dropdownToggleList = [].slice.call(dropdownElement.querySelectorAll(SELECTOR_DROPDOWN_TOGGLE));
  160. $__default["default"](dropdownToggleList).addClass(CLASS_NAME_ACTIVE);
  161. }
  162. element.setAttribute('aria-expanded', true);
  163. }
  164. if (callback) {
  165. callback();
  166. }
  167. } // Static
  168. ;
  169. Tab._jQueryInterface = function _jQueryInterface(config) {
  170. return this.each(function () {
  171. var $this = $__default["default"](this);
  172. var data = $this.data(DATA_KEY);
  173. if (!data) {
  174. data = new Tab(this);
  175. $this.data(DATA_KEY, data);
  176. }
  177. if (typeof config === 'string') {
  178. if (typeof data[config] === 'undefined') {
  179. throw new TypeError("No method named \"" + config + "\"");
  180. }
  181. data[config]();
  182. }
  183. });
  184. };
  185. _createClass(Tab, null, [{
  186. key: "VERSION",
  187. get: function get() {
  188. return VERSION;
  189. }
  190. }]);
  191. return Tab;
  192. }();
  193. /**
  194. * Data API implementation
  195. */
  196. $__default["default"](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
  197. event.preventDefault();
  198. Tab._jQueryInterface.call($__default["default"](this), 'show');
  199. });
  200. /**
  201. * jQuery
  202. */
  203. $__default["default"].fn[NAME] = Tab._jQueryInterface;
  204. $__default["default"].fn[NAME].Constructor = Tab;
  205. $__default["default"].fn[NAME].noConflict = function () {
  206. $__default["default"].fn[NAME] = JQUERY_NO_CONFLICT;
  207. return Tab._jQueryInterface;
  208. };
  209. return Tab;
  210. }));
  211. //# sourceMappingURL=tab.js.map