Created
November 14, 2012 21:17
-
-
Save jicksta/4074897 to your computer and use it in GitHub Desktop.
My way of initializing JavaScript unobtrusively
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
%html{:lang => "en"} | |
%head= render "shared/head" | |
%body.app{"data-events" => yield(:body_events)} | |
= yield |
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
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 |
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
App.bind "signup", -> | |
modal = document.getElementById "signup-modal" | |
new App.Views.SignupView(el: modal).render() |
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
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 |
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
- 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