Class: DeRjs::JavaScriptElementProxy

Inherits:
JavaScriptProxy show all
Defined in:
lib/de_rjs/jquery_generator.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.



627
628
629
630
631
632
633
634
635
636
# File 'lib/de_rjs/jquery_generator.rb', line 627

def initialize(generator, id)
  id = id.sub(/<%=.*%>/,'').to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
  #id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
  @id = id
  if id =~ /\A#?<%=.*%>\z/  # if completely using erb
    super(generator, "#{::JQUERY_VAR}(\"#{id}\");")  # USER BEWARE !
  else
    super(generator, "#{::JQUERY_VAR}(#{::ActiveSupport::JSON.encode(id)});")
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DeRjs::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';


644
645
646
647
# File 'lib/de_rjs/jquery_generator.rb', line 644

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

#[]=(variable, value) ⇒ Object



649
650
651
# File 'lib/de_rjs/jquery_generator.rb', line 649

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

#add_class_name(class_name) ⇒ Object



665
666
667
# File 'lib/de_rjs/jquery_generator.rb', line 665

def add_class_name(class_name)
  call 'addClass', class_name
end

#reload(options_for_replace = {}) ⇒ Object



669
670
671
# File 'lib/de_rjs/jquery_generator.rb', line 669

def reload(options_for_replace = {})
  replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
end

#replace(*options_for_render) ⇒ Object



657
658
659
# File 'lib/de_rjs/jquery_generator.rb', line 657

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

#replace_html(*options_for_render) ⇒ Object



653
654
655
# File 'lib/de_rjs/jquery_generator.rb', line 653

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

#valueObject



673
674
675
# File 'lib/de_rjs/jquery_generator.rb', line 673

def value()
  call 'val()'
end

#value=(value) ⇒ Object



677
678
679
# File 'lib/de_rjs/jquery_generator.rb', line 677

def value=(value)
  call 'val', value
end

#visual_effect(name, options = {}) ⇒ Object



661
662
663
# File 'lib/de_rjs/jquery_generator.rb', line 661

def visual_effect(name, options = {})
  append_to_function_chain!(@generator.send(:jquery_ui_effect, name, options))
end