X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ae0177fbe61d7d02e3c6b441bd395fff6fd96a18..29aac6e14964d612ee6a06998ae61bc8923f5946:/vendor/assets/bootstrap/bootstrap.dropdown.js diff --git a/vendor/assets/bootstrap/bootstrap.dropdown.js b/vendor/assets/bootstrap/bootstrap.dropdown.js index d04da5d7b..200e1c67b 100644 --- a/vendor/assets/bootstrap/bootstrap.dropdown.js +++ b/vendor/assets/bootstrap/bootstrap.dropdown.js @@ -1,155 +1,145 @@ -/* ============================================================ - * bootstrap-dropdown.js v2.3.2 - * http://getbootstrap.com/2.3.2/javascript.html#dropdowns - * ============================================================ - * Copyright 2013 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============================================================ */ - - -!function ($) { - - "use strict"; // jshint ;_; - - - /* DROPDOWN CLASS DEFINITION - * ========================= */ - - var toggle = '[data-toggle=dropdown]' - , Dropdown = function (element) { - var $el = $(element).on('click.dropdown.data-api', this.toggle) - $('html').on('click.dropdown.data-api', function () { - $el.parent().removeClass('open') - }) - } +/* ======================================================================== + * Bootstrap: dropdown.js v3.3.2 + * http://getbootstrap.com/javascript/#dropdowns + * ======================================================================== + * Copyright 2011-2015 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ - Dropdown.prototype = { - constructor: Dropdown ++function ($) { + 'use strict'; - , toggle: function (e) { - var $this = $(this) - , $parent - , isActive + // DROPDOWN CLASS DEFINITION + // ========================= + + var backdrop = '.dropdown-backdrop' + var toggle = '[data-toggle="dropdown"]' + var Dropdown = function (element) { + $(element).on('click.bs.dropdown', this.toggle) + } + + Dropdown.VERSION = '3.3.2' - if ($this.is('.disabled, :disabled')) return + Dropdown.prototype.toggle = function (e) { + var $this = $(this) - $parent = getParent($this) + if ($this.is('.disabled, :disabled')) return - isActive = $parent.hasClass('open') + var $parent = getParent($this) + var isActive = $parent.hasClass('open') - clearMenus() + clearMenus() - if (!isActive) { - if ('ontouchstart' in document.documentElement) { - // if mobile we we use a backdrop because click events don't delegate - $('
').insertBefore($(this)).on('click', clearMenus) - } - $parent.toggleClass('open') + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we use a backdrop because click events don't delegate + $('').insertAfter($(this)).on('click', clearMenus) } - $this.focus() + var relatedTarget = { relatedTarget: this } + $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget)) - return false - } + if (e.isDefaultPrevented()) return - , keydown: function (e) { - var $this - , $items - , $active - , $parent - , isActive - , index + $this + .trigger('focus') + .attr('aria-expanded', 'true') - if (!/(38|40|27)/.test(e.keyCode)) return + $parent + .toggleClass('open') + .trigger('shown.bs.dropdown', relatedTarget) + } - $this = $(this) + return false + } - e.preventDefault() - e.stopPropagation() + Dropdown.prototype.keydown = function (e) { + if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return - if ($this.is('.disabled, :disabled')) return + var $this = $(this) - $parent = getParent($this) + e.preventDefault() + e.stopPropagation() - isActive = $parent.hasClass('open') + if ($this.is('.disabled, :disabled')) return - if (!isActive || (isActive && e.keyCode == 27)) { - if (e.which == 27) $parent.find(toggle).focus() - return $this.click() - } + var $parent = getParent($this) + var isActive = $parent.hasClass('open') - $items = $('[role=menu] li:not(.divider):visible a', $parent) + if ((!isActive && e.which != 27) || (isActive && e.which == 27)) { + if (e.which == 27) $parent.find(toggle).trigger('focus') + return $this.trigger('click') + } - if (!$items.length) return + var desc = ' li:not(.divider):visible a' + var $items = $parent.find('[role="menu"]' + desc + ', [role="listbox"]' + desc) - index = $items.index($items.filter(':focus')) + if (!$items.length) return - if (e.keyCode == 38 && index > 0) index-- // up - if (e.keyCode == 40 && index < $items.length - 1) index++ // down - if (!~index) index = 0 + var index = $items.index(e.target) - $items - .eq(index) - .focus() - } + if (e.which == 38 && index > 0) index-- // up + if (e.which == 40 && index < $items.length - 1) index++ // down + if (!~index) index = 0 + $items.eq(index).trigger('focus') } - function clearMenus() { - $('.dropdown-backdrop').remove() + function clearMenus(e) { + if (e && e.which === 3) return + $(backdrop).remove() $(toggle).each(function () { - getParent($(this)).removeClass('open') + var $this = $(this) + var $parent = getParent($this) + var relatedTarget = { relatedTarget: this } + + if (!$parent.hasClass('open')) return + + $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) + + if (e.isDefaultPrevented()) return + + $this.attr('aria-expanded', 'false') + $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget) }) } function getParent($this) { var selector = $this.attr('data-target') - , $parent if (!selector) { selector = $this.attr('href') - selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 } - $parent = selector && $(selector) - - if (!$parent || !$parent.length) $parent = $this.parent() + var $parent = selector && $(selector) - return $parent + return $parent && $parent.length ? $parent : $this.parent() } - /* DROPDOWN PLUGIN DEFINITION - * ========================== */ + // DROPDOWN PLUGIN DEFINITION + // ========================== - var old = $.fn.dropdown - - $.fn.dropdown = function (option) { + function Plugin(option) { return this.each(function () { var $this = $(this) - , data = $this.data('dropdown') - if (!data) $this.data('dropdown', (data = new Dropdown(this))) + var data = $this.data('bs.dropdown') + + if (!data) $this.data('bs.dropdown', (data = new Dropdown(this))) if (typeof option == 'string') data[option].call($this) }) } + var old = $.fn.dropdown + + $.fn.dropdown = Plugin $.fn.dropdown.Constructor = Dropdown - /* DROPDOWN NO CONFLICT - * ==================== */ + // DROPDOWN NO CONFLICT + // ==================== $.fn.dropdown.noConflict = function () { $.fn.dropdown = old @@ -157,13 +147,15 @@ } - /* APPLY TO STANDARD DROPDOWN ELEMENTS - * =================================== */ + // APPLY TO STANDARD DROPDOWN ELEMENTS + // =================================== $(document) - .on('click.dropdown.data-api', clearMenus) - .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle) - .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) - -}(window.jQuery); + .on('click.bs.dropdown.data-api', clearMenus) + .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) + .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle) + .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown) + .on('keydown.bs.dropdown.data-api', '[role="menu"]', Dropdown.prototype.keydown) + .on('keydown.bs.dropdown.data-api', '[role="listbox"]', Dropdown.prototype.keydown) + +}(jQuery);