Created
February 18, 2012 12:35
-
-
Save datiecher/1859103 to your computer and use it in GitHub Desktop.
Simple Backbone Test Case
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
(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); |
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
(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