Class: EventBinding

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

Instance Attribute Summary collapse

Attributes inherited from BaseBinding

#target

Instance Method Summary collapse

Methods inherited from BaseBinding

#queue_update, #remove_anchors, #section, #value_from_getter

Constructor Details

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

Returns a new instance of EventBinding.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/volt/templates/event_binding.rb', line 24

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

Instance Attribute Details

#binding_nameObject

Returns the value of attribute binding_name.



23
24
25
# File 'lib/volt/templates/event_binding.rb', line 23

def binding_name
  @binding_name
end

#contextObject

Returns the value of attribute context.



23
24
25
# File 'lib/volt/templates/event_binding.rb', line 23

def context
  @context
end

Instance Method Details

#elementObject



42
43
44
# File 'lib/volt/templates/event_binding.rb', line 42

def element
  Element.find('#' + binding_name)
end

#removeObject

Remove the event binding



47
48
49
50
# File 'lib/volt/templates/event_binding.rb', line 47

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