Class: Volt::EventBinding
- Inherits:
-
BaseBinding
- Object
- BaseBinding
- Volt::EventBinding
- Defined in:
- lib/volt/page/bindings/event_binding.rb
Instance Attribute Summary collapse
-
#binding_name ⇒ Object
Returns the value of attribute binding_name.
-
#context ⇒ Object
Returns the value of attribute context.
Attributes inherited from BaseBinding
Instance Method Summary collapse
-
#initialize(page, target, context, binding_name, event_name, call_proc) ⇒ EventBinding
constructor
A new instance of EventBinding.
-
#remove ⇒ Object
Remove the event binding.
Methods inherited from BaseBinding
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_name ⇒ Object
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 |
#context ⇒ Object
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
#remove ⇒ Object
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 |