Social Login Javascript API Complete Code
(Difference between revisions)
Renato.neves (Talk | contribs) |
Renato.neves (Talk | contribs) |
||
Line 1: | Line 1: | ||
<script> | <script> | ||
− | |||
//<![CDATA[ | //<![CDATA[ | ||
+ | |||
+ | // load the Social-ID Javascript API | ||
(function(){ | (function(){ | ||
if (typeof(window.socialid) !== "object") window.socialid = {}; | if (typeof(window.socialid) !== "object") window.socialid = {}; | ||
Line 21: | Line 22: | ||
})(); | })(); | ||
+ | // render the login widget | ||
function showLoginWidget() { | function showLoginWidget() { | ||
socialid.login.init(1, {loginType: "event"}); | socialid.login.init(1, {loginType: "event"}); | ||
Line 60: | Line 62: | ||
}); | }); | ||
} | } | ||
− | |||
+ | //]]> | ||
</script> | </script> |
Revision as of 21:40, 11 March 2013
<script> //<![CDATA[
// load the Social-ID Javascript API (function(){ if (typeof(window.socialid) !== "object") window.socialid = {}; socialid.onLoad = function() { showLoginWidget(); customLoginButtons(); eventHandlers(); }; var e = document.createElement('script'); e.type = 'text/javascript'; e.id = 'socialid_api_script'; if (document.location.protocol === 'https:') { e.src = 'https://socialid.local:3000/assets/api/socialid.js'; } else { e.src = 'http://socialid.local:3000/assets/api/socialid.js'; } var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(e, s); })();
// render the login widget function showLoginWidget() { socialid.login.init(1, {loginType: "event"}); socialid.login.renderLoginWidget("socialid_login_container", { theme: "bricks", providers: ["facebook", "twitter", "linkedin"], language: "pt_br", showSocialIdLink: true, loadCss: true, }); }
// start login for custom buttons function customLoginButtons() { // start login process when user clicks on facebook button facebook_button = document.getElementById("facebook_login"); facebook_button.onclick = function() { socialid.login.startLogin("facebook"); }; // start login process when user clicks on twitter and linkedin button socialid.login.startLoginClick("twitter_login", "twitter"); socialid.login.startLoginClick("linkedin_login", "linkedin"); }
// add event handlers function eventHandlers() { // for onLogin socialid.events.onLoginSuccess.addHandler(function(data) { console.log("Website received onLoginSuccess: ", data); }); socialid.events.onLoginCancel.addHandler(function(data) { console.log("Website received onLoginCancel: ", data); }); socialid.events.onLoginError.addHandler(function(data) { console.log("Website received onLoginError: ", data); }); socialid.events.onLoginStart.addHandler(function(data) { console.log("Website received onLoginStart: ", data); }); }
//]]> </script>