Created
April 9, 2014 18:02
-
-
Save richard-flosi/10297918 to your computer and use it in GitHub Desktop.
Spine App example with navigation method
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
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