1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/src/UI/Mixins/AutoComplete.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-10-09 04:43:41 +03:00
'use strict';
2014-04-01 23:10:36 +03:00
define(
[
'jquery',
'typeahead'
], function ($) {
2013-02-16 02:38:53 +03:00
$.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);
}
});
}
});
};
});