info@54: /* ======================================================================== info@54: * Bootstrap: dropdown.js v3.0.3 info@54: * http://getbootstrap.com/javascript/#dropdowns info@54: * ======================================================================== info@54: * Copyright 2013 Twitter, Inc. info@54: * info@54: * Licensed under the Apache License, Version 2.0 (the "License"); info@54: * you may not use this file except in compliance with the License. info@54: * You may obtain a copy of the License at info@54: * info@54: * http://www.apache.org/licenses/LICENSE-2.0 info@54: * info@54: * Unless required by applicable law or agreed to in writing, software info@54: * distributed under the License is distributed on an "AS IS" BASIS, info@54: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. info@54: * See the License for the specific language governing permissions and info@54: * limitations under the License. info@54: * ======================================================================== */ info@54: info@54: info@54: +function ($) { "use strict"; info@54: info@54: // DROPDOWN CLASS DEFINITION info@54: // ========================= info@54: info@54: var backdrop = '.dropdown-backdrop' info@54: var toggle = '[data-toggle=dropdown]' info@54: var Dropdown = function (element) { info@54: $(element).on('click.bs.dropdown', this.toggle) info@54: } info@54: info@54: Dropdown.prototype.toggle = function (e) { info@54: var $this = $(this) info@54: info@54: if ($this.is('.disabled, :disabled')) return info@54: info@54: var $parent = getParent($this) info@54: var isActive = $parent.hasClass('open') info@54: info@54: clearMenus() info@54: info@54: if (!isActive) { info@54: if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { info@54: // if mobile we use a backdrop because click events don't delegate info@54: $('
').insertAfter($(this)).on('click', clearMenus) info@54: } info@54: info@54: $parent.trigger(e = $.Event('show.bs.dropdown')) info@54: info@54: if (e.isDefaultPrevented()) return info@54: info@54: $parent info@54: .toggleClass('open') info@54: .trigger('shown.bs.dropdown') info@54: info@54: $this.focus() info@54: } info@54: info@54: return false info@54: } info@54: info@54: Dropdown.prototype.keydown = function (e) { info@54: if (!/(38|40|27)/.test(e.keyCode)) return info@54: info@54: var $this = $(this) info@54: info@54: e.preventDefault() info@54: e.stopPropagation() info@54: info@54: if ($this.is('.disabled, :disabled')) return info@54: info@54: var $parent = getParent($this) info@54: var isActive = $parent.hasClass('open') info@54: info@54: if (!isActive || (isActive && e.keyCode == 27)) { info@54: if (e.which == 27) $parent.find(toggle).focus() info@54: return $this.click() info@54: } info@54: info@54: var $items = $('[role=menu] li:not(.divider):visible a', $parent) info@54: info@54: if (!$items.length) return info@54: info@54: var index = $items.index($items.filter(':focus')) info@54: info@54: if (e.keyCode == 38 && index > 0) index-- // up info@54: if (e.keyCode == 40 && index < $items.length - 1) index++ // down info@54: if (!~index) index=0 info@54: info@54: $items.eq(index).focus() info@54: } info@54: info@54: function clearMenus() { info@54: $(backdrop).remove() info@54: $(toggle).each(function (e) { info@54: var $parent = getParent($(this)) info@54: if (!$parent.hasClass('open')) return info@54: $parent.trigger(e = $.Event('hide.bs.dropdown')) info@54: if (e.isDefaultPrevented()) return info@54: $parent.removeClass('open').trigger('hidden.bs.dropdown') info@54: }) info@54: } info@54: info@54: function getParent($this) { info@54: var selector = $this.attr('data-target') info@54: info@54: if (!selector) { info@54: selector = $this.attr('href') info@54: selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 info@54: } info@54: info@54: var $parent = selector && $(selector) info@54: info@54: return $parent && $parent.length ? $parent : $this.parent() info@54: } info@54: info@54: info@54: // DROPDOWN PLUGIN DEFINITION info@54: // ========================== info@54: info@54: var old = $.fn.dropdown info@54: info@54: $.fn.dropdown = function (option) { info@54: return this.each(function () { info@54: var $this = $(this) info@54: var data = $this.data('bs.dropdown') info@54: info@54: if (!data) $this.data('bs.dropdown', (data = new Dropdown(this))) info@54: if (typeof option == 'string') data[option].call($this) info@54: }) info@54: } info@54: info@54: $.fn.dropdown.Constructor = Dropdown info@54: info@54: info@54: // DROPDOWN NO CONFLICT info@54: // ==================== info@54: info@54: $.fn.dropdown.noConflict = function () { info@54: $.fn.dropdown = old info@54: return this info@54: } info@54: info@54: info@54: // APPLY TO STANDARD DROPDOWN ELEMENTS info@54: // =================================== info@54: info@54: $(document) info@54: .on('click.bs.dropdown.data-api', clearMenus) info@54: .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) info@54: .on('click.bs.dropdown.data-api' , toggle, Dropdown.prototype.toggle) info@54: .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) info@54: info@54: }(jQuery);