@@ -15,7 +15,6 @@ module JavaScriptHelper
1515
1616 JS_ESCAPE_MAP [ "\342 \200 \250 " . force_encoding ( 'UTF-8' ) . encode! ] = '
'
1717 JS_ESCAPE_MAP [ "\342 \200 \251 " . force_encoding ( 'UTF-8' ) . encode! ] = '
'
18-
1918
2019 # Escapes carriage returns and single and double quotes for JavaScript segments.
2120 #
@@ -68,40 +67,6 @@ def javascript_tag(content_or_options_with_block = nil, html_options = {}, &bloc
6867 def javascript_cdata_section ( content ) #:nodoc:
6968 "\n //#{ cdata_section ( "\n #{ content } \n //" ) } \n " . html_safe
7069 end
71-
72- # Returns a button whose +onclick+ handler triggers the passed JavaScript.
73- #
74- # The helper receives a name, JavaScript code, and an optional hash of HTML options. The
75- # name is used as button label and the JavaScript code goes into its +onclick+ attribute.
76- # If +html_options+ has an <tt>:onclick</tt>, that one is put before +function+.
77- #
78- # button_to_function "Greeting", "alert('Hello world!')", :class => "ok"
79- # # => <input class="ok" onclick="alert('Hello world!');" type="button" value="Greeting" />
80- #
81- def button_to_function ( name , function = nil , html_options = { } )
82- onclick = "#{ "#{ html_options [ :onclick ] } ; " if html_options [ :onclick ] } #{ function } ;"
83-
84- tag ( :input , html_options . merge ( :type => 'button' , :value => name , :onclick => onclick ) )
85- end
86-
87- # Returns a link whose +onclick+ handler triggers the passed JavaScript.
88- #
89- # The helper receives a name, JavaScript code, and an optional hash of HTML options. The
90- # name is used as the link text and the JavaScript code goes into the +onclick+ attribute.
91- # If +html_options+ has an <tt>:onclick</tt>, that one is put before +function+. Once all
92- # the JavaScript is set, the helper appends "; return false;".
93- #
94- # The +href+ attribute of the tag is set to "#" unless +html_options+ has one.
95- #
96- # link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link"
97- # # => <a class="nav_link" href="#" onclick="alert('Hello world!'); return false;">Greeting</a>
98- #
99- def link_to_function ( name , function , html_options = { } )
100- onclick = "#{ "#{ html_options [ :onclick ] } ; " if html_options [ :onclick ] } #{ function } ; return false;"
101- href = html_options [ :href ] || '#'
102-
103- content_tag ( :a , name , html_options . merge ( :href => href , :onclick => onclick ) )
104- end
10570 end
10671 end
10772end
0 commit comments