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
|
|
|
];
|
2015-01-14 20:51:13 +01:00
|
|
|
var MAX_RSS = 3;
|
|
|
|
|
|
|
|
function shorten(text, maxLength) {
|
|
|
|
var ret = text;
|
|
|
|
if (ret.length > maxLength) {
|
|
|
|
ret = ret.substr(0,maxLength-3) + "...";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2014-09-10 16:49:19 +02:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-09-15 14:53:00 +02:00
|
|
|
var addItem = function(title, link, date, text) {
|
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);
|
2014-09-15 14:53:00 +02:00
|
|
|
var prev = $('<p>')
|
|
|
|
.attr('class', 'css-truncate')
|
|
|
|
.html(text);
|
|
|
|
$('#news').append($('<li>').append(item).append(prev));
|
2014-09-12 16:32:49 +02:00
|
|
|
};
|
|
|
|
|
2015-12-07 19:28:54 +01:00
|
|
|
var forEach = function(x, f) {
|
|
|
|
var i;
|
|
|
|
for(i = 0; i < x.length; i++) {
|
|
|
|
f(x[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-12 16:32:49 +02:00
|
|
|
var getAddedItems = function() {
|
|
|
|
var news = [];
|
2015-12-07 19:28:54 +01:00
|
|
|
forEach($('#news').find('li'), function(item) {
|
2014-09-15 14:53:00 +02:00
|
|
|
var a = $(item).children('a');
|
|
|
|
var p = $(item).children('p');
|
2014-09-12 16:32:49 +02:00
|
|
|
var title = a.text();
|
|
|
|
var link = a.attr('href');
|
|
|
|
var date = a.data('date');
|
2014-09-15 14:53:00 +02:00
|
|
|
var text = p.html();
|
2014-09-12 16:32:49 +02:00
|
|
|
|
2014-09-15 14:53:00 +02:00
|
|
|
news.push({title:title, link:link, date:date, text:text});
|
2014-09-12 16:32:49 +02:00
|
|
|
});
|
|
|
|
return news;
|
|
|
|
};
|
|
|
|
|
|
|
|
var clearNewsFeed = function() {
|
2015-12-07 19:28:54 +01:00
|
|
|
forEach($('#news').children(), function(child) {
|
2014-09-12 16:32:49 +02:00
|
|
|
child.remove();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateNewsFeed = function(news) {
|
2015-12-07 19:28:54 +01:00
|
|
|
var items = getAddedItems().concat(news);
|
2014-09-12 16:32:49 +02:00
|
|
|
|
|
|
|
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;
|
2015-01-14 20:51:13 +01:00
|
|
|
addItem(item.title, item.link, item.date, shorten(item.text, 80));
|
2014-09-12 16:32:49 +02:00
|
|
|
});
|
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 = [];
|
|
|
|
|
2015-12-07 19:28:54 +01:00
|
|
|
forEach($(data).find('item'), function(entry) {
|
2014-09-10 17:19:25 +02:00
|
|
|
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-15 14:53:00 +02:00
|
|
|
var text = $(entry).find('description').text();
|
2014-09-10 16:49:19 +02:00
|
|
|
|
2014-09-15 14:53:00 +02:00
|
|
|
news.push({title:title, link:link, date:date, text:text});
|
2014-09-10 16:49:19 +02:00
|
|
|
});
|
2014-09-12 15:57:50 +02:00
|
|
|
|
2015-12-07 19:28:54 +01:00
|
|
|
forEach($(data).find('entry'), function(entry) {
|
2014-09-12 15:57:50 +02:00
|
|
|
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-15 14:53:00 +02:00
|
|
|
var text = $(entry).find('content').text();
|
2014-09-12 15:57:50 +02:00
|
|
|
|
2014-09-15 14:53:00 +02:00
|
|
|
news.push({title:title, link:link, date:date, text:text});
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|