2014-09-10 16:49:19 +02:00
|
|
|
var rss = [
|
2014-09-12 16:32:49 +02:00
|
|
|
'hamburg.freifunk.net',
|
2014-09-10 16:49:19 +02:00
|
|
|
];
|
2014-09-12 15:45:34 +02:00
|
|
|
var MAX_RSS = 5;
|
2014-09-10 16:49:19 +02:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-09-12 16:32:49 +02:00
|
|
|
var addItem = function(title, link, date) {
|
2014-09-12 16:00:41 +02:00
|
|
|
var item = $('<a>')
|
|
|
|
.attr('class', 'css-truncate')
|
|
|
|
.attr('href', link)
|
|
|
|
.attr('target', '_blank')
|
2014-09-12 16:32:49 +02:00
|
|
|
.data('date', date)
|
2014-09-12 16:00:41 +02:00
|
|
|
.text(title);
|
|
|
|
$('#news').append($('<li>').append(item));
|
2014-09-12 16:32:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var getAddedItems = function() {
|
|
|
|
var news = [];
|
|
|
|
$('#news').find('a').forEach(function(item) {
|
|
|
|
var a = $(item);
|
|
|
|
var title = a.text();
|
|
|
|
var link = a.attr('href');
|
|
|
|
var date = a.data('date');
|
|
|
|
|
|
|
|
news.push({title:title, link:link, date:date});
|
|
|
|
});
|
|
|
|
return news;
|
|
|
|
};
|
|
|
|
|
|
|
|
var clearNewsFeed = function() {
|
|
|
|
$('#news').children().forEach(function(child) {
|
|
|
|
child.remove();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateNewsFeed = function(news) {
|
|
|
|
var items = getAddedItems().concat(news);;
|
|
|
|
|
|
|
|
items.sort(function(a, b) {
|
|
|
|
a = new Date(a.date);
|
|
|
|
b = new Date(b.date);
|
|
|
|
|
|
|
|
return a > b ? -1 : a < b ? 1 : 0;
|
|
|
|
});
|
2014-09-12 16:00:41 +02:00
|
|
|
|
2014-09-12 16:32:49 +02:00
|
|
|
clearNewsFeed();
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
items.forEach(function(item) {
|
|
|
|
if(i++ >= MAX_RSS) return;
|
|
|
|
addItem(item.title, item.link, item.date);
|
|
|
|
});
|
2014-09-12 16:00:41 +02:00
|
|
|
};
|
|
|
|
|
2014-09-10 16:49:19 +02:00
|
|
|
rss.forEach(function(feed) {
|
|
|
|
$.get('/feeds/' + feed + '.rss', function(data) {
|
2014-09-12 16:32:49 +02:00
|
|
|
var news = [];
|
|
|
|
|
2014-09-10 17:19:25 +02:00
|
|
|
$(data).find('item').forEach(function(entry) {
|
|
|
|
var title = $(entry).find('title').text();
|
|
|
|
var link = $(entry).find('link').text();
|
2014-09-12 16:32:49 +02:00
|
|
|
var date = $(entry).find('pubDate').text();
|
2014-09-10 16:49:19 +02:00
|
|
|
|
2014-09-12 16:32:49 +02:00
|
|
|
news.push({title:title, link:link, date:date});
|
2014-09-10 16:49:19 +02:00
|
|
|
});
|
2014-09-12 15:57:50 +02:00
|
|
|
|
|
|
|
$(data).find('entry').forEach(function(entry) {
|
|
|
|
var title = $(entry).find('title').text();
|
|
|
|
var link = $(entry).find('link').attr('href');
|
2014-09-12 16:32:49 +02:00
|
|
|
var date = $(entry).find('published').text();
|
2014-09-12 15:57:50 +02:00
|
|
|
|
2014-09-12 16:32:49 +02:00
|
|
|
news.push({title:title, link:link, date:date});
|
2014-09-12 15:57:50 +02:00
|
|
|
});
|
2014-09-12 16:32:49 +02:00
|
|
|
|
|
|
|
updateNewsFeed(news);
|
2014-09-10 16:49:19 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|