/* ----- Login with Fb/Tw ----- */ (function ($) { function is_available (service) { var all = l10nAppApi && l10nAppApi.show_login_button ? l10nAppApi.show_login_button : []; return all.indexOf(service) >= 0; } function create_app_login_interface ($me) { if ($("#appointments-login_links-wrapper").length) { $("#appointments-login_links-wrapper").remove(); } $me.parents('.appointments-login').after('
'); var $root = $("#appointments-login_links-wrapper"); $root.html( '
' + l10nAppApi.please_wait);
$.post(_appointments_data.ajax_url, {
"action": "app_facebook_login",
"user_id": resp.authResponse.userID,
"token": FB.getAccessToken()
}, function (data) {
var status = 0;
try { status = parseInt(data.status, 10); } catch (e) { status = 0; }
if (!status) { // ... handle error
$root.remove();
return false;
}
if ( data.status && data.status==1 ) {
$(".appointments-login_inner").text(l10nAppApi.logged_in);
window.location.href = window.location.href;
window.location.reload();
}
else {
alert(l10nAppApi.error);
}
});
}
}, {scope: 'email'});
return false;
};
} else if ($lnk.is(".appointments-login_link-twitter")) {
if (!l10nAppApi._can_use_twitter) {
$lnk.parents('li').hide();
return true;
}
callback = function () {
var twLogin = window.open('', "twitter_login", "scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600");
twLogin.document.write(l10nAppApi.please_wait || "Please hold on...");
$.post(_appointments_data.ajax_url, {
"action": "app_get_twitter_auth_url",
"url": window.location.toString()
}, function (data) {
var href = data.url,
cback = function () {
$(twLogin).off("unload", cback);
var tTimer = setInterval(function () {
try {
if (twLogin.location.hostname == window.location.hostname) {
clearInterval(tTimer);
twLogin.close();
// We're back!
var location = twLogin.location;
var search = '';
try { search = location.search; } catch (e) { search = ''; }
clearInterval(tTimer);
twLogin.close();
// change UI
$root.html('
' + (l10nAppApi.please_wait || "Please hold on..."));
$.post(_appointments_data.ajax_url, {
"action": "app_twitter_login",
"secret": data.secret,
"data": search
}, function (data) {
var status = 0;
try { status = parseInt(data.status, 10); } catch (e) { status = 0; }
if (!status) { // ... handle error
$root.remove();
return false;
}
if ( data.status && data.status==1 ) {
$(".appointments-login_inner").text(l10nAppApi.logged_in);
window.location.href = window.location.href;
window.location.reload();
}
else {
alert(l10nAppApi.error);
}
});
}
} catch (e) {}
}, 300);
}
;
$(twLogin).on("unload", cback);
twLogin.location = href;
});
return false;
};
}
else if ($lnk.is(".appointments-login_link-google")) {
callback = function () {
var googleLogin = window.open('https://www.google.com/accounts', "google_login", "scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=800");
$.post(_appointments_data.ajax_url, {
"action": "app_get_google_auth_url",
"url": window.location.href
}, function (data) {
var href = data.url;
googleLogin.location = href;
var gTimer = setInterval(function () {
try {
if (googleLogin.location.hostname == window.location.hostname) {
// We're back!
clearInterval(gTimer);
googleLogin.close();
// change UI
$root.html('
' + l10nAppApi.please_wait);
$.post(_appointments_data.ajax_url, {
"action": "app_google_login"
}, function (data) {
var status = 0;
try { status = parseInt(data.status, 10); } catch (e) { status = 0; }
if (!status) { // ... handle error
$root.remove();
$me.click();
return false;
}
if ( data.status && data.status==1 ) {
$(".appointments-login_inner").text(l10nAppApi.logged_in);
window.location.href = window.location.href;
window.location.reload();
}
else {
alert(l10nAppApi.error);
}
});
}
} catch (e) {}
}, 300);
});
return false;
};
}
else if ($lnk.is(".appointments-login_link-wordpress")) {
// Pass on to wordpress login
callback = function () {
//window.location = $me.parents(".appointments_login").find(".app_login_hidden").attr("href");
$(".app_login_submit").show();
return false;
};
} else if ($lnk.is(".appointments-login_link-submit")) {
callback = function () {
$(".app_error").remove();
$lnk.after('
' + l10nAppApi.please_wait +'