SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 933c7631 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Newsticker goes infinite

parent 2db73257
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ var NewsTicker; ...@@ -9,6 +9,8 @@ var NewsTicker;
NewsTicker = (function() { NewsTicker = (function() {
NewsTicker.prototype.items = []; NewsTicker.prototype.items = [];
NewsTicker.prototype.cached_items = [];
NewsTicker.prototype.defaults = { NewsTicker.prototype.defaults = {
url: '/api', url: '/api',
interval: 10000, interval: 10000,
...@@ -22,15 +24,26 @@ NewsTicker = (function() { ...@@ -22,15 +24,26 @@ NewsTicker = (function() {
this.start_ticker() this.start_ticker()
}; };
NewsTicker.prototype.set_item = function(item_id) {
var self = this
this.element.fadeOut(function() {
self.element.html(self.cached_items[item_id]).fadeIn()
})
};
NewsTicker.prototype.get_item = function(item) { NewsTicker.prototype.get_item = function(item) {
var self = this var self = this
$.get(this.options.url + '/' + item.id + '/?format=html') if(typeof(this.cached_items[item.id]) == 'undefined') {
.done(function(data) { $.get(this.options.url + '/' + item.id + '/?format=html')
self.element.fadeOut(function() { .done(function(data) {
self.element.html(data).fadeIn() self.cached_items[item.id] = data
self.set_item(item.id)
}) })
}) } else {
self.set_item(item.id)
}
}; };
NewsTicker.prototype.start_ticker = function() { NewsTicker.prototype.start_ticker = function() {
...@@ -39,11 +52,14 @@ NewsTicker = (function() { ...@@ -39,11 +52,14 @@ NewsTicker = (function() {
$.get(this.options.url + '?format=json') $.get(this.options.url + '?format=json')
.done(function(data) { .done(function(data) {
$.each(data, function(index, item) { var counter = 1
setTimeout( function(){ self.get_item(item); }, time) var total = data.length
time += self.options.interval;
}) setInterval(function(){
}); self.get_item(data[counter % total]);
counter += 1
}, self.options.interval);
})
}; };
return NewsTicker; return NewsTicker;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment