Skip to content

Instantly share code, notes, and snippets.

@airhorns
Created January 10, 2012 19:13
Show Gist options
  • Save airhorns/1590577 to your computer and use it in GitHub Desktop.
Save airhorns/1590577 to your computer and use it in GitHub Desktop.
How to jqueryize nodes rendered by batman
# Option 1
class SomeController extends Batman.Controller
index: ->
# Do some stuff
view = @render()
view.on 'ready', ->
# The view's HTML is now in the DOM, ready for jQuerying.
# To make your jQuery selectors faster, you can use the second argument of `$` and
# pass in the view's node as the node to search for your selector within
$('a', view.get('node')).css(color: '#F00')
# Option 2
# Completely undocumentedly, Batman will search for a class with the same name as the controller action you are rendering to use instead of a default view.
# You can learn more about custom view classes here: https://github.com/Shopify/batman/wiki/Creating-Batman.Views
class YourApp.ArticlesController extends Batman.Controller
index: -> # Do stuff
new: -> # Do other stuff
class YourApp.ArticlesView
ready: ->
# This will be called when the view is finished rendering during the index action, so its a good time to do your jQueries
class YourApp.ArticlesNewView
ready: ->
# This will be called when the view is finished rendering during the new action, so its a good time to do your jQueries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment