tab.js 8.0 KB

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