-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fbstatus.js
62 lines (44 loc) · 1.92 KB
/
jquery.fbstatus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Facebook Status - A super lightweight tool to display current publicly accessible facebook status
* Coded by Ben Greig @ Abitlikethis
* Based on the code example by PrettyKlicks http://www.prettyklicks.com/demo/fbjson.php
* Version 1.0
* http://abitlikethis.com/
**/
(function($){
$.fn.fbstatus = function(options) {
set = jQuery.extend({
username: 'prettyklicks', // [string] required, unless you want to display prettyklicks status. :)
count: 5, // [integer] how many status updates to display?
loading_text: null // [string] optional loading text, displayed while tweets load
}, options);
function fbstatus_link(text){
return text.replace(/(href="|<a.*?>)?[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function($0, $1) {
return $1 ? $0 : $0.link($0);
});
}
//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "http://graph.facebook.com/"+set.username+"/feed?limit="+set.count+"&callback=?";
$(this).each(function(i, widget){
var loading = $('<p class="loading">'+set.loading_text+'</p>');
var theObject = $(this);
if (set.loading_text) $(widget).append(loading);
//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
$.getJSON(url,function(json){
var html = "<ul>";
//loop through and within data array's retrieve the message variable.
$.each(json.data,function(i,fb){
if (fb.message) {
html += "<li>" + fbstatus_link(fb.message) + "</li>";
}
});
html += "</ul>";
//A little animation once fetched
theObject.animate({opacity:0}, 500, function(){
theObject.html(html);
});
theObject.animate({opacity:1}, 500);
});
});
};
})(jQuery);