Serach enhancement refinement
This commit is contained in:
17
script.js
17
script.js
@@ -104,6 +104,7 @@ jQuery(function(){
|
||||
var curRequest = null;
|
||||
var items = [];
|
||||
var activeIndex = -1;
|
||||
var lastNavigation = null;
|
||||
var listId = 'qsearch__listbox';
|
||||
|
||||
$form
|
||||
@@ -127,6 +128,7 @@ jQuery(function(){
|
||||
|
||||
function clearActive() {
|
||||
activeIndex = -1;
|
||||
lastNavigation = null;
|
||||
$input.removeAttr('aria-activedescendant');
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ jQuery(function(){
|
||||
|
||||
function updateActive() {
|
||||
var $options = $output.find('li[data-index]');
|
||||
$options.removeClass('is-active').attr('aria-selected', 'false');
|
||||
$options.removeClass('is-active is-tabbed').attr('aria-selected', 'false');
|
||||
|
||||
if (activeIndex < 0 || activeIndex >= items.length) {
|
||||
clearActive();
|
||||
@@ -209,13 +211,17 @@ jQuery(function(){
|
||||
|
||||
var $active = $options.filter('[data-index="' + activeIndex + '"]');
|
||||
$active.addClass('is-active').attr('aria-selected', 'true');
|
||||
if (lastNavigation === 'tab') {
|
||||
$active.addClass('is-tabbed');
|
||||
}
|
||||
$input.attr('aria-activedescendant', $active.attr('id'));
|
||||
}
|
||||
|
||||
function moveActive(delta) {
|
||||
function moveActive(delta, source) {
|
||||
if (!items.length) {
|
||||
return;
|
||||
}
|
||||
lastNavigation = source || null;
|
||||
if (activeIndex < 0) {
|
||||
activeIndex = delta > 0 ? 0 : items.length - 1;
|
||||
} else {
|
||||
@@ -349,19 +355,19 @@ jQuery(function(){
|
||||
|
||||
if (key === 'ArrowDown') {
|
||||
event.preventDefault();
|
||||
moveActive(1);
|
||||
moveActive(1, 'arrow');
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
moveActive(-1);
|
||||
moveActive(-1, 'arrow');
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'Tab') {
|
||||
event.preventDefault();
|
||||
moveActive(event.shiftKey ? -1 : 1);
|
||||
moveActive(event.shiftKey ? -1 : 1, 'tab');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -374,6 +380,7 @@ jQuery(function(){
|
||||
|
||||
$output.on('mouseenter', 'li[data-index]', function () {
|
||||
activeIndex = parseInt(jQuery(this).attr('data-index'), 10);
|
||||
lastNavigation = 'mouse';
|
||||
updateActive();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user