$(document).ready(function() {
$("div.wordpress").each(function(j) {
var closure = $(this);
$(this).removeClass("hidden");
$(this).find("ul").append("
Loading feed...");
var feed_url = $(this).find("input.feedurl").val();
$.getJSON("https://pssweb.manchester.ac.uk/includes/php/apps/wordpress/json_feed_fetcher.php?callback=?", {
"feed_url": feed_url + "feed/",
"limit": 10
}, function(data) {
if (data.outcome == "error") {
$(closure).find("ul").empty().append("ERROR: " + data.message + "");
}
if (data.outcome == "success") {
$(closure).find("ul").empty();
if (data.result.length == 0) {
$(closure).find("ul").append("No posts at the moment");
} else for (var i = 0; i < data.result.length; i++) {
var datetime = data.result[i].published;
var text = data.result[i].title;
text = text.replace(new RegExp("http://[-a-z0-9._/]+", "ig"), "$&");
$(closure).find("ul").append("Read this post");
$(closure).find("ul").children("li:last").children("p").html(text);
$(closure).find("ul").children("li:last").children(".time").text(datetime);
$(closure).find("ul").children("li:last").children("a.more").attr("href", data.result[i].link);
if (i > 2) $(closure).find("ul").children("li:last").addClass("post3");
}
}
});
});
});