mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
MDL-52042 autocomplete: close suggestion box
Close the suggestion box when the input loses focus for more than half a second.
This commit is contained in:
parent
1533fca4b5
commit
e1db2b4112
2
lib/amd/build/form-autocomplete.min.js
vendored
2
lib/amd/build/form-autocomplete.min.js
vendored
File diff suppressed because one or more lines are too long
@ -37,9 +37,6 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
UP: 38
|
||||
};
|
||||
|
||||
/** @var {Number} closeSuggestionsTimer - integer used to cancel window.setTimeout. */
|
||||
var closeSuggestionsTimer = null;
|
||||
|
||||
/**
|
||||
* Make an item in the selection list "active".
|
||||
*
|
||||
@ -568,15 +565,12 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
createItem(options, state, originalSelect);
|
||||
}
|
||||
});
|
||||
inputElement.on('blur focus', function(e) {
|
||||
// We may be blurring because we have clicked on the suggestion list. We
|
||||
// dont want to close the selection list before the click event fires, so
|
||||
// we have to delay.
|
||||
if (closeSuggestionsTimer) {
|
||||
window.clearTimeout(closeSuggestionsTimer);
|
||||
}
|
||||
closeSuggestionsTimer = window.setTimeout(function() {
|
||||
if (e.type == 'blur') {
|
||||
inputElement.on('blur', function() {
|
||||
window.setTimeout(function() {
|
||||
// Get the current element with focus.
|
||||
var focusElement = $(document.activeElement);
|
||||
// Only close the menu if the input hasn't regained focus.
|
||||
if (focusElement.attr('id') != inputElement.attr('id')) {
|
||||
if (options.tags) {
|
||||
createItem(options, state, originalSelect);
|
||||
}
|
||||
@ -589,9 +583,6 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
|
||||
arrowElement.on('click', function() {
|
||||
// Prevent the close timer, or we will open, then close the suggestions.
|
||||
inputElement.focus();
|
||||
if (closeSuggestionsTimer) {
|
||||
window.clearTimeout(closeSuggestionsTimer);
|
||||
}
|
||||
// Show the suggestions list.
|
||||
updateSuggestions(options, state, inputElement.val(), originalSelect);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user