/* * This function should be called when handling a redirect from facebook. * * */ function tvg_HandleFacebookRedirect(referrer, target, callback, userid) { var accessToken = window.location.hash.substring(1); var path = "https://graph.facebook.com/me?"; var query = accessToken+"&callback=?"; var url = path + query; // use jsonp to call the graph getJSONP(url, function(data){ //store the access token, call add contact with a userid if one is found var contact = data.id; var token = accessToken.split('=')[1]; token = token.replace('&expires_in', ''); //call add contact to add contact if needed (will not add contact if not needed) tvgAddContact(contact, token, 'FB', referrer, target, userid); //update the parent if(target!='_self') { window.opener.tvgSetCookie('tvgContact', contact); window.opener.tvgSetCookie('tvgPasswordHash', contact); //fire a custom call back function on the parent window var elem = window.opener.window[callback](contact, 'FB', referrer); //close window setTimeout(function() { window.close()}, 200); } else { //handle case when this is self (redirected) } }); } /** * function to call the add contact component */ function tvgAddContact(contact, token, type, referrer, target, userid) { if(target!='_self') { tvgHostUrl = window.opener.tvgHostUrl; } var params = "&tvgReferrer="+referrer+"&tvgContact="+contact+"&tvgType="+type+"&tvgAccessToken="+token; if(userid != undefined) params += "&tvgUserID="+userid; //Add the contact tvgLoadComponent ("?name=addcontact"+params, "tvgConnect"); } /* * Call a url in JSONP format. * */ function getJSONP(url, success) { var ud = '_' + +new Date, script = document.createElement('script'), head = document.getElementsByTagName('head')[0] || document.documentElement; window[ud] = function(data) { head.removeChild(script); success && success(data); }; script.src = url.replace('callback=?', 'callback=' + ud); head.appendChild(script); }