diff options
Diffstat (limited to 'docs/assets/js/bootstrap.js')
| -rw-r--r-- | docs/assets/js/bootstrap.js | 84 |
1 files changed, 70 insertions, 14 deletions
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js index 6eacda25d..9231b0ca1 100644 --- a/docs/assets/js/bootstrap.js +++ b/docs/assets/js/bootstrap.js @@ -595,6 +595,7 @@ * ========================= */ var toggle = '[data-toggle="dropdown"]' + , active = 'aria-active' , Dropdown = function (element) { var $el = $(element).on('click.dropdown.data-api', this.toggle) $('html').on('click.dropdown.data-api', function () { @@ -609,34 +610,87 @@ , toggle: function (e) { var $this = $(this) , $parent - , selector , isActive if ($this.is('.disabled, :disabled')) return - selector = $this.attr('data-target') - - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 - } - - $parent = $(selector) - $parent.length || ($parent = $this.parent()) + $parent = getParent($this) isActive = $parent.hasClass('open') clearMenus() - if (!isActive) $parent.toggleClass('open') + if (!isActive) { + $parent.toggleClass('open') + $this.focus() + } return false } + , keydown: function (e) { + var $this = $(this) + , $items + , $active + , $parent + , index + + if (e.keyCode == 27) return $this.click() + + if (!/(38|40|13)/.test(e.keyCode)) return + + e.preventDefault() + e.stopPropagation() + + if ($this.is('.disabled, :disabled')) return + + $parent = getParent($this) + + $parent.hasClass('open') || $this.click() + + $items = $('[role=menu] li:not(.divider)', $parent) + + if (!$items.length) return + + index = $items.index($items.filter('#' + active)) + + $items + .eq(index) + .attr('id', '') + + if (e.keyCode == 38 && index > 0) index-- // up + else if (e.keyCode == 40 && index < $items.length - 1) index++ // down + else if (e.keyCode == 13 && ~index) return $items.eq(index).find('a').click() // enter + + if (!~index) index = 0 + + $items + .eq(index) + .attr('id', active) + } + } function clearMenus() { - $(toggle).parent().removeClass('open') + getParent($(toggle)) + .removeClass('open') + .find('#' + active) + .attr('id', '') + } + + function getParent($this) { + var selector = $this.attr('data-target') + , $parent + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } + + $parent = $(selector) + $parent.length || ($parent = $this.parent()) + + return $parent } @@ -659,10 +713,12 @@ * =================================== */ $(function () { - $('html').on('click.dropdown.data-api', clearMenus) + $('html') + .on('click.dropdown.data-api', clearMenus) $('body') .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) + .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle) + .on('keydown.dropdown.data-api', toggle, Dropdown.prototype.keydown) }) }(window.jQuery);/* ========================================================= |
