sonarr-repo-only/UI/Navbar/Search.js

37 lines
1016 B
JavaScript
Raw Normal View History

'use strict';
define(
[
'app',
'Series/SeriesCollection'
], function (App, SeriesCollection) {
2013-09-24 05:27:51 +00:00
$(document).on('keydown', function (e){
if ($(e.target).is('input')) {
return;
}
if (e.keyCode === 84) {
$('.x-series-search').focus();
e.preventDefault();
}
});
$.fn.bindSearch = function () {
$(this).typeahead({
source : function () {
2013-09-23 19:03:33 +00:00
return SeriesCollection.pluck('title');
},
sorter: function (items) {
return items.sort();
},
updater: function (item) {
2013-09-23 19:03:33 +00:00
var series = SeriesCollection.findWhere({ title: item });
this.$element.blur();
App.Router.navigate('/series/{0}'.format(series.get('titleSlug')), { trigger: true });
}
});
};
});