Skip to content

Instantly share code, notes, and snippets.

@dux
Last active August 29, 2015 14:09
Show Gist options
  • Save dux/7f54529a26ec4b05c0d2 to your computer and use it in GitHub Desktop.
Save dux/7f54529a26ec4b05c0d2 to your computer and use it in GitHub Desktop.
Mozilla Persona flawless init
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