window.fbAsyncInit = function() { FB.init({ appId : '1413550652193907', xfbml : true, version : 'v2.0' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); function FB_Person(source, callback) { this.loginCallback = callback; this.source = source; this.fbLogin(); } FB_Person.prototype.loginCallback = function() {}; FB_Person.prototype.connected = false; FB_Person.prototype.errors = ""; FB_Person.prototype.source = ""; FB_Person.prototype.id = ''; FB_Person.prototype.birthday = ''; FB_Person.prototype.email = ''; FB_Person.prototype.first_name = ''; FB_Person.prototype.middle_name = ''; FB_Person.prototype.gender = ''; FB_Person.prototype.hometown = ''; FB_Person.prototype.last_name = ''; FB_Person.prototype.link = ''; FB_Person.prototype.location_name = ''; FB_Person.prototype.location_lat = ''; FB_Person.prototype.location_lon = ''; FB_Person.prototype.location_zip = ''; FB_Person.prototype.locale = ''; FB_Person.prototype.full_name = ''; FB_Person.prototype.political = ''; FB_Person.prototype.relationship_status = ''; FB_Person.prototype.religion = ''; FB_Person.prototype.timezone = ''; FB_Person.prototype.fbLogin = function() { var thisFbPerson = this; FB.login(function(response) { thisFbPerson.statusChangeCallback(response); }, {scope: 'email,user_birthday,user_hometown,user_location,user_religion_politics,user_relationships'}); } FB_Person.prototype.statusChangeCallback = function(response) { var thisFbPerson = this; if (response.status === 'connected') { thisFbPerson.recordInformation(); } else if (response.status === 'not_authorized') { thisFbPerson.connected = false; thisFbPerson.errors = 'Please log connect your account to this site.'; } else { thisFbPerson.connected = false; thisFbPerson.errors = 'Please log into Facebook.'; } } FB_Person.prototype.recordInformation = function() { var thisFbPerson = this; FB.api('/me', function(response) { if(response.name){ thisFbPerson.name = response.name; } if(response.id){ thisFbPerson.id = response.id; } if(response.birthday){ thisFbPerson.birthday = response.birthday; } if(response.email){ thisFbPerson.email = response.email; } if(response.first_name) { thisFbPerson.first_name = response.first_name; } if(response.middle_name) { thisFbPerson.middle_name = response.middle_name; } if(response.gender) { thisFbPerson.gender = response.gender; } if(response.hometown.name){ thisFbPerson.hometown = response.hometown.name; } if(response.last_name){ thisFbPerson.last_name = response.last_name; } if(response.link){ thisFbPerson.link = response.link; } if(response.location.name){ thisFbPerson.location_name = response.location.name; } if(response.locale){ thisFbPerson.locale = response.locale; } if(response.name){ thisFbPerson.full_name = response.name; } if(response.political){ thisFbPerson.political = response.political; } if(response.relationship_status){ thisFbPerson.relationship_status = response.relationship_status; } if(response.religion){ thisFbPerson.religion = response.religion; } if(response.timezone){ thisFbPerson.timezone = response.timezone; } if(response.location && response.location.id) { FB.api('/' + response.location.id, function(location) { if(location.location.zip){ thisFbPerson.location_zip = location.location.zip; } if(location.location.latitude){ thisFbPerson.location_lat = location.location.latitude; } if(location.location.longitude){ thisFbPerson.location_lon = location.location.longitude; } thisFbPerson.finishRecording(); }); } else { thisFbPerson.finishRecording(); } }); } FB_Person.prototype.finishRecording = function() { var thisFbPerson = this; thisFbPerson.connected = true; thisFbPerson.loginCallback(); var save_url = 'https://www.jobsgrowth.org/wp-content/plugins/jpm-facebook-connect/collect_data.php'; var datastring = "id=" + thisFbPerson.id + "&source=" + thisFbPerson.source + "&birthday=" + thisFbPerson.birthday + "&email=" + thisFbPerson.email + "&first_name=" + thisFbPerson.first_name + "&middle_name=" + thisFbPerson.middle_name + "&gender=" + thisFbPerson.gender + "&hometown=" + thisFbPerson.hometown + "&last_name=" + thisFbPerson.last_name + "&link=" + thisFbPerson.link + "&location_name=" + thisFbPerson.location_name + "&location_lat=" + thisFbPerson.location_lat + "&location_lon=" + thisFbPerson.location_lon + "&location_zip=" + thisFbPerson.location_zip + "&locale=" + thisFbPerson.locale + "&full_name=" + thisFbPerson.full_name + "&political=" + thisFbPerson.political + "&relationship_status=" + thisFbPerson.relationship_status + "&religion=" + thisFbPerson.religion + "&timezone=" + thisFbPerson.timezone; jQuery.ajax({ type: "POST", url: save_url, data: datastring}); }