Readarr/src/UI/Navbar/Search.js
Mark McDowall 3411c4e5a7 UI fixes
Fixed: Series search won't break when term contains brackets
Fixed: Attempting to apply the activity spinner incorrectly
2014-11-05 08:46:08 -08:00

44 lines
1.3 KiB
JavaScript

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