2007-02-10 00:12:31 +01:00
|
|
|
module ActionView
|
|
|
|
module Helpers
|
|
|
|
module PrototypeHelper
|
|
|
|
|
2007-10-15 19:16:54 +02:00
|
|
|
# Method to execute an element update using Prototype.
|
|
|
|
# DEPRECATION WARNING: This helper has been depercated; use RJS instead.
|
|
|
|
# See ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods for more information.
|
2007-02-10 00:12:31 +01:00
|
|
|
def update_element_function(element_id, options = {}, &block)
|
|
|
|
content = escape_javascript(options[:content] || '')
|
|
|
|
content = escape_javascript(capture(&block)) if block
|
|
|
|
|
|
|
|
javascript_function = case (options[:action] || :update)
|
|
|
|
when :update
|
|
|
|
if options[:position]
|
|
|
|
"new Insertion.#{options[:position].to_s.camelize}('#{element_id}','#{content}')"
|
|
|
|
else
|
|
|
|
"$('#{element_id}').innerHTML = '#{content}'"
|
|
|
|
end
|
|
|
|
|
|
|
|
when :empty
|
|
|
|
"$('#{element_id}').innerHTML = ''"
|
|
|
|
|
|
|
|
when :remove
|
|
|
|
"Element.remove('#{element_id}')"
|
|
|
|
|
|
|
|
else
|
|
|
|
raise ArgumentError, "Invalid action, choose one of :update, :remove, :empty"
|
|
|
|
end
|
|
|
|
|
|
|
|
javascript_function << ";\n"
|
|
|
|
options[:binding] ? concat(javascript_function, options[:binding]) : javascript_function
|
|
|
|
end
|
|
|
|
deprecate :update_element_function => "use RJS instead"
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|