mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-16 21:16:24 -04:00
rjs -> webpack
This commit is contained in:
@@ -1,65 +1,43 @@
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'marionette',
|
||||
'jquery',
|
||||
'Health/HealthView',
|
||||
'Activity/Queue/QueueView',
|
||||
'Navbar/Search'
|
||||
], function (Marionette, $, HealthView, QueueView) {
|
||||
return Marionette.Layout.extend({
|
||||
template: 'Navbar/NavbarLayoutTemplate',
|
||||
var Marionette = require('marionette');
|
||||
var $ = require('jquery');
|
||||
var HealthView = require('../Health/HealthView');
|
||||
var QueueView = require('../Activity/Queue/QueueView');
|
||||
require('./Search');
|
||||
|
||||
regions: {
|
||||
health : '#x-health',
|
||||
queue : '#x-queue-count'
|
||||
},
|
||||
|
||||
ui: {
|
||||
search: '.x-series-search',
|
||||
collapse: '.x-navbar-collapse'
|
||||
},
|
||||
|
||||
events: {
|
||||
'click a': 'onClick'
|
||||
},
|
||||
|
||||
onRender: function () {
|
||||
this.ui.search.bindSearch();
|
||||
this.health.show(new HealthView());
|
||||
this.queue.show(new QueueView());
|
||||
},
|
||||
|
||||
onClick: function (event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var target = $(event.target);
|
||||
|
||||
//look down for <a/>
|
||||
var href = event.target.getAttribute('href');
|
||||
|
||||
//if couldn't find it look up'
|
||||
if (!href && target.closest('a') && target.closest('a')[0]) {
|
||||
|
||||
var linkElement = target.closest('a')[0];
|
||||
|
||||
href = linkElement.getAttribute('href');
|
||||
this.setActive(linkElement);
|
||||
}
|
||||
else {
|
||||
this.setActive(event.target);
|
||||
}
|
||||
|
||||
if ($(window).width() < 768) {
|
||||
this.ui.collapse.collapse('hide');
|
||||
}
|
||||
},
|
||||
|
||||
setActive: function (element) {
|
||||
//Todo: Set active on first load
|
||||
this.$('a').removeClass('active');
|
||||
$(element).addClass('active');
|
||||
}
|
||||
});
|
||||
});
|
||||
module.exports = Marionette.Layout.extend({
|
||||
template : 'Navbar/NavbarLayoutTemplate',
|
||||
regions : {
|
||||
health : '#x-health',
|
||||
queue : '#x-queue-count'
|
||||
},
|
||||
ui : {
|
||||
search : '.x-series-search',
|
||||
collapse : '.x-navbar-collapse'
|
||||
},
|
||||
events : {"click a" : 'onClick'},
|
||||
onRender : function(){
|
||||
this.ui.search.bindSearch();
|
||||
this.health.show(new HealthView());
|
||||
this.queue.show(new QueueView());
|
||||
},
|
||||
onClick : function(event){
|
||||
event.preventDefault();
|
||||
var target = $(event.target);
|
||||
var href = event.target.getAttribute('href');
|
||||
if(!href && target.closest('a') && target.closest('a')[0]) {
|
||||
var linkElement = target.closest('a')[0];
|
||||
href = linkElement.getAttribute('href');
|
||||
this.setActive(linkElement);
|
||||
}
|
||||
else {
|
||||
this.setActive(event.target);
|
||||
}
|
||||
if($(window).width() < 768) {
|
||||
this.ui.collapse.collapse('hide');
|
||||
}
|
||||
},
|
||||
setActive : function(element){
|
||||
this.$('a').removeClass('active');
|
||||
$(element).addClass('active');
|
||||
}
|
||||
});
|
||||
@@ -1,44 +1,36 @@
|
||||
'use strict';
|
||||
define(
|
||||
[
|
||||
'underscore',
|
||||
'jquery',
|
||||
'vent',
|
||||
'backbone',
|
||||
'Series/SeriesCollection',
|
||||
'typeahead'
|
||||
], function (_, $, vent, Backbone, SeriesCollection) {
|
||||
var _ = require('underscore');
|
||||
var $ = require('jquery');
|
||||
var vent = require('../vent');
|
||||
var Backbone = require('backbone');
|
||||
var SeriesCollection = require('../Series/SeriesCollection');
|
||||
require('typeahead');
|
||||
|
||||
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);
|
||||
};
|
||||
};
|
||||
module.exports = (function(){
|
||||
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);
|
||||
};
|
||||
};
|
||||
}).call(this);
|
||||
Reference in New Issue
Block a user