You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/UI/Mixins/AutoComplete.js

42 lines
1.2 KiB

'use strict';
define(
[
'jquery',
'underscore',
'typeahead'
], function ($, _) {
$.fn.autoComplete = function (resource) {
$(this).typeahead({
hint : true,
highlight : true,
minLength : 3,
items : 20
},
{
name: resource.replace('/'),
displayKey: '',
source : function (filter, callback) {
$.ajax({
url : window.NzbDrone.ApiRoot + resource,
dataType: 'json',
type : 'GET',
data : { query: filter },
success : function (data) {
var matches = [];
$.each(data, function(i, d) {
if (d.startsWith(filter)) {
matches.push({ value: d });
}
});
callback(matches);
}
});
}
});
};
});