diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-05 06:42:58 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-05 06:42:58 +0000 |
commit | 16b9409a9c087d26e415de9fe66b8a754d76e7f0 (patch) | |
tree | e597e18fd2a5518ed717749077c216a748945787 /actionpack/lib/action_view | |
parent | 5afbffdd95c738f33f41efc0a42af1b73ad4dfe4 (diff) | |
download | rails-16b9409a9c087d26e415de9fe66b8a754d76e7f0.tar.gz rails-16b9409a9c087d26e415de9fe66b8a754d76e7f0.tar.bz2 rails-16b9409a9c087d26e415de9fe66b8a754d76e7f0.zip |
allow RJS enum values to be passed to visual_effect() and other scriptaculous helpers #4080 [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/scriptaculous_helper.rb | 10 |
2 files changed, 11 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index db36f3de5f..9a58f41821 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -409,7 +409,8 @@ module ActionView class JavaScriptGenerator def initialize(context, &block) #:nodoc: @context, @lines = context, [] - include_helpers_from_context + # removed because those methods were overriding valid generator methods + # include_helpers_from_context @context.instance_exec(self, &block) end @@ -567,7 +568,7 @@ module ActionView # Starts a script.aculo.us visual effect. See # ActionView::Helpers::ScriptaculousHelper for more information. - def visual_effect(name, id, options = {}) + def visual_effect(name, id = nil, options = {}) record @context.send(:visual_effect, name, id, options) end @@ -791,7 +792,7 @@ module ActionView append_enumerable_function!("zip(#{arguments.collect { |a| a.to_json } * ', '}") if block function_chain[-1] += ", function(array) {" - yield @generator, ActiveSupport::JSON::Variable.new('array') + yield ActiveSupport::JSON::Variable.new('array') add_return_statement! @generator << '});' else @@ -811,7 +812,8 @@ module ActionView def enumerable_method(enumerable, variable, yield_params, &block) add_variable_assignment!(variable) if variable append_enumerable_function!(enumerable) - yield *([@generator] + yield_params.collect { |p| JavaScriptVariableProxy.new(@generator, p) }) + # only yield as many params as were passed in the block + yield *yield_params.collect { |p| JavaScriptVariableProxy.new(@generator, p) }[0..block.arity-1] add_return_statement! if variable @generator << '});' end diff --git a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb b/actionpack/lib/action_view/helpers/scriptaculous_helper.rb index bd88b3ec0a..263be5d032 100644 --- a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb +++ b/actionpack/lib/action_view/helpers/scriptaculous_helper.rb @@ -42,7 +42,7 @@ module ActionView # You can change the behaviour with various options, see # http://script.aculo.us for more documentation. def visual_effect(name, element_id = false, js_options = {}) - element = element_id ? "'#{element_id}'" : "element" + element = element_id ? element_id.to_json : "element" js_options[:queue] = if js_options[:queue].is_a?(Hash) '{' + js_options[:queue].map {|k, v| k == :limit ? "#{k}:#{v}" : "#{k}:'#{v}'" }.join(',') + '}' @@ -76,7 +76,7 @@ module ActionView end def sortable_element_js(element_id, options = {}) #:nodoc: - options[:with] ||= "Sortable.serialize('#{element_id}')" + options[:with] ||= "Sortable.serialize(#{element_id.to_json})" options[:onUpdate] ||= "function(){" + remote_function(options) + "}" options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) } @@ -87,7 +87,7 @@ module ActionView options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment] options[:only] = array_or_string_for_javascript(options[:only]) if options[:only] - %(Sortable.create('#{element_id}', #{options_for_javascript(options)});) + %(Sortable.create(#{element_id.to_json}, #{options_for_javascript(options)});) end # Makes the element with the DOM ID specified by +element_id+ draggable. @@ -102,7 +102,7 @@ module ActionView end def draggable_element_js(element_id, options = {}) #:nodoc: - %(new Draggable('#{element_id}', #{options_for_javascript(options)});) + %(new Draggable(#{element_id.to_json}, #{options_for_javascript(options)});) end # Makes the element with the DOM ID specified by +element_id+ receive @@ -128,7 +128,7 @@ module ActionView options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept] options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] - %(Droppables.add('#{element_id}', #{options_for_javascript(options)});) + %(Droppables.add(#{element_id.to_json}, #{options_for_javascript(options)});) end end end |