Module: Viewaide::Helpers::JqueryHelper

Included in:
Viewaide::Helpers
Defined in:
lib/viewaide/helpers/jquery_helper.rb

Instance Method Summary collapse

Instance Method Details

#document_ready(&block) ⇒ String

generates a script tag with the appropriate type, an anonymous function (assigning jQuery to $), and within a #ready callback

Examples:

<% document_ready do %>
  $("a[rel=external]").live(function() {
    $(this).attr({target: "_blank"});
  });
<% end %>
generates
<script type="text/javascript">
  (function($) {
    $(document).ready(function() {
      $("a[rel=external]").live(function() {
        $(this).attr({target: "_blank"});
      });
    });
  })(jQuery);
</script>

Parameters:

  • &block (block)

    the block of text to wrap

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/viewaide/helpers/jquery_helper.rb', line 26

def document_ready(&block)
  html =  :script, :type => "text/javascript" do
    %(
      (function($) {
        $(document).ready(function() {
          #{capture(&block)}
        });
      })(jQuery);
    )
  end

  concat(html)
end