You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.7KB

  1. /* ========================================================================
  2. * Bootstrap: tab.js v3.3.2
  3. * http://getbootstrap.com/javascript/#tabs
  4. * ========================================================================
  5. * Copyright 2011-2015 Twitter, Inc.
  6. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  7. * ======================================================================== */
  8. +function ($) {
  9. 'use strict';
  10. // TAB CLASS DEFINITION
  11. // ====================
  12. var Tab = function (element) {
  13. this.element = $(element)
  14. }
  15. Tab.VERSION = '3.3.2'
  16. Tab.TRANSITION_DURATION = 150
  17. Tab.prototype.show = function () {
  18. var $this = this.element
  19. var $ul = $this.closest('ul:not(.dropdown-menu)')
  20. var selector = $this.data('target')
  21. if (!selector) {
  22. selector = $this.attr('href')
  23. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
  24. }
  25. if ($this.parent('li').hasClass('active')) return
  26. var $previous = $ul.find('.active:last a')
  27. var hideEvent = $.Event('hide.bs.tab', {
  28. relatedTarget: $this[0]
  29. })
  30. var showEvent = $.Event('show.bs.tab', {
  31. relatedTarget: $previous[0]
  32. })
  33. $previous.trigger(hideEvent)
  34. $this.trigger(showEvent)
  35. if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
  36. var $target = $(selector)
  37. this.activate($this.closest('li'), $ul)
  38. this.activate($target, $target.parent(), function () {
  39. $previous.trigger({
  40. type: 'hidden.bs.tab',
  41. relatedTarget: $this[0]
  42. })
  43. $this.trigger({
  44. type: 'shown.bs.tab',
  45. relatedTarget: $previous[0]
  46. })
  47. })
  48. }
  49. Tab.prototype.activate = function (element, container, callback) {
  50. var $active = container.find('> .active')
  51. var transition = callback
  52. && $.support.transition
  53. && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
  54. function next() {
  55. $active
  56. .removeClass('active')
  57. .find('> .dropdown-menu > .active')
  58. .removeClass('active')
  59. .end()
  60. .find('[data-toggle="tab"]')
  61. .attr('aria-expanded', false)
  62. element
  63. .addClass('active')
  64. .find('[data-toggle="tab"]')
  65. .attr('aria-expanded', true)
  66. if (transition) {
  67. element[0].offsetWidth // reflow for transition
  68. element.addClass('in')
  69. } else {
  70. element.removeClass('fade')
  71. }
  72. if (element.parent('.dropdown-menu')) {
  73. element
  74. .closest('li.dropdown')
  75. .addClass('active')
  76. .end()
  77. .find('[data-toggle="tab"]')
  78. .attr('aria-expanded', true)
  79. }
  80. callback && callback()
  81. }
  82. $active.length && transition ?
  83. $active
  84. .one('bsTransitionEnd', next)
  85. .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
  86. next()
  87. $active.removeClass('in')
  88. }
  89. // TAB PLUGIN DEFINITION
  90. // =====================
  91. function Plugin(option) {
  92. return this.each(function () {
  93. var $this = $(this)
  94. var data = $this.data('bs.tab')
  95. if (!data) $this.data('bs.tab', (data = new Tab(this)))
  96. if (typeof option == 'string') data[option]()
  97. })
  98. }
  99. var old = $.fn.tab
  100. $.fn.tab = Plugin
  101. $.fn.tab.Constructor = Tab
  102. // TAB NO CONFLICT
  103. // ===============
  104. $.fn.tab.noConflict = function () {
  105. $.fn.tab = old
  106. return this
  107. }
  108. // TAB DATA-API
  109. // ============
  110. var clickHandler = function (e) {
  111. e.preventDefault()
  112. Plugin.call($(this), 'show')
  113. }
  114. $(document)
  115. .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
  116. .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)
  117. }(jQuery);