2013-10-09 04:43:41 +03:00
|
|
|
'use strict';
|
2014-04-01 23:10:36 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'jquery',
|
|
|
|
'typeahead'
|
2014-05-18 09:12:57 +03:00
|
|
|
], function ($) {
|
2013-02-14 05:28:56 +03:00
|
|
|
|
2013-02-16 02:38:53 +03:00
|
|
|
$.fn.autoComplete = function (resource) {
|
2013-02-14 05:28:56 +03:00
|
|
|
$(this).typeahead({
|
2014-05-04 10:11:43 +03:00
|
|
|
hint : true,
|
|
|
|
highlight : true,
|
|
|
|
minLength : 3,
|
|
|
|
items : 20
|
2013-02-14 05:28:56 +03:00
|
|
|
},
|
2014-05-04 10:11:43 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-02-14 05:28:56 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|