Class: Browser::Event

Inherits:
Object show all
Includes:
Native::Wrapper
Defined in:
opal/browser/event.rb,
opal/browser/event/ui.rb,
opal/browser/event/base.rb,
opal/browser/event/drag.rb,
opal/browser/event/close.rb,
opal/browser/event/focus.rb,
opal/browser/event/mouse.rb,
opal/browser/event/touch.rb,
opal/browser/event/wheel.rb,
opal/browser/event/custom.rb,
opal/browser/event/sensor.rb,
opal/browser/event/gamepad.rb,
opal/browser/event/message.rb,
opal/browser/event/storage.rb,
opal/browser/event/keyboard.rb,
opal/browser/event/progress.rb,
opal/browser/event/animation.rb,
opal/browser/event/clipboard.rb,
opal/browser/event/pop_state.rb,
opal/browser/event/composition.rb,
opal/browser/event/hash_change.rb,
opal/browser/event/device_light.rb,
opal/browser/event/before_unload.rb,
opal/browser/event/data_transfer.rb,
opal/browser/event/device_motion.rb,
opal/browser/event/page_transition.rb,
opal/browser/event/audio_processing.rb,
opal/browser/event/device_proximity.rb,
opal/browser/event/device_orientation.rb

Defined Under Namespace

Modules: Target Classes: Animation, AudioProcessing, BeforeUnload, Clipboard, Close, Composition, Custom, DataTransfer, Definition, DeviceLight, DeviceMotion, DeviceOrientation, DeviceProximity, Drag, Focus, Gamepad, HashChange, Keyboard, Message, Mouse, PageTransition, PopState, Progress, Sensor, Storage, Touch, UI, Wheel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, callback = nil) ⇒ Event

Returns a new instance of Event.


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

def initialize(event, callback = nil)
  super(event)

  @callback = callback
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback


95
96
97
# File 'opal/browser/event.rb', line 95

def callback
  @callback
end

#onObject


108
109
110
# File 'opal/browser/event.rb', line 108

def on
  @on || Target.convert(`#@native.currentTarget`)
end

Class Method Details

.aliasesObject


6
7
8
9
10
11
# File 'opal/browser/event.rb', line 6

def self.aliases
  @aliases ||= {
    'dom:load' => 'DOMContentLoaded',
    'hover'    => 'mouse:over'
  }
end

.class_for(name) ⇒ Object


39
40
41
# File 'opal/browser/event.rb', line 39

def self.class_for(name)
  @handlers[name_for(name)] || Custom
end

.construct(name, desc) ⇒ Object


58
59
60
# File 'opal/browser/event.rb', line 58

def self.construct(name, desc)
  `new Event(#{name}, #{desc})`
end

.create(name, *args, &block) ⇒ Object


47
48
49
50
51
52
53
54
55
# File 'opal/browser/event.rb', line 47

def self.create(name, *args, &block)
  name  = name_for(name)
  klass = class_for(name)

  event = klass.new(klass.construct(name, klass.const_get(:Definition).new(&block)))
  event.arguments = args

  event
end

.handlersObject


17
18
19
# File 'opal/browser/event.rb', line 17

def self.handlers
  @handlers ||= {}
end

.handles(*events) ⇒ Object


21
22
23
# File 'opal/browser/event.rb', line 21

def self.handles(*events)
  events.each { |event| Event.handlers[event] = self }
end

.name_for(name) ⇒ Object


13
14
15
# File 'opal/browser/event.rb', line 13

def self.name_for(name)
  (aliases[name] || name).gsub(?:, '')
end

.new(value, callback = nil) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
# File 'opal/browser/event.rb', line 83

def self.new(value, callback = nil)
  return super unless self == Event

  klass = class_for(callback ? callback.name : `value.type`)

  if klass == Event
    super
  else
    klass.new(value, callback)
  end
end

.supported?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'opal/browser/event.rb', line 43

def self.supported?
  true
end

Instance Method Details

#argumentsObject


116
117
118
# File 'opal/browser/event.rb', line 116

def arguments
  `#@native.arguments || []`
end

#arguments=(args) ⇒ Object


120
121
122
# File 'opal/browser/event.rb', line 120

def arguments=(args)
  `#@native.arguments = #{args}`
end

#nameObject


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

def name
  `#@native.type`
end

#offObject


130
131
132
# File 'opal/browser/event.rb', line 130

def off
  @callback.off if @callback
end

#preventObject


143
144
145
146
# File 'opal/browser/event.rb', line 143

def prevent
  `#@native.preventDefault()` if defined?(`#@native.preventDefault`)
  `#@native.prevented = true`
end

#prevented?Boolean

Returns:

  • (Boolean)

148
149
150
# File 'opal/browser/event.rb', line 148

def prevented?
  `!!#@native.prevented`
end

#stopObject


138
139
140
141
# File 'opal/browser/event.rb', line 138

def stop
  `#@native.stopPropagation()` if defined?(`#@native.stopPropagation`)
  `#@native.stopped = true`
end

#stop!Object


152
153
154
155
# File 'opal/browser/event.rb', line 152

def stop!
  prevent
  stop
end

#stopped?Boolean

Returns:

  • (Boolean)

134
135
136
# File 'opal/browser/event.rb', line 134

def stopped?
  `!!#@native.stopped`
end

#targetObject


112
113
114
# File 'opal/browser/event.rb', line 112

def target
  Target.convert(`#@native.srcElement || #@native.target`)
end