Permalink
Browse files

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
  • Loading branch information...
1 parent 03d9159 commit 4dc2dc1402a41cd2c2210f5fb4418e905d42d75b @dhh dhh committed Jul 17, 2005
Showing with 13 additions and 16 deletions.
  1. +13 −16 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -363,11 +363,7 @@ def auto_complete_field(field_id, options = {})
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 @@ def sortable_element(element_id, options = {})
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 @@ def drop_receiving_element(element_id, options = {})
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 @@ def options_for_javascript(options)
'{' + 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)

0 comments on commit 4dc2dc1

Please sign in to comment.