Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 data-i18n="app.title"></h2>
<input class='col8' id='address' placeholder='' data-i18n="[placeholder]step1.addr"/>
<button class='col4' id='findme' data-i18n="step1.button"></button>
<br />
Or <a id="use_my_location" href="#" onclick="return false">use my current location</a>.
Or <a id="use_my_location" href="#" onclick="return false">use my current location</a>, <a id='fblogin' href='#' onclick="return false">sync a facebook business page</a>.
</form>
</div>
</div>
Expand Down Expand Up @@ -94,5 +94,23 @@ <h4><button class='col12' id='collect-data-done' data-i18n="step2.done"></button
</div>
</div>
<script src='js/site.js'></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '230563574073994',
xfbml : false,
version : 'v2.8'
});
FB.AppEvents.logPageView();
};

(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'));
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,39 @@ function clearFields() {
$("#category").val('');
$("#address").val('');
}


function fetch_facebook_page_url() {

var page_url = prompt("Copy/paste in your businesses facebook page url; ie: https://www.facebook.com/pages/Adelaide-Hills-Stationery/517688011766722?fref=ts'");
var parts = page_url.split("/");
var fbid = parts[parts.length-1].split("?")[0];

FB.api(
'/' + fbid + '/',
'GET',
{"fields":"id,name,about,single_line_address,website,is_always_open,payment_options,hours,location,category,category_list,company_overview,description,general_info,is_permanently_closed,link,parking,phone,place_type,public_transit,store_location_descriptor"},
function(response) {
$('#address').val(response.single_line_address);
$("#find").submit();

$('#name').val(response.name);
$('#phone').val(response.phone);
$('#website').val(response.link);
$('#opening_hours').val(response.hours);
}
);

}

$('#fblogin').click(function () {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
fetch_facebook_page_url();
} else {
FB.login(function (response) {
fetch_facebook_page_url();
});
}
});
});