Created
May 16, 2012 15:59
-
-
Save mikermcneil/2711613 to your computer and use it in GitHub Desktop.
Asynchronous Unwired Bridge callbacks
This file contains 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
// 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