File indexing completed on 2024-05-12 17:26:18

0001 /* ========================================================================
0002  * Bootstrap: dropdown.js v3.3.4
0003  * http://getbootstrap.com/javascript/#dropdowns
0004  * ========================================================================
0005  * Copyright 2011-2015 Twitter, Inc.
0006  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
0007  * ======================================================================== */
0008 
0009 
0010 +function ($) {
0011   'use strict';
0012 
0013   // DROPDOWN CLASS DEFINITION
0014   // =========================
0015 
0016   var backdrop = '.dropdown-backdrop'
0017   var toggle   = '[data-toggle="dropdown"]'
0018   var Dropdown = function (element) {
0019     $(element).on('click.bs.dropdown', this.toggle)
0020   }
0021 
0022   Dropdown.VERSION = '3.3.4'
0023 
0024   function getParent($this) {
0025     var selector = $this.attr('data-target')
0026 
0027     if (!selector) {
0028       selector = $this.attr('href')
0029       selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
0030     }
0031 
0032     var $parent = selector && $(selector)
0033 
0034     return $parent && $parent.length ? $parent : $this.parent()
0035   }
0036 
0037   function clearMenus(e) {
0038     if (e && e.which === 3) return
0039     $(backdrop).remove()
0040     $(toggle).each(function () {
0041       var $this         = $(this)
0042       var $parent       = getParent($this)
0043       var relatedTarget = { relatedTarget: this }
0044 
0045       if (!$parent.hasClass('open')) return
0046 
0047       if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return
0048 
0049       $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
0050 
0051       if (e.isDefaultPrevented()) return
0052 
0053       $this.attr('aria-expanded', 'false')
0054       $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
0055     })
0056   }
0057 
0058   Dropdown.prototype.toggle = function (e) {
0059     var $this = $(this)
0060 
0061     if ($this.is('.disabled, :disabled')) return
0062 
0063     var $parent  = getParent($this)
0064     var isActive = $parent.hasClass('open')
0065 
0066     clearMenus()
0067 
0068     if (!isActive) {
0069       if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
0070         // if mobile we use a backdrop because click events don't delegate
0071         $(document.createElement('div'))
0072           .addClass('dropdown-backdrop')
0073           .insertAfter($(this))
0074           .on('click', clearMenus)
0075       }
0076 
0077       var relatedTarget = { relatedTarget: this }
0078       $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))
0079 
0080       if (e.isDefaultPrevented()) return
0081 
0082       $this
0083         .trigger('focus')
0084         .attr('aria-expanded', 'true')
0085 
0086       $parent
0087         .toggleClass('open')
0088         .trigger('shown.bs.dropdown', relatedTarget)
0089     }
0090 
0091     return false
0092   }
0093 
0094   Dropdown.prototype.keydown = function (e) {
0095     if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return
0096 
0097     var $this = $(this)
0098 
0099     e.preventDefault()
0100     e.stopPropagation()
0101 
0102     if ($this.is('.disabled, :disabled')) return
0103 
0104     var $parent  = getParent($this)
0105     var isActive = $parent.hasClass('open')
0106 
0107     if (!isActive && e.which != 27 || isActive && e.which == 27) {
0108       if (e.which == 27) $parent.find(toggle).trigger('focus')
0109       return $this.trigger('click')
0110     }
0111 
0112     var desc = ' li:not(.disabled):visible a'
0113     var $items = $parent.find('[role="menu"]' + desc + ', [role="listbox"]' + desc)
0114 
0115     if (!$items.length) return
0116 
0117     var index = $items.index(e.target)
0118 
0119     if (e.which == 38 && index > 0)                 index--         // up
0120     if (e.which == 40 && index < $items.length - 1) index++         // down
0121     if (!~index)                                    index = 0
0122 
0123     $items.eq(index).trigger('focus')
0124   }
0125 
0126 
0127   // DROPDOWN PLUGIN DEFINITION
0128   // ==========================
0129 
0130   function Plugin(option) {
0131     return this.each(function () {
0132       var $this = $(this)
0133       var data  = $this.data('bs.dropdown')
0134 
0135       if (!data) $this.data('bs.dropdown', (data = new Dropdown(this)))
0136       if (typeof option == 'string') data[option].call($this)
0137     })
0138   }
0139 
0140   var old = $.fn.dropdown
0141 
0142   $.fn.dropdown             = Plugin
0143   $.fn.dropdown.Constructor = Dropdown
0144 
0145 
0146   // DROPDOWN NO CONFLICT
0147   // ====================
0148 
0149   $.fn.dropdown.noConflict = function () {
0150     $.fn.dropdown = old
0151     return this
0152   }
0153 
0154 
0155   // APPLY TO STANDARD DROPDOWN ELEMENTS
0156   // ===================================
0157 
0158   $(document)
0159     .on('click.bs.dropdown.data-api', clearMenus)
0160     .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
0161     .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
0162     .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown)
0163     .on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown)
0164 
0165 }(jQuery);