module ActionView::Helpers::JavaScriptHelper

def button_to_function(name, *args, &block)

end
page[:details].visual_effect :toggle_slide
button_to_function "Details", :class => "details_button" do |page|
end
page[:details].visual_effect :toggle_slide
button_to_function "Details" do |page|
button_to_function "Delete", "if (confirm('Really?')) do_delete()"
button_to_function "Greeting", "alert('Hello world!')"
Examples:

Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil

The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button"

(instead of making an Ajax request first).
block, which evaluates to a string when the template is rendered
The +function+ argument can be omitted in favor of an +update_page+

The next arguments are optional and may include the javascript function definition and a hash of html_options.

The first argument +name+ is used as the button's value or display text.

onclick handler.
Returns a button with the given +name+ text that'll trigger a JavaScript +function+ using the
def button_to_function(name, *args, &block)
  html_options = args.extract_options!.symbolize_keys
  function = block_given? ? update_page(&block) : args[0] || ''
  onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"
  tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick))
end

def escape_javascript(javascript)

Escape carrier returns and single and double quotes for JavaScript segments.
def escape_javascript(javascript)
  if javascript
    result = javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) {|match| JS_ESCAPE_MAP[match] }
    javascript.html_safe? ? result.html_safe : result
  else
    ''
  end
end

def javascript_cdata_section(content) #:nodoc:

:nodoc:
def javascript_cdata_section(content) #:nodoc:
  "\n//#{cdata_section("\n#{content}\n//")}\n".html_safe
end

def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)

<% end -%>
alert('All is good')
<%= javascript_tag :defer => 'defer' do -%>
in which case, you pass your +html_options+ as the first parameter.
Instead of passing the content as an argument, you can also use a block

# =>
javascript_tag "alert('All is good')", :defer => 'defer'
Example:
+html_options+ may be a hash of attributes for the \
//]]>
alert('All is good')
//