in www/assets/bootstrap-select.js [1558:1769]
keydown: function (e) {
var $this = $(this),
$parent = $this.is('input') ? $this.parent().parent() : $this.parent(),
$items,
that = $parent.data('this'),
index,
next,
first,
last,
prev,
nextPrev,
prevIndex,
isActive,
selector = ':not(.disabled, .hidden, .dropdown-header, .divider)',
keyCodeMap = {
32: ' ',
48: '0',
49: '1',
50: '2',
51: '3',
52: '4',
53: '5',
54: '6',
55: '7',
56: '8',
57: '9',
59: ';',
65: 'a',
66: 'b',
67: 'c',
68: 'd',
69: 'e',
70: 'f',
71: 'g',
72: 'h',
73: 'i',
74: 'j',
75: 'k',
76: 'l',
77: 'm',
78: 'n',
79: 'o',
80: 'p',
81: 'q',
82: 'r',
83: 's',
84: 't',
85: 'u',
86: 'v',
87: 'w',
88: 'x',
89: 'y',
90: 'z',
96: '0',
97: '1',
98: '2',
99: '3',
100: '4',
101: '5',
102: '6',
103: '7',
104: '8',
105: '9'
};
if (that.options.liveSearch) $parent = $this.parent().parent();
if (that.options.container) $parent = that.$menu;
$items = $('[role="listbox"] li', $parent);
isActive = that.$newElement.hasClass('open');
if (!isActive && (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90)) {
if (!that.options.container) {
that.setSize();
that.$menu.parent().addClass('open');
isActive = true;
} else {
that.$button.trigger('click');
}
that.$searchbox.focus();
return;
}
if (that.options.liveSearch) {
if (/(^9$|27)/.test(e.keyCode.toString(10)) && isActive) {
e.preventDefault();
e.stopPropagation();
that.$menuInner.click();
that.$button.focus();
}
// $items contains li elements when liveSearch is enabled
$items = $('[role="listbox"] li' + selector, $parent);
if (!$this.val() && !/(38|40)/.test(e.keyCode.toString(10))) {
if ($items.filter('.active').length === 0) {
$items = that.$menuInner.find('li');
if (that.options.liveSearchNormalize) {
$items = $items.filter(':a' + that._searchStyle() + '(' + normalizeToBase(keyCodeMap[e.keyCode]) + ')');
} else {
$items = $items.filter(':' + that._searchStyle() + '(' + keyCodeMap[e.keyCode] + ')');
}
}
}
}
if (!$items.length) return;
if (/(38|40)/.test(e.keyCode.toString(10))) {
index = $items.index($items.find('a').filter(':focus').parent());
first = $items.filter(selector).first().index();
last = $items.filter(selector).last().index();
next = $items.eq(index).nextAll(selector).eq(0).index();
prev = $items.eq(index).prevAll(selector).eq(0).index();
nextPrev = $items.eq(next).prevAll(selector).eq(0).index();
if (that.options.liveSearch) {
$items.each(function (i) {
if (!$(this).hasClass('disabled')) {
$(this).data('index', i);
}
});
index = $items.index($items.filter('.active'));
first = $items.first().data('index');
last = $items.last().data('index');
next = $items.eq(index).nextAll().eq(0).data('index');
prev = $items.eq(index).prevAll().eq(0).data('index');
nextPrev = $items.eq(next).prevAll().eq(0).data('index');
}
prevIndex = $this.data('prevIndex');
if (e.keyCode == 38) {
if (that.options.liveSearch) index--;
if (index != nextPrev && index > prev) index = prev;
if (index < first) index = first;
if (index == prevIndex) index = last;
} else if (e.keyCode == 40) {
if (that.options.liveSearch) index++;
if (index == -1) index = 0;
if (index != nextPrev && index < next) index = next;
if (index > last) index = last;
if (index == prevIndex) index = first;
}
$this.data('prevIndex', index);
if (!that.options.liveSearch) {
$items.eq(index).children('a').focus();
} else {
e.preventDefault();
if (!$this.hasClass('dropdown-toggle')) {
$items.removeClass('active').eq(index).addClass('active').children('a').focus();
$this.focus();
}
}
} else if (!$this.is('input')) {
var keyIndex = [],
count,
prevKey;
$items.each(function () {
if (!$(this).hasClass('disabled')) {
if ($.trim($(this).children('a').text().toLowerCase()).substring(0, 1) == keyCodeMap[e.keyCode]) {
keyIndex.push($(this).index());
}
}
});
count = $(document).data('keycount');
count++;
$(document).data('keycount', count);
prevKey = $.trim($(':focus').text().toLowerCase()).substring(0, 1);
if (prevKey != keyCodeMap[e.keyCode]) {
count = 1;
$(document).data('keycount', count);
} else if (count >= keyIndex.length) {
$(document).data('keycount', 0);
if (count > keyIndex.length) count = 1;
}
$items.eq(keyIndex[count - 1]).children('a').focus();
}
// Select focused option if "Enter", "Spacebar" or "Tab" (when selectOnTab is true) are pressed inside the menu.
if ((/(13|32)/.test(e.keyCode.toString(10)) || (/(^9$)/.test(e.keyCode.toString(10)) && that.options.selectOnTab)) && isActive) {
if (!/(32)/.test(e.keyCode.toString(10))) e.preventDefault();
if (!that.options.liveSearch) {
var elem = $(':focus');
elem.click();
// Bring back focus for multiselects
elem.focus();
// Prevent screen from scrolling if the user hit the spacebar
e.preventDefault();
// Fixes spacebar selection of dropdown items in FF & IE
$(document).data('spaceSelect', true);
} else if (!/(32)/.test(e.keyCode.toString(10))) {
that.$menuInner.find('.active a').click();
$this.focus();
}
$(document).data('keycount', 0);
}
if ((/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && (that.multiple || that.options.liveSearch)) || (/(27)/.test(e.keyCode.toString(10)) && !isActive)) {
that.$menu.parent().removeClass('open');
if (that.options.container) that.$newElement.removeClass('open');
that.$button.focus();
}
},