Skip to content

Instantly share code, notes, and snippets.

@datiecher
Created February 18, 2012 12:35
Show Gist options
  • Save datiecher/1859103 to your computer and use it in GitHub Desktop.
Save datiecher/1859103 to your computer and use it in GitHub Desktop.
Simple Backbone Test Case
(function($){
window.app = {
init: function() {
app.router = new app.Router();
Backbone.history.loadUrl = function(fragmentOverride) {
var fragment = this.fragment = this.getFragment(fragmentOverride).replace(/^.+\.php\/?/, '');
console.log('Navigated URL: '+fragment);
var matched = _.any(this.handlers, function(handler) {
if (handler.route.test(fragment)) {
handler.callback(fragment);
return true;
}
});
return matched;
};
Backbone.history.start({ pushState: true });
}
};
app.Router = Backbone.Router.extend({
routes: {
'' : 'index'
},
index: function() { console.log('index fired') }
});
$(function(){
app.init();
});
})(jQuery, undefined);
(function($){
window.app = {
init: function() {
app.router = new app.Router();
Backbone.history.start({ pushState: true });
}
};
app.Router = Backbone.Router.extend({
routes: {
'' : 'index'
},
index: function() { console.log('index fired') }
});
$(function(){
app.init();
});
})(jQuery, undefined);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment