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_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> <script>
function finishSignOut() { function finishSignOut() {
$.post("[% c.uri_for('/logout') %]") $.post("[% c.uri_for('/logout') %]")
@ -65,6 +73,15 @@
return false; 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> </script>
[% IF c.config.enable_google_login %] [% IF c.config.enable_google_login %]
@ -80,15 +97,17 @@
}); });
return false; return false;
}; };
$("#google-signin").click(function() {
$(".g-signin2:first-child > div").click();
});
</script> </script>
[% END %] [% END %]
[% END %]
[% IF c.config.enable_persona %] [% IF c.config.enable_persona %]
<script src="https://login.persona.org/include.js"></script>
<script> <script>
$("#persona-signin").click(function() {
navigator.id.watch({ navigator.id.watch({
onlogin: function(assertion) { onlogin: function(assertion) {
requestJSON({ requestJSON({
@ -101,8 +120,9 @@
} }
}); });
$("#persona-signin").click(function() {
navigator.id.request({ siteName: 'Hydra' }); navigator.id.request({ siteName: 'Hydra' });
}); });
</script> </script>
[% END %] [% END %]
[% END %]

View file

@ -43,7 +43,6 @@
[% IF c.config.enable_google_login %] [% IF c.config.enable_google_login %]
<meta name="google-signin-client_id" content="[% c.config.google_client_id %]"> <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 %] [% END %]
[% tracker %] [% tracker %]

View file

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