diff --git a/misc/autocomplete.js b/misc/autocomplete.js index 267d4b7..122f05d 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -18,7 +18,7 @@ Drupal.behaviors.autocomplete = { $input.parent() .attr('role', 'application') .append($('') - .attr('id', $input.attr('id') + '-autocomplete-aria-live') + .attr('id', $input[0].id + '-autocomplete-aria-live') ); new Drupal.jsAC($input, acdb[uri]); }); @@ -30,9 +30,11 @@ Drupal.behaviors.autocomplete = { * and closes the suggestions popup when doing so. */ Drupal.autocompleteSubmit = function () { - return $('#autocomplete').each(function () { - this.owner.hidePopup(); - }).length == 0; + var $autocomplete = $('#autocomplete'); + if ($autocomplete.length !== 0) { + $autocomplete[0].owner.hidePopup(); + } + return $autocomplete.length === 0; }; /** @@ -48,7 +50,6 @@ Drupal.jsAC = function ($input, db) { .keydown(function (event) { return ac.onkeydown(this, event); }) .keyup(function (event) { ac.onkeyup(this, event); }) .blur(function () { ac.hidePopup(); ac.db.cancel(); }); - }; /** @@ -99,10 +100,12 @@ Drupal.jsAC.prototype.onkeyup = function (input, e) { return true; default: // All other keys. - if (input.value.length > 0) + if (input.value.length > 0) { this.populatePopup(); - else + } + else { this.hidePopup(e.keyCode); + } return true; } }; @@ -142,7 +145,8 @@ Drupal.jsAC.prototype.selectUp = function () { * Highlights a suggestion. */ Drupal.jsAC.prototype.highlight = function (node) { - if (this.selected) { + // Unhighlights a suggestion for "keyup" and "keydown" events. + if (this.selected !== false) { $(this.selected).removeClass('selected'); } $(node).addClass('selected'); @@ -164,7 +168,7 @@ Drupal.jsAC.prototype.unhighlight = function (node) { */ Drupal.jsAC.prototype.hidePopup = function (keycode) { // Select item if the right key or mousebutton was pressed. - if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) { + if (this.selected && ((keycode && keycode !== 46 && keycode !== 8 && keycode !== 27) || !keycode)) { this.input.value = $(this.selected).data('autocompleteValue'); } // Hide popup. @@ -215,14 +219,16 @@ Drupal.jsAC.prototype.found = function (matches) { // Prepare matches. var ul = $('