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