Created
February 6, 2012 03:22
-
-
Save pehrlich/1749334 to your computer and use it in GitHub Desktop.
Spine.js get active controller from stack
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
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 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
# 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