This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
facebook_wall.plugin.js
254 lines (242 loc) · 12.8 KB
/
facebook_wall.plugin.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
(function($) {
$.fn.facebook_wall = function(options) {
if (options.id === undefined || options.access_token === undefined) {
return;
}
options = $.extend({
id: '',
access_token: '',
limit: 15, // You can also pass a custom limit as a parameter.
timeout: 400,
speed: 400,
effect: 'slide', // slide | fade | none
locale: 'da_DK', // your contry code
avatar_size: 'square', // square | small | normal | large
message_length: 200, // Any amount you like. Above 0 shortens the message length
show_guest_entries: true, // true | false
text_labels: {
shares: {
singular: 'Delt % gang',
plural: 'Delt % gange'
},
likes: {
singular: '% synes godt om',
plural: '% synes godt om'
},
comments: {
singular: '% kommentar',
plural: '% kommentarer'
},
like: 'Synes godt om',
comment: 'Skriv kommentar',
share: 'Del',
weekdays: ['Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'],
months: ['januar', 'februar', 'marts', 'april', 'maj', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'december'],
seconds: {
few: 'Få sekunder siden',
plural: ' sekunder siden'
},
minutes: {
singular: ' minut siden',
plural: ' minutter siden'
},
hours: {
singular: ' time siden',
plural: ' timer siden'
},
days: {
singular: ' dag siden',
plural: ' dage siden'
}
},
on_complete: null
}, options);
var graphURL = 'https://graph.facebook.com/',
graphTYPE = (options.show_guest_entries === false) ? 'posts' : 'feed',
graphPOSTS = graphURL + options.id + '/' + graphTYPE + '/?access_token=' + options.access_token + '&limit=' + options.limit + '&locale=' + options.locale + '&date_format=U&callback=?',
e = $(this);
e.append('<div class="facebook-loading"></div>');
$.getJSON(graphPOSTS, function(posts) {
$.each(posts.data, function() {
var output = '',
post_class = '',
media_class = '',
split_id = '';
if (this.is_hidden === false) {
if (this.type === 'link') {
post_class = 'type-link ';
} else if (this.type === 'photo') {
post_class = 'type-photo ';
} else if (this.type === 'status') {
post_class = 'type-status ';
} else if (this.type === 'video') {
post_class = 'type-video ';
}
output += '<li class="post ' + post_class + 'avatar-size-' + options.avatar_size + '">';
output += '<div class="meta-header">';
output += '<div class="avatar"><a href="http://www.facebook.com/profile.php?id=' + this.from.id + '" target="_blank" title="' + this.from.name + '"><img src="' + (graphURL + this.from.id + '/picture?type=' + options.avatar_size) + '" alt="' + this.from.name + '" /></a></div>';
output += '<div class="author"><a href="http://www.facebook.com/profile.php?id=' + this.from.id + '" target="_blank" title="' + this.from.name + '">' + this.from.name + '</a></div>';
output += '<div class="date">' + timeToHuman(this.created_time) + '</div>';
output += '</div>';
if (this.message !== undefined) {
if (options.message_length > 0 && this.message.length > options.message_length) {
output += '<div class="message">' + modText(this.message.substring(0, options.message_length)) + '...</div>';
} else {
output += '<div class="message">' + modText(this.message) + '</div>';
}
} else if (this.story !== undefined) {
if (options.message_length > 0 && this.story.length > options.message_length) {
output += '<div class="story">' + modText(this.story.substring(0, options.message_length)) + '...</div>';
} else {
output += '<div class="story">' + modText(this.story) + '</div>';
}
}
if (this.type === 'link' || this.type === 'photo' || this.type === 'video') {
if (this.picture !== undefined || this.object_id !== undefined) {
media_class = ' border-left';
} else {
media_class = '';
}
output += '<div class="media' + media_class + ' clearfix">';
if (this.picture !== undefined) {
output += '<div class="image"><a href="' + this.link + '" target="_blank"><img src="' + this.picture + '" /></a></div>';
} else if (this.object_id !== undefined) {
output += '<div class="image"><a href="' + this.link + '" target="_blank"><img src="' + (graphURL + this.object_id + '/picture?type=album') + '" /></a></div>';
}
output += '<div class="media-meta">';
if (this.name !== undefined) {
output += '<div class="name"><a href="' + this.link + '" target="_blank">' + this.name + '</a></div>';
}
if (this.caption !== undefined) {
output += '<div class="caption">' + modText(this.caption) + '</div>';
}
if (this.description !== undefined) {
output += '<div class="description">' + modText(this.description) + '</div>';
}
output += '</div>';
output += '</div>';
}
output += '<div class="meta-footer">';
output += '<time class="date" datetime="' + this.created_time + '" pubdate>' + timeToHuman(this.created_time) + '</time>';
if (this.likes !== undefined && this.likes.data !== undefined) {
if (this.likes.count !== undefined) {
if (this.likes.count === 1) {
output += '<span class="seperator">·</span><span class="likes">' + options.text_labels.likes.singular.replace('%', this.likes.count) + '</span>';
} else {
output += '<span class="seperator">·</span><span class="likes">' + options.text_labels.likes.plural.replace('%', this.likes.count) + '</span>';
}
} else {
if (this.likes.data.length === 1) {
output += '<span class="seperator">·</span><span class="likes">' + options.text_labels.likes.singular.replace('%', this.likes.data.length) + '</span>';
} else {
output += '<span class="seperator">·</span><span class="likes">' + options.text_labels.likes.plural.replace('%', this.likes.data.length) + '</span>';
}
}
}
if (this.comments !== undefined && this.comments.data !== undefined) {
if (this.comments.data.length === 1) {
output += '<span class="seperator">·</span><span class="comments">' + options.text_labels.comments.singular.replace('%', this.comments.data.length) + '</span>';
} else {
output += '<span class="seperator">·</span><span class="comments">' + options.text_labels.comments.plural.replace('%', this.comments.data.length) + '</span>';
}
}
if (this.shares !== undefined) {
if (this.shares.count === 1) {
output += '<span class="seperator">·</span><span class="shares">' + options.text_labels.shares.singular.replace('%', this.shares.count) + '</span>';
} else {
output += '<span class="seperator">·</span><span class="shares">' + options.text_labels.shares.plural.replace('%', this.shares.count) + '</span>';
}
} else {
output += '<span class="seperator">·</span><span class="shares">' + options.text_labels.shares.plural.replace('%', '0') + '</span>';
}
split_id = this.id.split('_');
output += '<div class="actionlinks"><span class="like"><a href="http://www.facebook.com/permalink.php?story_fbid=' + split_id[1] + '&id=' + split_id[0] + '" target="_blank">' + options.text_labels.like + '</a></span><span class="seperator">·</span><span class="comment"><a href="http://www.facebook.com/permalink.php?story_fbid=' + split_id[1] + '&id=' + split_id[0] + '" target="_blank">' + options.text_labels.comment + '</a></span><span class="seperator">·</span><span class="share"><a href="http://www.facebook.com/permalink.php?story_fbid=' + split_id[1] + '&id=' + split_id[0] + '" target="_blank">' + options.text_labels.share + '</a></span></div>';
output += '</div>';
if (this.likes !== undefined && this.likes.data !== undefined) {
output += '<ul class="like-list">';
for (var l = 0; l < this.likes.data.length; l++) {
output += '<li class="like">';
output += '<div class="meta-header">';
output += '<div class="avatar"><a href="http://www.facebook.com/profile.php?id=' + this.likes.data[l].id + '" target="_blank" title="' + this.likes.data[l].name + '"><img src="' + (graphURL + this.likes.data[l].id + '/picture?type=' + options.avatar_size) + '" alt="' + this.likes.data[l].name + '" /></a></div>';
output += '<div class="author"><a href="http://www.facebook.com/profile.php?id=' + this.likes.data[l].id + '" target="_blank" title="' + this.likes.data[l].name + '">' + this.likes.data[l].name + '</a>' + options.text_labels.likes.singular.replace('%', '') + '</div>';
output += '</div>';
output += '</li>';
}
output += '</ul>';
}
if (this.comments !== undefined && this.comments.data !== undefined) {
output += '<ul class="comment-list">';
for (var c = 0; c < this.comments.data.length; c++) {
output += '<li class="comment">';
output += '<div class="meta-header">';
output += '<div class="avatar"><a href="http://www.facebook.com/profile.php?id=' + this.comments.data[c].from.id + '" target="_blank" title="' + this.comments.data[c].from.name + '"><img src="' + (graphURL + this.comments.data[c].from.id + '/picture?type=' + options.avatar_size) + '" alt="' + this.comments.data[c].from.name + '" /></a></div>';
output += '<div class="author"><a href="http://www.facebook.com/profile.php?id=' + this.comments.data[c].from.id + '" target="_blank" title="' + this.comments.data[c].from.name + '">' + this.comments.data[c].from.name + '</a></div>';
output += '<time class="date" datetime="' + this.comments.data[c].created_time + '" pubdate>' + timeToHuman(this.comments.data[c].created_time) + '</time>';
output += '</div>';
output += '<div class="message">' + modText(this.comments.data[c].message) + '</div>';
output += '<time class="date" datetime="' + this.comments.data[c].created_time + '" pubdate>' + timeToHuman(this.comments.data[c].created_time) + '</time>';
output += '</li>';
}
output += '</ul>';
}
output += '</li>';
e.append(output);
}
});
}).complete(function() {
$('.facebook-loading', e).fadeOut(800, function() {
$(this).remove();
for (var p = 0; p < e.children('li').length; p++) {
if (options.effect === 'none') {
e.children('li').eq(p).show();
} else if (options.effect === 'fade') {
e.children('li').eq(p).delay(p*options.timeout).fadeIn(options.speed);
} else {
e.children('li').eq(p).delay(p*options.timeout).slideDown(options.speed, function() {
$(this).css('overflow', 'visible');
});
}
}
});
if ($.isFunction(options.on_complete)) {
options.on_complete.call();
}
});
function modText(text) {
return nl2br(autoLink(escapeTags(text)));
}
function nl2br(str) {
return str.replace(/(\r\n)|(\n\r)|\r|\n/g, '<br />');
}
function autoLink(str) {
return str.replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '<a href="$1" target="_blank">$1</a>');
}
function escapeTags(str) {
return str.replace(/</g, '<').replace(/>/g, '>');
}
function timeToHuman(time) {
var timestamp = new Date(time*1000),
dateString = timestamp.toGMTString(),
time_difference = Math.round(new Date().getTime()/1000)-time;
if (time_difference < 10) {
return options.text_labels.seconds.few;
} else if (time_difference < 60) {
return Math.round(time_difference) + options.text_labels.seconds.plural;
} else if (Math.round(time_difference/60) === 1) {
return Math.round(time_difference/60) + options.text_labels.minutes.singular;
} else if (Math.round(time_difference/60) < 60) {
return Math.round(time_difference/60) + options.text_labels.minutes.plural;
} else if (Math.round(time_difference/(60*60)) === 1) {
return Math.round(time_difference/(60*60)) + options.text_labels.hours.singular;
} else if (Math.round(time_difference/(60*60)) < 24) {
return Math.round(time_difference/(60*60)) + options.text_labels.hours.plural;
} else if (Math.round(time_difference/(60*60*24)) === 1) {
return Math.round(time_difference/(60*60*24)) + options.text_labels.days.singular;
} else if (Math.round(time_difference/(60*60*24)) <= 10) {
return Math.round(time_difference/(60*60*24)) + options.text_labels.days.plural;
} else {
return options.text_labels.weekdays[timestamp.getDay()] + ' d. ' + timestamp.getDate() + '. ' + options.text_labels.months[timestamp.getMonth()] + ' ' + timestamp.getFullYear();
}
}
};
})(jQuery);