Skip to content

Instantly share code, notes, and snippets.

@richard-flosi
Created April 9, 2014 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard-flosi/10297918 to your computer and use it in GitHub Desktop.
Save richard-flosi/10297918 to your computer and use it in GitHub Desktop.
Spine App example with navigation method
module.exports = (function() {
var App,
Spine = require('spine'),
$ = Spine.$;
// extend Spine
require('spine/lib/local');
require('spine/lib/ajax');
require('spine/lib/route');
require('spine/lib/manager');
// set ajax prefix
Spine.Model.host = '/api';
App = Spine.Controller.sub({
init: function() {
var Routes = require('routes'); // a sibling routes.js file that extends Spine.Stack to define controller routes
this.routes = new Routes({
el: $('#app')
});
Spine.Route.setup({
history: true
});
},
events: {
'click a': 'navigate'
},
navigate: function(e) {
if (e.currentTarget.target || // target is set to _self or _blank
e.metaKey) { // command key is press to open in new tab/window
return $.noop();
} else {
e.preventDefault();
if (e.currentTarget.pathname.charAt(0) === '/') {
return Spine.Route.navigate(e.currentTarget.pathname);
} else {
// IE 9
return Spine.Route.navigate('/' + e.currentTarget.pathname);
}
}
}
});
return App;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment