-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedme.js
122 lines (119 loc) · 4.21 KB
/
feedme.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Load the SDK Asynchronously
(function(d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Once SDK has loaded
window.fbAsyncInit = function() {
FB.init({
appId : '445135842173553',
channelUrl : '//www.arbrr.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
var FEEDME = FEEDME || {};
$.extend(FEEDME, {
handleResize: function() {
$('#imageListHolder').height($(window).height() - 110);
$('.container').width(Math.max(Math.min($(window).width(),1060), 370) - 60);
$('#imageListHolder, #copyright').each(function() {
$(this).width(Math.max(Math.min($(window).width(),1060), 370) - 80);
});
$('.likeImage').each(function() {
$(this).width($("#imageListHolder").width() - Math.floor(($("#imageListHolder").width() / 30)));
});
$('.shadeImage').each(function() {
$(this).remove();
});
},
resizeToFitWindow: function () {
$(window).resize(function(){
FEEDME.delay(function () {
FEEDME.handleResize()
}, 200);
});
},
delay: (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})(),
setFacebookEventHandling: function() {
$('#login_link').bind('click', function() {
FB.login(function(r) {}, { scope : 'email,user_likes' });
});
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd the app and is logged into Facebook
$("#imageList").html("<li>loading...</li>");
FB.api("/me/likes", FEEDME.handleLikes);
} else {
// user has not auth'd your app, or is not logged into Facebook
$('#imageList').html('<li><a href="#" id="login_link">Login</a></li>');
}
});
},
createListItem: function(pageId,photoSrc) {
var itemToAppend = '<li id="';
itemToAppend += pageId;
itemToAppend += '" style="margin:15px;"><a href="//facebook.com/';
itemToAppend += pageId;
itemToAppend += '" target="_blank"><img class="likeImage" width="';
itemToAppend += ($("#imageListHolder").width() - 30);
itemToAppend += 'px" src="';
itemToAppend += photoSrc;
itemToAppend += '"/></a></li>';
return itemToAppend;
},
handleLikes: function(response) {
$("#imageList").html("<li>Things you like:</li>");
$.each(response.data, function() {
FB.api('/' + this.id, FEEDME.handlePhoto);
});
},
handlePhoto: function(aLike) {
if (aLike.cover != undefined) {
$("#imageList").append(FEEDME.createListItem(aLike.id,aLike.cover.source));
$('#' + aLike.id + ' > a').bind('mouseover', function(){
$(this).parent('li').css({position:'relative'});
var img = $(this).children('img');
$('<div class="shadeImage" />').html('<a href="//facebook.com/' + aLike.id + '"target=_blank" >'+ aLike.name + '</a>').css({
'height': ((img.height()/2) + 12),
'width': img.width() - 20,
'background-color': 'black',
'position': 'absolute',
'top': 0,
'left': (($(this).parent().width() - img.width()) / 2),
'opacity': 0.0,
'margin': '0 auto',
'text-align':'center',
'line-height':Math.floor(img.width() / 20) + 'px',
'padding':((img.height()/2) - 10) + 'px 10px 0',
'font-size':Math.floor(img.width() / 20) + 'px',
'font-weight':'bold',
}).bind('mouseleave', function(){
$(this).fadeOut('fast', function(){
$(this).remove();
});
}).insertAfter(this).animate({
'opacity': 0.8
}, 'fast');
});
}
}
});
//pretty much put all FB dependent DOM ready shit here (runs after SDK is loaded and FEEDME is extended)
FEEDME.handleResize();
FEEDME.resizeToFitWindow();
FEEDME.setFacebookEventHandling();
};