-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
55 lines (55 loc) · 1.88 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var apiRoot = "https://fansubdb.github.io/";
var app = $.sammy('#app',function() {
this.use(Sammy.Template, 'tpl');
this.get('^(?:|#|\/#)/$',function(req){
$("#top-brand").html("FansubDB");
var requestURL = apiRoot+'/lang.json';
$.get(requestURL).done(function(response){
req.render('templates/home.tpl', {
data: response
}).swap(req.$element());
}).fail(function(){
req.render('templates/notfound.tpl').swap(req.$element());
})
});
this.get('^/#/:lang(?:|\/)$', function(req) {
$("#top-brand").html("FansubDB");
var requestURL = apiRoot+'/'+req.params.lang+'/list.json';
$.get(requestURL).done(function(response){
var data = response.data;
for(var i=0;i<data.length;i++){
for(var j=0;j<data[i].seasons.length;j++){
data[i].seasons[j].url = data[i].seasons[j].url.split('.json')[0];
}
data[i].seasons = data[i].seasons.reverse();
}
data = data.reverse();
req.render('templates/list.tpl', {
language: req.params.lang,
data: data
}).swap(req.$element());
}).fail(function(){
req.render('templates/notfound.tpl').swap(req.$element());
})
});
this.get('^/#/:lang/:year/:season(?:|\/)$', function(req) {
$("#top-brand").html(req.params.season+" "+req.params.year);
var requestURL = apiRoot+'/'+req.params.lang+'/'+req.params.year+'/'+req.params.season+'.json';
$.get(requestURL).done(function(response){
req.render('templates/season.tpl', {
context: req,
id: 0,
lang: req.params.lang,
year: req.params.year,
season: req.params.season,
data: response
}).swap(req.$element());
}).fail(function(){
req.render('templates/notfound.tpl').swap(req.$element());
})
});
this.get('.*',function(req){
req.render('templates/notfound.tpl').swap(req.$element());
});
});
app.run();