File indexing completed on 2024-12-22 05:33:16
0001 /* ======================================================== 0002 * bootstrap-tab.js v2.0.4 0003 * http://twitter.github.com/bootstrap/javascript.html#tabs 0004 * ======================================================== 0005 * Copyright 2012 Twitter, Inc. 0006 * 0007 * Licensed under the Apache License, Version 2.0 (the "License"); 0008 * you may not use this file except in compliance with the License. 0009 * You may obtain a copy of the License at 0010 * 0011 * http://www.apache.org/licenses/LICENSE-2.0 0012 * 0013 * Unless required by applicable law or agreed to in writing, software 0014 * distributed under the License is distributed on an "AS IS" BASIS, 0015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 * See the License for the specific language governing permissions and 0017 * limitations under the License. 0018 * ======================================================== */ 0019 0020 0021 !function ($) { 0022 0023 "use strict"; // jshint ;_; 0024 0025 0026 /* TAB CLASS DEFINITION 0027 * ==================== */ 0028 0029 var Tab = function ( element ) { 0030 this.element = $(element) 0031 } 0032 0033 Tab.prototype = { 0034 0035 constructor: Tab 0036 0037 , show: function () { 0038 var $this = this.element 0039 , $ul = $this.closest('ul:not(.dropdown-menu)') 0040 , selector = $this.attr('data-target') 0041 , previous 0042 , $target 0043 , e 0044 0045 if (!selector) { 0046 selector = $this.attr('href') 0047 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 0048 } 0049 0050 if ( $this.parent('li').hasClass('active') ) return 0051 0052 previous = $ul.find('.active a').last()[0] 0053 0054 e = $.Event('show', { 0055 relatedTarget: previous 0056 }) 0057 0058 $this.trigger(e) 0059 0060 if (e.isDefaultPrevented()) return 0061 0062 $target = $(selector) 0063 0064 this.activate($this.parent('li'), $ul) 0065 this.activate($target, $target.parent(), function () { 0066 $this.trigger({ 0067 type: 'shown' 0068 , relatedTarget: previous 0069 }) 0070 }) 0071 } 0072 0073 , activate: function ( element, container, callback) { 0074 var $active = container.find('> .active') 0075 , transition = callback 0076 && $.support.transition 0077 && $active.hasClass('fade') 0078 0079 function next() { 0080 $active 0081 .removeClass('active') 0082 .find('> .dropdown-menu > .active') 0083 .removeClass('active') 0084 0085 element.addClass('active') 0086 0087 if (transition) { 0088 element[0].offsetWidth // reflow for transition 0089 element.addClass('in') 0090 } else { 0091 element.removeClass('fade') 0092 } 0093 0094 if ( element.parent('.dropdown-menu') ) { 0095 element.closest('li.dropdown').addClass('active') 0096 } 0097 0098 callback && callback() 0099 } 0100 0101 transition ? 0102 $active.one($.support.transition.end, next) : 0103 next() 0104 0105 $active.removeClass('in') 0106 } 0107 } 0108 0109 0110 /* TAB PLUGIN DEFINITION 0111 * ===================== */ 0112 0113 $.fn.tab = function ( option ) { 0114 return this.each(function () { 0115 var $this = $(this) 0116 , data = $this.data('tab') 0117 if (!data) $this.data('tab', (data = new Tab(this))) 0118 if (typeof option == 'string') data[option]() 0119 }) 0120 } 0121 0122 $.fn.tab.Constructor = Tab 0123 0124 0125 /* TAB DATA-API 0126 * ============ */ 0127 0128 $(function () { 0129 $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { 0130 e.preventDefault() 0131 $(this).tab('show') 0132 }) 0133 }) 0134 0135 }(window.jQuery);