Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed duplication

  • Loading branch information...
commit 39ec7ce6a93945bc97f599d8cb503711a66f3952 1 parent 8e172f1
@foobarfighter foobarfighter authored stefanpenner committed
View
16 actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -49,16 +49,16 @@ def button_to_remote(name, options = {}, html_options = {})
end
def periodically_call_remote(options = {})
-# frequency = options[:frequency] || 10 # every ten seconds by default
-# code = "new PeriodicalExecuter(function() {#{remote_function(options)}}, #{frequency})"
-# javascript_tag(code)
+ attributes = extract_observer_attributes!(options)
+ attributes["data-js-type"] = "periodical_executer"
+
+ script_decorator(attributes)
end
+ #TODO: Should name change to a css query? - BR
def observe_field(name, options = {})
options[:observed] = name
-
- attributes = extract_remote_attributes!(options)
- attributes.merge!(extract_observer_attributes!(options))
+ attributes = extract_observer_attributes!(options)
attributes["data-js-type"] = "field_observer"
script_decorator(attributes)
@@ -139,7 +139,7 @@ def extract_update_attributes!(options)
end
def extract_observer_attributes!(options)
- attributes = {}
+ attributes = extract_remote_attributes!(options)
attributes["data-observed"] = options.delete(:observed)
callback = options.delete(:function)
@@ -151,7 +151,7 @@ def extract_observer_attributes!(options)
attributes["data-frequency"] = frequency.to_i
end
- attributes
+ purge_unused_attributes!(attributes)
end
def purge_unused_attributes!(attributes)
View
12 actionpack/test/javascript/ajax_test.rb
@@ -423,3 +423,15 @@ def field(options = {})
%w(script data-observer-code="function(element, value) {alert('Element changed')}")
end
end
+
+class PeriodicallyCallRemoteTest < AjaxTestCase
+ test "basic" do
+ assert_html periodically_call_remote(:update => "#schremser_bier", :url => { :action => "mehr_bier" }),
+ %w(script data-url="/url/hash" data-update-success="#schremser_bier")
+ end
+
+ test "periodically call remote with :frequency" do
+ assert_html periodically_call_remote(:frequency => 2, :url => "/url/string"),
+ %w(script data-url="/url/string" data-frequency="2")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.