Merge branch 'MDL-59836-33' of git://github.com/junpataleta/moodle into MOODLE_33_STABLE

This commit is contained in:
Eloy Lafuente (stronk7)
2017-08-18 12:36:28 +02:00
2 changed files with 35 additions and 35 deletions
File diff suppressed because one or more lines are too long
+34 -34
View File
@@ -679,19 +679,40 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
});
// Whenever the input field changes, update the suggestion list.
if (options.showSuggestions) {
inputElement.on('input', function(e) {
var query = $(e.currentTarget).val();
var last = $(e.currentTarget).data('last-value');
// IE11 fires many more input events than required - even when the value has not changed.
// We need to only do this for real value changed events or the suggestions will be
// unclickable on IE11 (because they will be rebuilt before the click event fires).
// Note - because of this we cannot close the list when the query is empty or it will break
// on IE11.
if (last !== query) {
updateSuggestions(options, state, query, originalSelect);
}
$(e.currentTarget).data('last-value', query);
});
// If this field uses ajax, set it up.
if (options.ajax) {
require([options.ajax], function(ajaxHandler) {
var throttleTimeout = null;
var handler = function(e) {
updateAjax(e, options, state, originalSelect, ajaxHandler);
};
// For input events, we do not want to trigger many, many updates.
var throttledHandler = function(e) {
if (throttleTimeout !== null) {
window.clearTimeout(throttleTimeout);
throttleTimeout = null;
}
throttleTimeout = window.setTimeout(handler.bind(this, e), 300);
};
// Trigger an ajax update after the text field value changes.
inputElement.on("input", throttledHandler);
});
} else {
inputElement.on('input', function(e) {
var query = $(e.currentTarget).val();
var last = $(e.currentTarget).data('last-value');
// IE11 fires many more input events than required - even when the value has not changed.
// We need to only do this for real value changed events or the suggestions will be
// unclickable on IE11 (because they will be rebuilt before the click event fires).
// Note - because of this we cannot close the list when the query is empty or it will break
// on IE11.
if (last !== query) {
updateSuggestions(options, state, query, originalSelect);
}
$(e.currentTarget).data('last-value', query);
});
}
}
};
@@ -786,31 +807,10 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
// Add the event handlers.
addNavigation(options, state, originalSelect);
var inputElement = $(document.getElementById(state.inputId));
var suggestionsElement = $(document.getElementById(state.suggestionsId));
// Hide the suggestions by default.
suggestionsElement.hide().attr('aria-hidden', true);
// If this field uses ajax, set it up.
if (options.ajax) {
require([options.ajax], function(ajaxHandler) {
var throttleTimeout = null;
var handler = function(e) {
updateAjax(e, options, state, originalSelect, ajaxHandler);
};
// For input events, we do not want to trigger many, many updates.
var throttledHandler = function(e) {
if (throttleTimeout !== null) {
window.clearTimeout(throttleTimeout);
throttleTimeout = null;
}
throttleTimeout = window.setTimeout(handler.bind(this, e), 300);
};
// Trigger an ajax update after the text field value changes.
inputElement.on("input", throttledHandler);
});
}
// Show the current values in the selection list.
updateSelectionList(options, state, originalSelect);
});