Skip to content

Commit cb9f7f4

Browse files
committed
Merge pull request rails#5923 from rafaelfranca/remove_javascript_helpers
Remove button_to_function and link_to_function helpers
2 parents 363d7ee + 3acdd65 commit cb9f7f4

File tree

4 files changed

+3
-65
lines changed

4 files changed

+3
-65
lines changed

actionpack/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Rails 4.0.0 (unreleased) ##
22

3+
* Remove `button_to_function` and `link_to_function` helpers. *Rafael Mendonça França*
4+
35
* Make current object and counter (when it applies) variables accessible when
46
rendering templates with :object / :collection. *Carlos Antonio da Silva*
57

actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'thread'
22
require 'active_support/core_ext/file'
3+
require 'active_support/core_ext/module/attribute_accessors'
34

45
module ActionView
56
module Helpers

actionpack/lib/action_view/helpers/javascript_helper.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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
10772
end

actionpack/test/template/javascript_helper_test.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,6 @@ def test_escape_javascript_with_safebuffer
4242
assert_instance_of ActiveSupport::SafeBuffer, escape_javascript(ActiveSupport::SafeBuffer.new(given))
4343
end
4444

45-
def test_button_to_function
46-
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
47-
button_to_function("Greeting", "alert('Hello world!')")
48-
end
49-
50-
def test_button_to_function_with_onclick
51-
assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
52-
button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
53-
end
54-
55-
def test_button_to_function_without_function
56-
assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />",
57-
button_to_function("Greeting")
58-
end
59-
60-
def test_link_to_function
61-
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
62-
link_to_function("Greeting", "alert('Hello world!')")
63-
end
64-
65-
def test_link_to_function_with_existing_onclick
66-
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
67-
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
68-
end
69-
70-
def test_function_with_href
71-
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
72-
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
73-
end
74-
7545
def test_javascript_tag
7646
self.output_buffer = 'foo'
7747

0 commit comments

Comments
 (0)