Skip to content

Instantly share code, notes, and snippets.

@jicksta
Created November 14, 2012 21:17
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 jicksta/4074897 to your computer and use it in GitHub Desktop.
Save jicksta/4074897 to your computer and use it in GitHub Desktop.
My way of initializing JavaScript unobtrusively
%html{:lang => "en"}
%head= render "shared/head"
%body.app{"data-events" => yield(:body_events)}
= yield
App = window.App = _.extend {Models: {}, Views: {}, Controllers: {}}, Backbone.Events
App.init = ->
eventNames = $("body").attr("data-events")
eventNames = if eventNames? then eventNames.split(/\s+/) else []
App.trigger event for event in eventNames
$ App.init
App.bind "signup", ->
modal = document.getElementById "signup-modal"
new App.Views.SignupView(el: modal).render()
def client_initializer(*event_names)
event_names = event_names.join(" ")
if content_for?(:body_events)
content_for(:body_events) << " " << event_names
else
content_for :body_events, event_names
end
nil
end
- client_initializer :signup
-# Rest of view goes here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment