Sha256: 900d2695ed6eb8a8eb5a9bf7f0d8b467547f2fb76c532fe733f3f861bcb269c4

Contents?: true

Size: 1.09 KB

Versions: 36

Compression:

Stored size: 1.09 KB

Contents

require 'volt/page/bindings/base_binding'

# TODO: We need to figure out how we want to wrap JS events
class JSEvent
  attr_reader :js_event
  def initialize(js_event)
    @js_event = js_event
  end
  
  def key_code
    `this.js_event.keyCode`
  end

  def stop
    # puts "STOPPING"
    # `this.js_event.stopPropagation();`
    `this.js_event.preventDefault();`
  end
end


class EventBinding < BaseBinding
  attr_accessor :context, :binding_name
  def initialize(target, context, binding_name, event_name, call_proc)
    @target = target
    @context = context
    @binding_name = binding_name
    @event_name = event_name
    
    handler = Proc.new do |js_event|
      event = JSEvent.new(js_event)
      event.stop if event_name == 'submit'

      # Call the proc the user setup for the event in context,
      # pass in the wrapper for the JS event
      result = @context.instance_exec(event, &call_proc)
    end

    @listener = $page.events.add(event_name, self, handler)
  end

  # Remove the event binding
  def remove
    # puts "REMOVE EL FOR #{@event}"
    $page.events.remove(@event_name, self)
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
volt-0.5.18 lib/volt/page/bindings/event_binding.rb
volt-0.5.17 lib/volt/page/bindings/event_binding.rb
volt-0.5.16 lib/volt/page/bindings/event_binding.rb
volt-0.5.15 lib/volt/page/bindings/event_binding.rb
volt-0.5.14 lib/volt/page/bindings/event_binding.rb
volt-0.5.13 lib/volt/page/bindings/event_binding.rb
volt-0.5.12 lib/volt/page/bindings/event_binding.rb
volt-0.5.11 lib/volt/page/bindings/event_binding.rb
volt-0.5.10 lib/volt/page/bindings/event_binding.rb
volt-0.5.9 lib/volt/page/bindings/event_binding.rb
volt-0.5.8 lib/volt/page/bindings/event_binding.rb
volt-0.5.7 lib/volt/page/bindings/event_binding.rb
volt-0.5.6 lib/volt/page/bindings/event_binding.rb
volt-0.5.4 lib/volt/page/bindings/event_binding.rb
volt-0.5.3 lib/volt/page/bindings/event_binding.rb
volt-0.5.2 lib/volt/page/bindings/event_binding.rb
volt-0.5.1 lib/volt/page/bindings/event_binding.rb
volt-0.5.0 lib/volt/page/bindings/event_binding.rb
volt-0.4.18 lib/volt/page/bindings/event_binding.rb
volt-0.4.17 lib/volt/page/bindings/event_binding.rb