8e338fa5be623d5316ba8c5ce55b8ba1b06d1f9b.svn-base 7.4 KB

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