Skip to content

Instantly share code, notes, and snippets.

@pehrlich
Created February 6, 2012 03:22
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 pehrlich/1749334 to your computer and use it in GitHub Desktop.
Save pehrlich/1749334 to your computer and use it in GitHub Desktop.
Spine.js get active controller from stack
Spine.Stack.include
active_controller: ()->
@manager.active_controller
window.app = new App
app.manager.bind 'change', (controller)->
console.log 'stack change', this, arguments
@active_controller = controller
# this is how/why the above is being used:
class window.App extends Spine.Stack
el: '#content'
# controllers:
# ...
events:
# by specifying tagnames and events, we allow html5 form validation
"click a[data-action]": 'auto_action'
"submit form[data-action]": "auto_action"
# the active controller is passed the action, context is maintained
auto_action: (event)->
console.log 'auto action', arguments, this, event
event.preventDefault();
ajax_status('done')
action = $(event.currentTarget || event.target).data('action')
@active_controller()[action]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment