Last active
August 29, 2015 14:09
-
-
Save dux/7f54529a26ec4b05c0d2 to your computer and use it in GitHub Desktop.
Mozilla Persona flawless init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Persona = | |
loaded: false | |
button: null | |
init: (element) -> | |
$ -> | |
Persona.button = $(element) | |
return unless Persona.button[0] | |
unless Persona.button[0].persona_binded | |
Persona.button.on "click", -> Persona.click() | |
Persona.button[0].persona_binded = true | |
return if Persona.loaded | |
$.getScript "https://login.persona.org/include.js", (data, state) -> | |
if state is "success" | |
navigator.id.watch | |
onlogin: (assertion) -> | |
$.get("/login", { persona: assertion }).done (data) -> | |
navigator.id.logout() | |
# Pjax.refresh() if window.Pjax | |
location.href = '/' | |
return | |
onlogout: -> 1; | |
Persona.loaded = true | |
else | |
Info.alert "Error loading Persona login library, try again" | |
click: -> | |
unless Persona.loaded | |
setTimeout -> | |
Persona.click() | |
, 200 | |
return | |
navigator.id.request() | |
# onmouseover="Persona.init(this);" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment