1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-18 23:48:35 +02:00
Sonarr/src/UI/Mixins/AutoComplete.js
2014-05-17 23:12:57 -07:00

41 lines
1.2 KiB
JavaScript

'use strict';
define(
[
'jquery',
'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);
}
});
}
});
};
});