Class: Volt::EventBinding

Inherits:
BaseBinding show all
Defined in:
lib/volt/page/bindings/event_binding.rb

Instance Attribute Summary collapse

Attributes inherited from BaseBinding

#target

Instance Method Summary collapse

Methods inherited from BaseBinding

#dom_section, #remove_anchors

Constructor Details

#initialize(page, target, context, binding_name, event_name, call_proc) ⇒ EventBinding

Returns a new instance of EventBinding.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/volt/page/bindings/event_binding.rb', line 32

def initialize(page, target, context, binding_name, event_name, call_proc)
  super(page, target, context, binding_name)
  @event_name = event_name

  handler = proc do |js_event|
    event = JSEvent.new(js_event)
    event.prevent_default! 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

Instance Attribute Details

#binding_nameObject

Returns the value of attribute binding_name.



30
31
32
# File 'lib/volt/page/bindings/event_binding.rb', line 30

def binding_name
  @binding_name
end

#contextObject

Returns the value of attribute context.



30
31
32
# File 'lib/volt/page/bindings/event_binding.rb', line 30

def context
  @context
end

Instance Method Details

#removeObject

Remove the event binding



49
50
51
# File 'lib/volt/page/bindings/event_binding.rb', line 49

def remove
  @page.events.remove(@event_name, self)
end