2010-02-01 10:38:33 +00:00
|
|
|
(function() {
|
2010-02-01 01:59:21 +00:00
|
|
|
var articles = null;
|
2010-02-02 02:07:40 +00:00
|
|
|
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
|
|
|
|
var per_page = 10;
|
2009-11-23 09:33:21 +00:00
|
|
|
|
2010-02-01 10:38:33 +00:00
|
|
|
function render_article(o) {
|
|
|
|
return '<li>\n\
|
|
|
|
<abbr class="calender date" title="' + (Mojo.escape(Mojo.normalize(o.date))) + '">\n\
|
|
|
|
<span class="day">' + (Mojo.escape(Mojo.normalize(o.day))) + '</span>\n\
|
|
|
|
<span class="month">' + (Mojo.escape(Mojo.normalize(o.month))) + '</span>\n\
|
|
|
|
<span class="year">' + (Mojo.escape(Mojo.normalize(o.year))) + '</span>\n\
|
|
|
|
</abbr>\n\
|
|
|
|
<p>\n\
|
|
|
|
<strong><a href="' + (Mojo.escape(Mojo.normalize(o.path))) + '">' + (Mojo.escape(Mojo.normalize(o.title))) + '</a></strong>\n\
|
|
|
|
' + (Mojo.escape(Mojo.normalize(o.summary))) + '\n\
|
|
|
|
</p>\n\
|
|
|
|
</li>';
|
2010-02-01 01:59:21 +00:00
|
|
|
};
|
|
|
|
|
2010-02-02 02:07:40 +00:00
|
|
|
function update_pagination_controls(page) {
|
2010-02-04 02:42:58 +00:00
|
|
|
var older = $('.pagination .older').attr('href', '#' + (page + 1));
|
|
|
|
var newer = $('.pagination .newer').attr('href', '#' + (page - 1));
|
2010-02-03 02:34:04 +00:00
|
|
|
|
2010-02-02 02:07:40 +00:00
|
|
|
// Hide if out of range
|
2010-02-04 02:42:58 +00:00
|
|
|
older.css('visibility', page * per_page >= articles.length ? 'hidden' : 'visible');
|
|
|
|
newer.css('visibility', page <= 1 ? 'hidden' : 'visible');
|
2010-02-02 02:07:40 +00:00
|
|
|
};
|
|
|
|
|
2010-02-01 10:38:33 +00:00
|
|
|
function articles_loaded(data) {
|
|
|
|
articles = data;
|
|
|
|
jQuery(function() {
|
2010-02-03 02:34:04 +00:00
|
|
|
$(window).bind('hashchange', function(e) {
|
2010-02-01 10:38:33 +00:00
|
|
|
// Get the hash (fragment) as a string, with any leading # removed. Note that
|
|
|
|
// in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
|
|
|
|
var page;
|
|
|
|
var matches;
|
|
|
|
var page_fragment = e.fragment;
|
2010-02-03 02:34:04 +00:00
|
|
|
if(matches = page_fragment.match(/(\d+)$/)) {
|
2010-02-01 10:38:33 +00:00
|
|
|
page = new Number(matches[1]);
|
|
|
|
}
|
|
|
|
else {
|
2010-02-03 02:34:04 +00:00
|
|
|
page = 1;
|
2010-02-01 10:38:33 +00:00
|
|
|
}
|
2010-02-03 02:34:04 +00:00
|
|
|
|
2010-02-02 02:30:14 +00:00
|
|
|
var container = $('ul.articles');
|
2010-02-03 02:34:04 +00:00
|
|
|
container.empty();
|
2010-02-01 01:59:21 +00:00
|
|
|
|
2010-02-01 10:38:33 +00:00
|
|
|
// Generate the items
|
|
|
|
var i = (page - 1) * per_page;
|
2010-02-02 02:07:40 +00:00
|
|
|
for(; i < page * per_page && i < articles.length; i++) {
|
2010-02-01 10:38:33 +00:00
|
|
|
var article = articles[i];
|
|
|
|
var date = new Date(Date.parse(article.date));
|
|
|
|
var article_view = {
|
|
|
|
date: article.date,
|
2010-02-02 02:07:40 +00:00
|
|
|
day: date.getDate(),
|
|
|
|
month: months[date.getMonth()],
|
|
|
|
year: date.getYear() + 1900,
|
2010-02-01 10:38:33 +00:00
|
|
|
path: article.path,
|
|
|
|
title: article.title,
|
|
|
|
summary: article.summary
|
|
|
|
};
|
|
|
|
var li = render_article(article_view);
|
|
|
|
container.append(li);
|
|
|
|
}
|
2010-02-03 02:34:04 +00:00
|
|
|
|
2010-02-02 02:07:40 +00:00
|
|
|
update_pagination_controls(page);
|
2010-02-03 02:34:04 +00:00
|
|
|
window.document.title = "All Articles - Page " + page
|
2010-02-01 10:38:33 +00:00
|
|
|
});
|
2010-02-01 01:59:21 +00:00
|
|
|
|
2010-02-01 10:38:33 +00:00
|
|
|
// Since the event is only triggered when the hash changes, we need to trigger
|
|
|
|
// the event now, to handle the hash the page may have loaded with.
|
2010-02-03 02:34:04 +00:00
|
|
|
$(window).trigger('hashchange');
|
2010-02-03 10:53:58 +00:00
|
|
|
show_javascript_widgets();
|
|
|
|
webkit_search_tweak();
|
2010-02-01 10:38:33 +00:00
|
|
|
});
|
|
|
|
};
|
2010-02-02 02:07:40 +00:00
|
|
|
|
|
|
|
// Load articles JSON ASAP
|
2010-02-03 02:34:04 +00:00
|
|
|
jQuery.getJSON('../json/articles.json', {}, articles_loaded);
|
2010-02-01 10:38:33 +00:00
|
|
|
})();
|