Remove duplicate code

This commit is contained in:
kpcyrd 2014-09-12 16:00:41 +02:00
parent 85d039a640
commit 94bc111b20

View file

@ -5,34 +5,34 @@ var MAX_RSS = 5;
$(document).ready(function() {
var i = 0;
var addItem = function(title, link) {
if(i >= MAX_RSS) return;
var item = $('<a>')
.attr('class', 'css-truncate')
.attr('href', link)
.attr('target', '_blank')
.text(title);
$('#news').append($('<li>').append(item));
i++;
};
rss.forEach(function(feed) {
$.get('/feeds/' + feed + '.rss', function(data) {
$(data).find('item').forEach(function(entry) {
if(i >= MAX_RSS) return;
var title = $(entry).find('title').text();
var link = $(entry).find('link').text();
var item = $('<a>')
.attr('class', 'css-truncate')
.attr('href', link)
.attr('target', '_blank')
.text(title);
$('#news').append($('<li>').append(item));
i++;
addItem(title, link);
});
$(data).find('entry').forEach(function(entry) {
if(i >= MAX_RSS) return;
var title = $(entry).find('title').text();
var link = $(entry).find('link').attr('href');
var item = $('<a>')
.attr('class', 'css-truncate')
.attr('href', link)
.attr('target', '_blank')
.text(title);
$('#news').append($('<li>').append(item));
i++;
addItem(title, link);
});
});
});