defer persona init till after people launch the login dialog

This commit is contained in:
Sam 2013-08-26 17:51:41 +10:00
parent d0b4c751b7
commit ac905d4a08
3 changed files with 31 additions and 30 deletions

View File

@ -16,6 +16,31 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
this.set('controller.lastY', e.screenY);
},
initPersona: function(){
var readyCalled = false;
navigator.id.watch({
onlogin: function(assertion) {
if (readyCalled) {
Discourse.ajax('/auth/persona/callback', {
type: 'POST',
data: { 'assertion': assertion },
dataType: 'json'
}).then(function(data) {
Discourse.authenticationComplete(data);
});
}
},
onlogout: function() {
if (readyCalled) {
Discourse.logout();
}
},
onready: function() {
readyCalled = true;
}
});
},
didInsertElement: function(e) {
this._super();
@ -35,6 +60,12 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
}
});
});
var view = this;
// load persona if needed
if(Discourse.SiteSettings.enable_persona_logins) {
$LAB.script("https://login.persona.org/include.js").wait(view.initPersona);
}
}
});

View File

@ -1,29 +0,0 @@
<!-- TODO, move this into login UI, don't deliver with page -->
<script>
$LAB.script("https://login.persona.org/include.js").wait(function(){
(function() {
var readyCalled = false;
navigator.id.watch({
onlogin: function(assertion) {
if (readyCalled) {
Discourse.ajax('/auth/persona/callback', {
type: 'POST',
data: { 'assertion': assertion },
dataType: 'json'
}).then(function(data) {
Discourse.authenticationComplete(data);
});
}
},
onlogout: function() {
if (readyCalled) {
Discourse.logout();
}
},
onready: function() {
readyCalled = true;
}
});
}());
});
</script>

View File

@ -69,7 +69,6 @@
<footer id='bottom'></footer>
<%= render :partial => "common/discourse_javascript" %>
<%= render :partial => "common/persona_javascript" if !current_user && SiteSetting.enable_persona_logins %>
<%= render_google_analytics_code %>
<!-- Discourse Version: <%= Discourse::VERSION::STRING %> -->