JAVASCRIPT   7

bootstrap.js

Guest on 19th August 2021 04:22:25 PM

  1. /* ============================================================
  2.  * bootstrap-dropdown.js v2.3.2
  3.  * http://twitter.github.com/bootstrap/javascript.html#dropdowns
  4.  * ============================================================
  5.  * Copyright Twitter, Inc.
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  * http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * ============================================================ */
  19.  
  20.  
  21. !function ($) {
  22.  
  23.   "use strict"; // jshint ;_;
  24.  
  25.  
  26.  
  27.   // TAB CLASS DEFINITION
  28.   // ====================
  29.  
  30.   var Tab = function (element) {
  31.     this.element = $(element)
  32.   }
  33.  
  34.   Tab.prototype.show = function () {
  35.     var $this    = this.element
  36.     var $ul      = $this.closest('ul:not(.dropdown-menu)')
  37.     var selector = $this.data('target')
  38.  
  39.     if (!selector) {
  40.       selector = $this.attr('href')
  41.       selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  42.     }
  43.  
  44.     if ($this.parent('li').hasClass('active')) return
  45.  
  46.     var previous = $ul.find('.active:last a')[0]
  47.     var e        = $.Event('show.bs.tab', {
  48.       relatedTarget: previous
  49.     })
  50.  
  51.     $this.trigger(e)
  52.  
  53.     if (e.isDefaultPrevented()) return
  54.  
  55.     var $target = $(selector)
  56.  
  57.     this.activate($this.parent('li'), $ul)
  58.     this.activate($target, $target.parent(), function () {
  59.       $this.trigger({
  60.         type: 'shown.bs.tab'
  61.       , relatedTarget: previous
  62.       })
  63.     })
  64.   }
  65.  
  66.   Tab.prototype.activate = function (element, container, callback) {
  67.     var $active    = container.find('> .active')
  68.     var transition = callback
  69.       && $.support.transition
  70.       && $active.hasClass('fade')
  71.  
  72.     function next() {
  73.       $active
  74.         .removeClass('active')
  75.         .find('> .dropdown-menu > .active')
  76.         .removeClass('active')
  77.  
  78.       element.addClass('active')
  79.  
  80.       if (transition) {
  81.         element[0].offsetWidth // reflow for transition
  82.         element.addClass('in')
  83.       } else {
  84.         element.removeClass('fade')
  85.       }
  86.  
  87.       if (element.parent('.dropdown-menu')) {
  88.         element.closest('li.dropdown').addClass('active')
  89.       }
  90.  
  91.       callback && callback()
  92.     }
  93.  
  94.     transition ?
  95.       $active
  96.         .one($.support.transition.end, next)
  97.         .emulateTransitionEnd(150) :
  98.       next()
  99.  
  100.     $active.removeClass('in')
  101.   }
  102.  
  103.  
  104.   // TAB PLUGIN DEFINITION
  105.   // =====================
  106.  
  107.   var old = $.fn.tab
  108.  
  109.   $.fn.tab = function ( option ) {
  110.     return this.each(function () {
  111.       var $this = $(this)
  112.       var data  = $this.data('bs.tab')
  113.  
  114.       if (!data) $this.data('bs.tab', (data = new Tab(this)))
  115.       if (typeof option == 'string') data[option]()
  116.     })
  117.   }
  118.  
  119.   $.fn.tab.Constructor = Tab
  120.  
  121.  
  122.   // TAB NO CONFLICT
  123.   // ===============
  124.  
  125.   $.fn.tab.noConflict = function () {
  126.     $.fn.tab = old
  127.     return this
  128.   }
  129.  
  130.  
  131.   // TAB DATA-API
  132.   // ============
  133.  
  134.   $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
  135.     e.preventDefault()
  136.     $(this).tab('show')
  137.   })   
  138.        
  139.        
  140. }(window.jQuery);

Raw Paste


Login or Register to edit or fork this paste. It's free.