tab.js 8.5 KB

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