Class: Browser::Event::Target::Callback

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/event/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eventClass (readonly)

Returns the class for the event.

Returns:

  • (Class)

    the class for the event


100
101
102
# File 'opal/browser/event/base.rb', line 100

def event
  Event.class_for(@name)
end

#nameObject (readonly)

Returns the value of attribute name


62
63
64
# File 'opal/browser/event/base.rb', line 62

def name
  @name
end

#selectorObject (readonly)

Returns the value of attribute selector


62
63
64
# File 'opal/browser/event/base.rb', line 62

def selector
  @selector
end

#targetObject (readonly)

Returns the value of attribute target


62
63
64
# File 'opal/browser/event/base.rb', line 62

def target
  @target
end

Instance Method Details

#call(event) ⇒ Object

Call the callback with the given event.

Parameters:

  • event (native)

    the native event object


75
76
77
# File 'opal/browser/event/base.rb', line 75

def call(event)
  to_proc.call(event)
end

#offObject

Stop listening for the event linked to the callback.


105
106
107
# File 'opal/browser/event/base.rb', line 105

def off
  target.off(self)
end

#to_procObject

Get the native function linked to the callback.


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'opal/browser/event/base.rb', line 80

def to_proc
  @proc ||= -> event {
    %x{
      if (!event.currentTarget) {
        event.currentTarget = self.target.native;
      }
    }

    event = Event.new(event, self)

    unless event.stopped?
      @block.call(event, *event.arguments)
    end

    !event.prevented?
  }
end