][0];
var callback = [][0];
if (json && !json.error && json.data.length)
{
json.parsedData = [];
var now = new Date();
var date = null;
var maxPostLength = 100;
for( var i = 0; i < json.data.length; i++ )
{
var post = json.data[i];
var data = {};
data.timeStamp = (post.updated_time || post.created_time);
date = Co.Calendar.Date.Parse(data.timeStamp);
data.timeStamp = date.initializedDate;
data.timeStringTitle = date.ToLocalizedString("dddd, MMM. d, yyyy") + ' ' + 'at' + ' ' + date.ToLocalizedString("h:mmtt");
data.timeStringText = date.ToLocalizedString("MMM. d, yyyy") + ' ' + 'at' + ' ' + date.ToLocalizedString("h:mmtt");
var timeDifference = (now.getTime() - data.timeStamp.getTime()) / 1000;
if( timeDifference < 60 )
data.timeStringText = 'wrote seconds ago';
else if( Math.floor(timeDifference / 60) == 1 )
data.timeStringText = 'wrote a minute ago';
else if( timeDifference / 60 < 60 )
{
data.timeStringText = 'wrote <<minutes>> minutes ago';
data.timeStringText = data.timeStringText.replace("<<minutes>>", Math.floor(timeDifference / 60));
}
else if( timeDifference / 60 < 90 )
data.timeStringText = 'wrote about an hour ago';
else if( now.getYear() == data.timeStamp.getYear()
&& now.getMonth() == data.timeStamp.getMonth()
&& now.getDay() == data.timeStamp.getDay() )
data.timeStringText = 'wrote at <<time>>'.replace("<<time>>", date.ToLocalizedString("h:mmtt"));
// NOTE: The post link provided through their API currently points to the source article shared on the respective facebook post.
// Meaning, if on facebook you share a chabad.org article, this value will be the url to that article.
if( post.link )
data.sharedArticleUrl = post.link;
// HACK! - in the new api facebook won't give the link, so it's being taken from the post id.
// Facebook says that the format of the id can change at any time - so this is not the right way to do it
var parts = post.id.split('_');
data.facebookPostUrl = 'https://www.facebook.com/' + parts.shift() + '/posts/' + parts.shift();
data.likesCount = 0;
if (!data.likesCount && post.likes)
data.likesCount = (post.likes.summary.total_count || 0);
data.commentsCount = 0;
if(post.comments)
data.commentsCount = post.comments.data.length;
if(post.shares)
data.sharesCount = post.shares.count;
data.postedBy = post.from.name;
if(post.full_picture || post.picture)
data.pictureUrl = post.full_picture || post.picture;
data.bodyText = post.message || post.story || "";
if (data.bodyText && maxPostLength > -1)
{
var msg = data.bodyText.substr(0, maxPostLength);
if( msg.length < data.bodyText.length )
msg = msg.replace(/[\s\S]$/g, "\u2026");//add ellipsis
data.bodyText = msg;
}
json.parsedData.push( data );
}
}
if( callback )
{
callback.apply(this, [json, "facebook_feed1"]);
}
else if( json.parsedData )
{
var post = json.parsedData[0];
var s = [];
var src = "https://graph.facebook.com/jewishteens/picture?type=small&width=40";
s.push('
');
s.push('
');
s.push('');
s.push('