Skip to content
This repository
Browse code

Merge pull request #5923 from rafaelfranca/remove_javascript_helpers

Remove button_to_function and link_to_function helpers
  • Loading branch information...
commit cb9f7f488a3be71ee4704a4e62f545ebd3f95310 2 parents 363d7ee + 3acdd65
Jeremy Kemper authored April 29, 2012
2  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,7 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   Remove `button_to_function` and `link_to_function` helpers. *Rafael Mendonça França*
  4
+
3 5
 *   Make current object and counter (when it applies) variables accessible when
4 6
     rendering templates with :object / :collection. *Carlos Antonio da Silva*
5 7
 
1  actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'thread'
2 2
 require 'active_support/core_ext/file'
  3
+require 'active_support/core_ext/module/attribute_accessors'
3 4
 
4 5
 module ActionView
5 6
   module Helpers
35  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -15,7 +15,6 @@ module JavaScriptHelper
15 15
 
16 16
       JS_ESCAPE_MAP["\342\200\250".force_encoding('UTF-8').encode!] = '
'
17 17
       JS_ESCAPE_MAP["\342\200\251".force_encoding('UTF-8').encode!] = '
'
18  
-      
19 18
 
20 19
       # Escapes carriage returns and single and double quotes for JavaScript segments.
21 20
       #
@@ -68,40 +67,6 @@ def javascript_tag(content_or_options_with_block = nil, html_options = {}, &bloc
68 67
       def javascript_cdata_section(content) #:nodoc:
69 68
         "\n//#{cdata_section("\n#{content}\n//")}\n".html_safe
70 69
       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
105 70
     end
106 71
   end
107 72
 end
30  actionpack/test/template/javascript_helper_test.rb
@@ -42,36 +42,6 @@ def test_escape_javascript_with_safebuffer
42 42
     assert_instance_of ActiveSupport::SafeBuffer, escape_javascript(ActiveSupport::SafeBuffer.new(given))
43 43
   end
44 44
 
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  
-
75 45
   def test_javascript_tag
76 46
     self.output_buffer = 'foo'
77 47
 

0 notes on commit cb9f7f4

Please sign in to comment.
Something went wrong with that request. Please try again.