Skip to content

Commit

Permalink
Reorg options_for_javascript and array_or_string_for_javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jan 30, 2010
1 parent 570e02c commit 657d855
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions actionpack/lib/action_view/helpers/javascript_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,6 @@ def javascript_tag(content_or_options_with_block = nil, html_options = {}, &bloc
def javascript_cdata_section(content) #:nodoc:
"\n//#{cdata_section("\n#{content}\n//")}\n"
end

protected
def options_for_javascript(options)
if options.empty?
'{}'
else
"{#{options.keys.map { |k| "#{k}:#{options[k]}" }.sort.join(', ')}}"
end
end

def array_or_string_for_javascript(option)
if option.kind_of?(Array)
"['#{option.join('\',\'')}']"
elsif !option.nil?
"'#{option}'"
end
end
end
end
end
8 changes: 8 additions & 0 deletions actionpack/lib/action_view/helpers/prototype_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@ def update_page_tag(html_options = {}, &block)
end

protected
def options_for_javascript(options)
if options.empty?
'{}'
else
"{#{options.keys.map { |k| "#{k}:#{options[k]}" }.sort.join(', ')}}"
end
end

def options_for_ajax(options)
js_options = build_callbacks(options)

Expand Down
9 changes: 9 additions & 0 deletions actionpack/lib/action_view/helpers/scriptaculous_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ def drop_receiving_element_js(element_id, options = {}) #:nodoc:

%(Droppables.add(#{ActiveSupport::JSON.encode(element_id)}, #{options_for_javascript(options)});)
end

protected
def array_or_string_for_javascript(option)
if option.kind_of?(Array)
"['#{option.join('\',\'')}']"
elsif !option.nil?
"'#{option}'"
end
end
end

module PrototypeHelper
Expand Down

0 comments on commit 657d855

Please sign in to comment.