Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3876: javascript_element_proxy.3597.diff

File javascript_element_proxy.3597.diff, 1.6 kB (added by rick, 3 years ago)
  • activesupport/lib/active_support/json.rb

    old new  
    33module ActiveSupport 
    44  module JSON #:nodoc: 
    55    class CircularReferenceError < StandardError; end 
    6        
     6    # returns the literal string as its JSON encoded form.  Useful for passing javascript variables into functions. 
     7    # 
     8    # page.call 'Element.show', ActiveSupport::JSON::Variable.new("$$(#items li)") 
     9    class Variable < String 
     10      def to_json 
     11        self 
     12      end 
     13    end 
     14 
    715    class << self 
    816      REFERENCE_STACK_VARIABLE = :json_reference_stack 
    917       
  • actionpack/lib/action_view/helpers/prototype_helper.rb

    old new  
    725725        super(generator, "$$('#{pattern}')") 
    726726      end 
    727727 
     728      # Calls the each enumorable method on the array returned from the #select call. 
     729      # 
     730      # page.select('#versions li.selected').each do |page, element| 
     731      #   page.call 'Element.removeClassName', element, 'selected' 
     732      # end 
     733      #  
     734      def each 
     735        @generator << '.each(function(element) {' 
     736        yield @generator, ActiveSupport::JSON::Variable.new('element') if block_given? 
     737        @generator << '});' 
     738      end 
     739 
    728740      # TODO: Implement funky stuff like .each 
    729741    end 
    730742  end