diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-17 09:15:41 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-17 09:15:41 +0000 |
commit | 4dc2dc1402a41cd2c2210f5fb4418e905d42d75b (patch) | |
tree | 4ec406ef9e774b0b385526d586adf390ac413381 /actionpack | |
parent | 03d91590258e7cc6e27a8b0c1dc21ff93b70884a (diff) | |
download | rails-4dc2dc1402a41cd2c2210f5fb4418e905d42d75b.tar.gz rails-4dc2dc1402a41cd2c2210f5fb4418e905d42d75b.tar.bz2 rails-4dc2dc1402a41cd2c2210f5fb4418e905d42d75b.zip |
Cleaning up of javascript_helper array options, add :only to sortable_element #1761 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1843 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 43bedbd366..5f450e9e8f 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -363,11 +363,7 @@ module ActionView function << "'#{url_for(options[:url])}'" js_options = {} - if options[:tokens] and options[:tokens].kind_of?(Array) - js_options[:tokens] = "['#{options[:tokens].join('\',\'')}']" - elsif options[:tokens] - js_options[:tokens] = "'#{options[:tokens]}'" if options[:tokens] - end + js_options[:tokens] = array_or_string_for_javascript(options[:tokens]) if options[:tokens] js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with] js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator] function << (', ' + options_for_javascript(js_options) + ')') @@ -453,11 +449,8 @@ module ActionView options[option] = "'#{options[option]}'" if options[option] end - if options[:containment] and options[:containment].kind_of?(Array) - options[:containment] = "['#{options[:containment].join('\',\'')}']" - elsif options[:containment] - options[:containment] = "'#{options[:containment]}'" if options[:containment] - end + options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment] + options[:only] = array_or_string_for_javascript(options[:only]) if options[:only] javascript_tag("Sortable.create('#{element_id}', #{options_for_javascript(options)})") end @@ -488,12 +481,7 @@ module ActionView options[:onDrop] ||= "function(element){" + remote_function(options) + "}" options.delete_if { |key, value| AJAX_OPTIONS.include?(key) } - if options[:accept] and options[:accept].kind_of?(Array) - options[:accept] = "['#{options[:accept].join('\',\'')}']" - elsif options[:accept] - options[:accept] = "'#{options[:accept]}'" if options[:accept] - end - + options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept] options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass] javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})") @@ -515,6 +503,15 @@ module ActionView '{' + options.map {|k, v| "#{k}:#{v}"}.sort.join(', ') + '}' end + def array_or_string_for_javascript(option) + js_option = if option.kind_of?(Array) + "['#{option.join('\',\'')}']" + elsif !option.nil? + "'#{option}'" + end + js_option + end + def options_for_ajax(options) js_options = build_callbacks(options) |