lib/jelly/jelly_helper.rb in pivotal-jelly-0.3.5 vs lib/jelly/jelly_helper.rb in pivotal-jelly-0.4.0

- old
+ new

@@ -9,10 +9,13 @@ def spread_jelly javascript_tag <<-JS window._token = '#{form_authenticity_token}' Jelly.activatePage('#{controller.controller_path.camelcase}', '#{controller.action_name}'); #{@content_for_javascript} + $(document).ready(function() { + #{@content_for_javascript_on_ready} + }); JS end def clear_jelly_attached() @jelly_attached_components = [] @@ -22,9 +25,18 @@ @jelly_attached_components ||= [] key = "page.attach(#{component_name}, #{args.to_json});" unless @jelly_attached_components.include? key @jelly_attached_components << key content_for(:javascript, key) + end + end + + def attach_javascript_component_on_ready(component_name, *args) + @jelly_attached_components_on_ready ||= [] + key = "page.attach(#{component_name}, #{args.to_json});" + unless @jelly_attached_components_on_ready.include? key + @jelly_attached_components_on_ready << key + content_for(:javascript_on_ready, key) end end end \ No newline at end of file