Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removing container inline js function of observed elements :function …

…callback
  • Loading branch information...
commit f661a3bc599ac336aeaf643a8d1d388fe905a07d 1 parent a6cd35b
@erikstmartin erikstmartin authored stefanpenner committed
View
6 actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -566,7 +566,7 @@ def extract_observer_attributes!(options)
attributes = extract_remote_attributes!(options)
attributes["data-observe"] = true
attributes["data-observed"] = options.delete(:observed)
- attributes["data-onobserve"] = create_js_function(callback, "element", "value") if callback
+ attributes["data-onobserve"] = callback if callback
attributes["data-frequency"] = frequency.to_i if frequency && frequency != 0
attributes.delete("data-remote")
@@ -577,10 +577,6 @@ def purge_unused_attributes!(attributes)
attributes.delete_if {|key, value| value.nil? }
attributes
end
-
- def create_js_function(statements, *arguments)
- "function(#{arguments.join(", ")}) {#{statements}}"
- end
end
# TODO: All evaled goes here per wycat
View
11 actionpack/test/template/ajax_helper_test.rb
@@ -171,6 +171,13 @@ def setup
)
end
+ test "periodically_call_remote_with_function" do
+ assert_dom_equal(
+ "<script data-periodical=\"true\" data-url=\"http://www.example.com/\" type=\"application/json\" data-onobserve=\"alert('test')\" data-frequency=\"2\"></script>",
+ periodically_call_remote(:frequency => 2, :function => "alert('test')")
+ )
+ end
+
test "form_remote_tag" do
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" data-remote=\"true\" data-update-success=\"glass_of_beer\">),
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
@@ -297,7 +304,7 @@ def setup
end
test "observe_field using function for callback" do
- assert_dom_equal %(<script data-observed=\"glass\" data-url=\"http://www.example.com/\" data-onobserve=\"function(element, value) {alert('Element changed')}\" data-observe=\"true\" type=\"application/json\" data-frequency=\"300\"></script>),
+ assert_dom_equal %(<script data-observed=\"glass\" data-url=\"http://www.example.com/\" data-observe=\"true\" type=\"application/json\" data-onobserve=\"alert('Element changed')\" data-frequency=\"300\"></script>),
observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')")
end
@@ -307,7 +314,7 @@ def setup
end
test "observe_form using function for callback" do
- assert_dom_equal %(<script data-observed=\"cart\" data-url=\"http://www.example.com/\" data-onobserve=\"function(element, value) {alert('Form changed')}\" data-observe=\"true\" type=\"application/json\" data-frequency=\"2\"></script>),
+ assert_dom_equal %(<script data-observed=\"cart\" data-url=\"http://www.example.com/\" data-observe=\"true\" type=\"application/json\" data-onobserve=\"alert('Form changed')\" data-frequency=\"2\"></script>),
observe_form("cart", :frequency => 2, :function => "alert('Form changed')")
end
Please sign in to comment.
Something went wrong with that request. Please try again.