Class: ActionView::Helpers::JavaScriptElementProxy

Inherits:
JavaScriptProxy
  • Object
show all
Defined in:
lib/action_view/helpers/prototype_helper.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from JavaScriptProxy

#is_a?

Constructor Details

#initialize(generator, id) ⇒ JavaScriptElementProxy

Returns a new instance of JavaScriptElementProxy.



710
711
712
713
# File 'lib/action_view/helpers/prototype_helper.rb', line 710

def initialize(generator, id)
  @id = id
  super(generator, "$(#{::ActiveSupport::JSON.encode(id)})")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActionView::Helpers::JavaScriptProxy

Instance Method Details

#[](attribute) ⇒ Object

Allows access of element attributes through attribute. Examples:

page['foo']['style']                  # => $('foo').style;
page['foo']['style']['color']         # => $('blank_slate').style.color;
page['foo']['style']['color'] = 'red' # => $('blank_slate').style.color = 'red';
page['foo']['style'].color = 'red'    # => $('blank_slate').style.color = 'red';


721
722
723
724
# File 'lib/action_view/helpers/prototype_helper.rb', line 721

def [](attribute)
  append_to_function_chain!(attribute)
  self
end

#[]=(variable, value) ⇒ Object



726
727
728
# File 'lib/action_view/helpers/prototype_helper.rb', line 726

def []=(variable, value)
  assign(variable, value)
end

#reload(options_for_replace = {}) ⇒ Object



738
739
740
# File 'lib/action_view/helpers/prototype_helper.rb', line 738

def reload(options_for_replace = {})
  replace(options_for_replace.merge({ :partial => @id.to_s }))
end

#replace(*options_for_render) ⇒ Object



734
735
736
# File 'lib/action_view/helpers/prototype_helper.rb', line 734

def replace(*options_for_render)
  call 'replace', @generator.send(:render, *options_for_render)
end

#replace_html(*options_for_render) ⇒ Object



730
731
732
# File 'lib/action_view/helpers/prototype_helper.rb', line 730

def replace_html(*options_for_render)
  call 'update', @generator.send(:render, *options_for_render)
end