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/Navbar/Search.js

45 lines
1.3 KiB

'use strict';
define(
[
'underscore',
11 years ago
'jquery',
'vent',
'backbone',
'Series/SeriesCollection',
'typeahead'
], function (_, $, vent, Backbone, SeriesCollection) {
vent.on(vent.Hotkeys.NavbarSearch, function () {
$('.x-series-search').focus();
});
$.fn.bindSearch = function () {
$(this).typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'series',
displayKey: 'title',
source: substringMatcher()
});
$(this).on('typeahead:selected typeahead:autocompleted', function (e, series) {
this.blur();
$(this).val('');
Backbone.history.navigate('/series/{0}'.format(series.titleSlug), { trigger: true });
});
};
var substringMatcher = function() {
return function findMatches(q, cb) {
var matches = _.select(SeriesCollection.toJSON(), function (series) {
return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1;
});
cb(matches);
};
};
});