mirror of
https://github.com/Radarr/Radarr
synced 2025-12-22 08:15:36 +01:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
var _ = require('underscore');
|
|
var $ = require('jquery');
|
|
var vent = require('vent');
|
|
var Backbone = require('backbone');
|
|
var SeriesCollection = require('../Movies/MoviesCollection');
|
|
require('typeahead');
|
|
|
|
vent.on(vent.Hotkeys.NavbarSearch, function() {
|
|
$('.x-series-search').focus();
|
|
});
|
|
|
|
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);
|
|
};
|
|
};
|
|
|
|
$.fn.bindSearch = function() {
|
|
$(this).typeahead({
|
|
hint : true,
|
|
highlight : true,
|
|
minLength : 1
|
|
}, {
|
|
name : 'series',
|
|
displayKey : function(series) {
|
|
return series.title + ' (' + series.year + ')';
|
|
},
|
|
source : substringMatcher()
|
|
});
|
|
|
|
$(this).on('typeahead:selected typeahead:autocompleted', function(e, series) {
|
|
this.blur();
|
|
$(this).val('');
|
|
Backbone.history.navigate('/movies/{0}'.format(series.titleSlug), { trigger : true });
|
|
});
|
|
};
|