Lazy load Google and Persona login stuff

This commit is contained in:
Eelco Dolstra 2016-04-28 17:13:02 +02:00
parent 0c4e8b13a1
commit b829be29b6
3 changed files with 48 additions and 34 deletions

View file

@ -1,5 +1,13 @@
[% IF c.user_exists %]
[% IF c.user.type == 'google' %]
<script src="https://apis.google.com/js/platform.js" async="1" defer="1"></script>
[% END %]
[% IF c.user.type == 'persona' %]
<script src="https://login.persona.org/include.js"></script>
[% END %]
<script>
function finishSignOut() {
$.post("[% c.uri_for('/logout') %]")
@ -65,6 +73,15 @@
return false;
});
$("#sign-in-menu").on("click", function() {
[% IF c.config.enable_google_login %]
$.getScript("https://apis.google.com/js/platform.js");
[% END %]
[% IF c.config.enable_persona %]
$.getScript("https://login.persona.org/include.js");
[% END %]
});
</script>
[% IF c.config.enable_google_login %]
@ -80,15 +97,17 @@
});
return false;
};
$("#google-signin").click(function() {
$(".g-signin2:first-child > div").click();
});
</script>
[% END %]
[% END %]
[% IF c.config.enable_persona %]
<script src="https://login.persona.org/include.js"></script>
<script>
$("#persona-signin").click(function() {
navigator.id.watch({
onlogin: function(assertion) {
requestJSON({
@ -101,8 +120,9 @@
}
});
$("#persona-signin").click(function() {
navigator.id.request({ siteName: 'Hydra' });
});
</script>
[% END %]
[% END %]

View file

@ -43,7 +43,6 @@
[% IF c.config.enable_google_login %]
<meta name="google-signin-client_id" content="[% c.config.google_client_id %]">
<script src="https://apis.google.com/js/platform.js" async="1" defer="1"></script>
[% END %]
[% tracker %]

View file

@ -1,5 +1,5 @@
[% BLOCK makeSubMenu %]
<li class="dropdown">
<li class="dropdown" [% IF id; HTML.attributes(id => id); END %] >
<a class="dropdown-toggle" href="#" data-toggle="dropdown">[% title %]<b class="caret"></b></a>
<ul class="dropdown-menu">
[% content %]
@ -130,19 +130,14 @@
<a href="#" onclick="signOut();">Sign out</a>
</li>
[% ELSE %]
[% WRAPPER makeSubMenu title="Sign in" %]
[% WRAPPER makeSubMenu title="Sign in" id="sign-in-menu" %]
[% IF c.config.enable_google_login %]
<li>
<a><div class="g-signin2" data-onsuccess="onGoogleSignIn" data-theme="dark"></div></a>
</li>
<div style="display: none" class="g-signin2" data-onsuccess="onGoogleSignIn" data-theme="dark"></div></a>
<li><a href="#" id="google-signin">Sign in with Google</a></li>
<li class="divider"></li>
[% END %]
[% IF c.config.enable_persona %]
<li>
<a href="#" id="persona-signin">
<img src="[% c.uri_for("/static/images/persona_sign_in_blue.png") %]" alt="Sign in with Persona" />
</a>
</li>
<li><a href="#" id="persona-signin">Sign in with Persona</a></li>
<li class="divider"></li>
[% END %]
<li>