var postID = null;
//var postID = 1745365715708413;
var lastTime = (new Date).getTime();
var refreshInterval = 30000;
var pageID = null;
var dataInterval = null;
var numLikes;
var numLoves;
var numWow;
var numHaHa;
var numAngry;
var numSad;
var numThankful;
function initPage() {
pageID = 319034668130985;
//instant articles
//pageID = 1721581924753459;
//getData();
displayMessage("Select a post to view comments...");
$("#pageSelector").on('change', function(eve) {
console.log($("#pageSelector").val());
var theIndex = eve.target.selectedIndex;
var theLabel = eve.currentTarget.children[theIndex].innerHTML;
var newLabel = theLabel.substring(0, 40);
$("#selectedTitle").html(newLabel);
//var theID = $("#pageSelector").val();
getData();
});
$("#pageThing").on('change', function(eve) {
//console.log(theLabel);
//eve.target.selectedIndex
//currentTarget.children.[].innerHTML
// el.options[el.selectedIndex].innerHTML;
// var str = "";
// $("select option:selected").each(function() {
// str += $(this).text() + " ";
// });
//
// //$("div").text(str);
// console.log("selected: " + str);
// $("#selectedTitle").text();
//clear interval
clearInterval(dataInterval);
displayMessage("Select a post to view comments");
// fetch posts
pageID = $("#pageThing").val();
console.log("set pageid " + pageID);
getPostListData();
//var theID = $("#pageSelector").val();
// pageID = $("#pageThing").val();
//getData();
});
getPostListData();
}
// function setPostID(theid) {
// console.log(theid);
// postID = theid;
// getData();
// }
function getPostListDataBOOTSTRAP() {
var theID = 319034668130985;
FB.api(
'/' + theID + '/feed',
'GET', {
order: 'reverse_chronological',
limit: 20
},
function(response) {
var theDropDown = ''; //'Select Post ';
//console.log(response);
//theDropDown = theDropDown + '
' + value + ' ';
$.each(response.data, function(index, value) {
//console.log(value.id);
//theDropDown = theDropDown + '' + value.message.substring(0, 70) + ' ';
var selectedID = "'" + value.id + "'";
theDropDown = theDropDown + '' + value.message.substring(0, 700) + ' ';
});
//theDropDown = theDropDown + '';
$("#selectorChoices").html(theDropDown);
}
);
dataInterval = setInterval(getData, refreshInterval);
}
function getPostReactions(postID) {
//var theID = 319034668130985;
numLikes = 0;
numLoves = 0;
numWow = 0;
numHaHa = 0;
numAngry = 0;
numSad = 0;
numThankful = 0;
FB.api(
'/' + postID + '/reactions',
'GET', {},
function(response) {
$.each(response.data, function(index, value) {
switch (value.type) {
case "LIKE":
numLikes++;
break;
case "LOVE":
numLoves++;
break;
case "THANKFUL":
numThankful++;
break;
case "HAHA":
numHaHa++;
break;
case "SAD":
numSad++;
break;
case "ANGRY":
numAngry++;
break;
} //console.log(value.type);
//theDropDown = theDropDown + '' + value.message.substring(0, 70) + ' ';
// var selectedID = "'" + value.id + "'";
//theDropDown = theDropDown + '' + value.message.substring(0, 700) + ' ';
});
console.log("got reactions");
$('#numLikes').text(numLikes);
setOpacity('numLikes', numLikes);
$('#numLoves').text(numLoves);
setOpacity('numLoves', numLoves);
$('#numHaHa').text(numHaHa);
setOpacity('numHaHa', numHaHa);
$('#numWow').text(numWow);
setOpacity('numWow', numWow);
$('#numAngry').text(numAngry);
setOpacity('numAngry', numAngry);
$('#numSad').text(numSad);
setOpacity('numSad', numSad);
}
);
}
function setOpacity(theID, itemCount) {
var theCount = Number(itemCount);
console.log("setOpacity: " + theCount);
if (theCount > 0) {
//numLikesIcon
$("#" + theID + "Icon").fadeTo("slow", 0.9);
$("#" + theID).fadeTo("slow", 0.9);
} else {
$("#" + theID + "Icon").fadeTo("slow", 0.3);
$("#" + theID).fadeTo("slow", 0.3);
}
}
function getPostListData() {
//Delmarvalife
//var thePageID = 319034668130985;
//other page
var thePageID = pageID; //168146169872122;
console.log(" load posts: " + thePageID);
//wboc
//thePageID = 219252434538;
FB.api(
'/' + thePageID + '/feed',
'GET', {
order: 'reverse_chronological',
limit: 20
},
function(response) {
var theDropDown = 'Select Post ';
//console.log(response.data);
// theDropDown = theDropDown + '' + value + ' ';
$.each(response.data, function(index, value) {
try {
theDropDown = theDropDown + '' + value.message.substring(0, 200) + ' ';
} catch (e) {
} finally {
}
//console.log(value.id);
//theDropDown = theDropDown + '' + value.message.substring(0, 100) + ' ';
});
//theDropDown = theDropDown + '';
$("#pageSelector").html(theDropDown);
}
);
dataInterval = setInterval(getData, refreshInterval);
}
///{{POST_ID}}/?fields=comments{comments}&access_token={{ACCESS_TOKEN}}
//post-id/comments?fields=id,message... [other fields you want] ...,comments{from,message,id... }
//1745365715708413/comments?fields=id,message,comments{from,message,id}
function getData() {
var theID = $("#pageSelector").val();
//console.log("getData: " + theID);
if (theID != "null") {
//console.log(theID);
if (theID) {
getPostReactions(theID);
FB.api(
'/' + theID + '/comments?fields=id,message,comments{message,id,comments,from,created_time},comment_count,from,created_time',
'GET', {
order: 'reverse_chronological',
limit: 20
},
function(response) {
//console.log(response);
// Insert your code here
//makeMediaObject(response);
;
updateDisplayTime(convertTime(Date()));
try {
if (response.data && response.data.length > 0) {
if (lastID != response.data[0].id) {
console.log("new data");
playAlert();
makeTabletheData(response);
} else {
console.log("old data");
makeTabletheData(response);
}
} else {
displayMessage("No comments yet...");
}
} catch (e) {
displayMessage("No comments yet...");
//console.log(response);
console.log(e);
} finally {
//console.log("finally");
}
}
);
} else {
console.log("no object id");
}
}
}
function getDataXX() {
var theID = $("#pageSelector").val();
console.log("getData: " + theID);
if (theID != "null") {
//console.log(theID);
if (theID) {
FB.api(
'/' + theID + '/comments',
'GET', {
order: 'reverse_chronological',
limit: 20
},
function(response) {
//console.log(response);
// Insert your code here
//makeMediaObject(response);
;
updateDisplayTime(convertTime(Date()));
try {
if (response.data && response.data.length > 0) {
if (lastID != response.data[0].id) {
console.log("new data");
playAlert();
makeTabletheData(response);
} else {
console.log("old data");
makeTabletheData(response);
}
} else {
displayMessage("No comments yet...");
}
} catch (e) {
displayMessage("No comments yet...");
//console.log(response);
console.log(e);
} finally {
console.log("finally");
}
}
);
} else {
console.log("no object id");
}
}
}
var auth_status_change_callback = function(response) {
console.log("auth_status_change_callback: " + response.status);
if (response.status == "connected") {
console.log("connected OK");
//setInterval(getData, 5000);
//getData();
initPage();
}
}
function dologin() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('Logged in.');
} else {
FB.login();
}
});
}
function displayMessage(message) {
var theContent = '' + message + '
';
$('#theTable').html(theContent);
}
function updateDisplayTime(thetime) {
$("#updatedTime").text(thetime);
}
function playAlert() {
var audio = new Audio('ding.mp3');
audio.play();
}
function renderReply(theComment) {
//console.log(theComment);
var theCommentHTML = "";
var displayName = theComment.from.name;
var userMessage = theComment.message;
var createdTime = theComment.created_time;
getThumbnailID(theComment.from.id, theComment.id);
theCommentHTML = '';
return theCommentHTML;
}
function renderComment(theComment) {
//console.log(theComment);
var theCommentHTML = "";
var displayName = theComment.from.name;
var userMessage = theComment.message;
var createdTime = theComment.created_time;
getThumbnailID(theComment.from.id, theComment.id);
var milliseconds = (new Date(createdTime)).getTime();
//console.log("post " + milliseconds + " | " + lastTime);
if (milliseconds > lastTime) {
theCommentHTML = '
' + displayName + '
'; theCommentHTML = theCommentHTML + userMessage; theCommentHTML = theCommentHTML + "" + convertTime(createdTime, true) + ""; theCommentHTML = theCommentHTML + '