2f171de15291ae713b1130800e6db854200207df.svn-base 8.5 KB

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