function showPlanFBComments(targetid) { showFBComments("Facebook Comments for current plan"); //, targetid); } function showGeoFBComments(targetid) { showFBComments("Facebook Comments for Location", targetid); } function showFBComments(title, targetid) { var title_elem = document.getElementById("popup-title"); title_elem.innerHTML = title; //hint for the refresh from: //http://stackoverflow.com/questions/11122633/how-to-dynamically-change-facebook-comments-plugin-url-based-on-javascript-varia var fb_elem = document.getElementById("fb-content"); fb_elem.innerHTML='
'; FB.XFBML.parse(fb_elem); window.location.hash = '#popup1'; //the(?) way to show the css popup console.log("showFBComments", title, targetid); } function hideFBComments() { window.location.hash = ''; //the(?) way to hide the css popup //NOTE: should we clear the fb content here too, or trust that only the show* func above enables the panel and sets the state before show? //UPDATE: is done in post form show //to re-enable keyboard input there, uh gameInstance.SendMessage('Rts-camera', 'EnableKeyboardCapture'); } function showFBPostForm() { var fbpost_elem = document.getElementById("fbpost-view"); fbpost_elem.style.display = "none"; var fbform_elem = document.getElementById("fbform"); fbform_elem.style.display = "block"; /*reset form, file and message document.getElementById("upload-photo-form-file").reset(); document.getElementById("message").reset(); document.getElementById("upload").reset(); */ document.getElementById("upload-photo-form-file").value = ""; document.getElementById("message").value = ""; document.getElementById("upload").value = "Post to Facebook"; window.location.hash = '#popup1'; //the(?) way to show the css popup } //works to group function postToFB(msg) { console.log("postToFB(): " + msg); //var body = 'Reading JS SDK documentation'; FB.api('/' + fbGroupId + '/feed', 'post', { message: msg, //is_hidden: true }, function (response) { if (!response || response.error) { alert('Error occured'); console.log(response.error); } else { //alert('Post ID: ' + response.id); console.log('Post ID: ' + response.id) postid = response.id.split('_')[1]; //first part seems to be group id gameInstance.SendMessage('Playfab-Configurations', 'ImagePosted', postid); } }); } function uploadPost() { var postForm = document.getElementById("upload-photo-form"); if (document.getElementById("upload-photo-form-file").value == "") { //post to feed, not photo upload var msg = document.getElementById("message").value; if (msg) { postToFB(msg); } } else { uploadPhoto(postForm); } var submitButton = document.getElementById("upload"); submitButton.setAttribute("value", "(.. uploading ..)") } function uploadPhoto(postForm) { var action_url = 'https://graph.facebook.com/' + fbGroupId + '/photos?access_token=' + accessToken; //var form = document.getElementById('upload-photo-form'); //form.setAttribute('action', action_url); //form.submit(); var xhr = new XMLHttpRequest(); xhr.open("POST", action_url); xhr.onload = function (event) { //alert("The server says: " + event.target.response); var response = JSON.parse(event.target.response); console.log(response); if (response.id && response.post_id) { console.log("succesful image upload to FB page"); postid = response.post_id.split('_')[1]; //first part seems to be group id gameInstance.SendMessage('Playfab-Configurations', 'ImagePosted', postid); } }; var formData = new FormData(postForm); xhr.send(formData); /*$('upload-photo-form') .ajaxForm({ url: action_url, dataType: 'json', success: function (response) { alert("The server says: " + response); } });*/ } function showFBPost(id) { //the plain 'id' & stripped post_id is the same :o var fbform_elem = document.getElementById("fbform"); fbform_elem.style.display = "none"; var post_id = id; var fb_elem = document.getElementById("fb-content"); var fbpost_elem = document.getElementById("fbpost-view"); fbpost_elem.style.display = "block"; var permurl = "https://www.facebook.com/permalink.php?story_fbid=" + post_id + "&id=" + id; fbpost_elem.setAttribute('data-href', permurl); //FB.XFBML.parse(fbpost_elem); //didn't do anything FB.XFBML.parse(fb_elem); //this works instead, i.e. parse the parent window.location.hash = '#popup1'; }