var _facebooker = new function() {
var url = 'https://graph.facebook.com/<username>?callback=?',
threshold = 3,
sKey = "_facebooker",
mode = (window.localStorage ? "storage" : "jcookie");
function getData(){
var data = {};
if (mode === "jcookie")
data = JSON.pase($.cookie(sKey));
else
data = JSON.parse(localStorage.getItem(sKey));
if (typeof data.expired\s == "undefined" || data.expires <= new Date())
return getNewData();
else
return data;
}
function setData(d){
if (mode === "jcookie")
$.cookie(sKey, JSON.stringify(d));
else
localStorage.setItem(sKey, JSON.stringify(d));
return d;
}
function getNewData(){
var data = {};
$.getJSON(url, function(d){
data = {
likeCount: d['likes'],
expires: new Date((new Date()).getTime() + threshold * 60000)
};
setData(data);
});
return data;
}
function getLikeCount(){
return getData().likeCount;
}
return {
"getLikeCount" : getLikeCount
}
}
$(document).ready(function() {
$('#fb_count').html(_facebooker.getLikeCount());
}