Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created May 16, 2012 15:59
Show Gist options
  • Save mikermcneil/2711613 to your computer and use it in GitHub Desktop.
Save mikermcneil/2711613 to your computer and use it in GitHub Desktop.
Asynchronous Unwired Bridge callbacks
// This example uses backbone.js to capture the hash change event.
// Unrelated functionality is referenced but not shown.
// Where ever you call it from, Unwired.login should look like the following:
/*
Unwired.login(guid, {
url: document.location.href+"#loginComplete"
});
*/
// Extend and instantiate main router
var app;
var AppRouter = Backbone.Router.extend({
// Trigger this route before rendering views which require enabled messaging
index: function () {
$(function(){
if (User.isLoggedIn()) {
app.navigate('loggedinhome',{trigger:true});
}
else {
app.navigate('login',{trigger:true});
}
})
},
// Login view
login: function () {
$(function() {
app.renderFromEl("#uwn-mobile-login");
// Configure forms to be processed by built-in handler
$("form").live('submit', app.handleForm);
})
},
// Login finished successfully, redirect to logged-in homeview
loginComplete: function () {
User.set({'loggedIn':true});
app.navigate('loggedinhome',{trigger:true});
},
// Logged-in homeview
loggedinhome: function() {
// do stuff, user is now logged in
}
});
Backbone.app = new AppRouter();
// when document is ready
$(function(){
// Launch history manager
Backbone.history.start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment