This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.FB.friends-selector.js
79 lines (71 loc) · 2.79 KB
/
jquery.FB.friends-selector.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* jQuery Plugin to display all friends of the user and give the opportunity to send them a mail
*
* Needs FB Api and jquery.tmpl to be loaded before
*
*/
(function( $ ){
$.fn.friendsSelector = function(method) {
var friends; // friends from facebook
var targets = this;
var settings = {
'perms' : '',
'auto_login' : false
};
var methods = {
init: function(options){
if (options) {
$.extend(settings, options);
}
if ((typeof FB != 'undefined') && (FB.ready)) {
checkFB();
} else {
$(document).bind('FB.ready', checkFB);
}
return this.each(function(){
$(this).append('<p>' + '<fb:login-button perms="' + settings['perms'] + '"></fb:login-button>' + '</p>');
});
},
unselect : function() {
return this.each(function() {
$(this).find('.selected').removeClass('selected');
})
}
}
checkFB = function() {
FB.getLoginStatus(function(response) {
if (response.session) {
build(response)
} else {
if (settings.auto_login) {
FB.login(build, {perms: settings['perms']});
}
FB.Event.subscribe('auth.login', build);
}
});
//FB.Event.subscribe('auth.sessionChange', build);
}
function build(response) {
FB.api('/me/friends/', function(response) {
friends = response['data'];
targets.each(function(){
$(this).children().remove();
$('#friendTemplate').tmpl(friends).appendTo($(this));
$(this).find('a.fb-friend').click(function(){
$(this).siblings().removeClass('selected');
$(this).addClass('selected');
$(this).trigger('select.friendsSelector', [$(this).tmplItem().data])
});
$(this).trigger('loaded', friends);
});
})
}
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.wallPoster' );
}
}
})( jQuery );