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
Mark McDowall 99f2b07a11 Bootstrap 3
New: Updated UI
New: Mobile browser support
Fixed: /favicon.ico will return the favicon now
2014-05-11 15:57:33 -07:00

42 lines
1.2 KiB
JavaScript

'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);
}
});
}
});
};
});