// JavaScript Document
var getFeeds = function(target, url, num) {
var query = "select * from rss where url=\""+url+"\"";
query = encodeURIComponent(query);
$.getJSON("http://query.yahooapis.com/v1/public/yql?q="+query+"&format=json&callback=?", function(res){
var item = res.query.results.item;
var html = '
';
for( var i = 0; i < num; i++) {
var title = item[i].title;
var pdate = new Date(item[i].pubDate);
var Y = pdate.getFullYear();
var m = pdate.getMonth() + 1;
m = (m < 10)? '0' + m:m;//月数字を2桁に
var d = pdate.getDate();
d = (d < 10)? '0' + d:d;//日数字を2桁に
var date = Y + '.' + m + '.' + d;
var link = (typeof item[i].link === 'string')? item[i].link : item[i].link[0];
html += '- ' + '
' + '- ' + '' + date + 'ブログ' + '
';
html += '- ' + '' + title + '
';
}
html += '
';
var container = document.getElementById(target);
container.innerHTML += html;
latestInfo();
});
};
var feed1 = new getFeeds("feed", 'http://blog.sdtc.ac.jp/feed', 5);
function latestInfo() {
var showNum = 5;
var t02 = $('.tab02 ul').clone().html();
var t03 = $('.tab03 ul').clone().html();
var t04 = $('.tab04 ul').clone().html();
var tmp = $('');
tmp.css('display', 'none');
$('body').append(tmp);
tmp.html(
$('.latest li').sort(function(a, b){
var dtA = $(a).find('em').html();
var dtB = $(b).find('em').html();
dtA = dtA.split('.');
dtB = dtB.split('.');
var dateA = new Date(parseInt(dtA[0].substr(dtA[0].length - 4), 10), parseInt(dtA[1], 10) - 1, dtA[2]);
var dateB = new Date(parseInt(dtB[0].substr(dtB[0].length - 4), 10), parseInt(dtB[1], 10) - 1, dtB[2]);
return parseInt((dateB.getTime() - dateA.getTime() < 0)? -1 : ((dateB.getTime() - dateA.getTime() > 0)? 1 : 0));
})
);
tmp.find('li').each(function(i){
if(i >= showNum) {
$(this).remove();
}
});
$('.tab01 section').empty();
$('.tab01 section').append(tmp);
tmp.fadeIn();
}