Class: DOM::Event

Inherits:
Object show all
Defined in:
opal/fron/dom/event.rb

Overview

Event

Constant Summary collapse

SPECIAL_KEYS =

Special keys for converions

{
  8 => 'backspace',
  9 => 'tab',
  12 => 'num',
  13 => 'enter',
  16 => 'shift',
  17 => 'ctrl',
  18 => 'alt',
  19 => 'pause',
  20 => 'capslock',
  27 => 'esc',
  32 => 'space',
  33 => 'pageup',
  34 => 'pagedown',
  35 => 'end',
  36 => 'home',
  37 => 'left',
  38 => 'up',
  39 => 'right',
  40 => 'down',
  44 => 'print',
  45 => 'insert',
  46 => 'delete',
  48 => '0',
  49 => '1',
  50 => '2',
  51 => '3',
  52 => '4',
  53 => '5',
  54 => '6',
  55 => '7',
  56 => '8',
  57 => '9',
  65 => 'a',
  66 => 'b',
  67 => 'c',
  68 => 'd',
  69 => 'e',
  70 => 'f',
  71 => 'g',
  72 => 'h',
  73 => 'i',
  74 => 'j',
  75 => 'k',
  76 => 'l',
  77 => 'm',
  78 => 'n',
  79 => 'o',
  80 => 'p',
  81 => 'q',
  82 => 'r',
  83 => 's',
  84 => 't',
  85 => 'u',
  86 => 'v',
  87 => 'w',
  88 => 'x',
  89 => 'y',
  90 => 'z',
  91 => 'cmd',
  92 => 'cmd',
  93 => 'cmd',
  96 => 'num_0',
  97 => 'num_1',
  98 => 'num_2',
  99 => 'num_3',
  100 => 'num_4',
  101 => 'num_5',
  102 => 'num_6',
  103 => 'num_7',
  104 => 'num_8',
  105 => 'num_9',
  106 => 'multiply',
  107 => 'add',
  108 => 'enter',
  109 => 'subtract',
  110 => 'decimal',
  111 => 'divide',
  124 => 'print',
  144 => 'num',
  145 => 'scroll',
  186 => ';',
  187 => '=',
  188 => ',',
  189 => '-',
  190 => '.',
  191 => '/',
  192 => '`',
  219 => '[',
  220 => '\\',
  221 => ']',
  222 => '\'',
  224 => 'cmd',
  57_392 => 'ctrl',
  63_289 => 'num'
}

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Event

Initializes the event


106
107
108
# File 'opal/fron/dom/event.rb', line 106

def initialize(event)
  @event = event
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

Runs missing method calls


113
114
115
# File 'opal/fron/dom/event.rb', line 113

def method_missing(name)
  `#{@event}[#{name}]`
end

Instance Method Details

#alt?Boolan

Returns whether the alt key has been pressed


233
234
235
# File 'opal/fron/dom/event.rb', line 233

def alt?
  `#{@event}.altKey`
end

#buttonNumeric

Returns the index of the pressed mouse button


140
141
142
# File 'opal/fron/dom/event.rb', line 140

def button
  `#{@event}.button`
end

#charCodeNumeric

Returns the character code of the pressed key


154
155
156
# File 'opal/fron/dom/event.rb', line 154

def charCode
  `#{@event}.charCode`
end

#clientXNumeric

Returns the clientX coordinate of the event


219
220
221
# File 'opal/fron/dom/event.rb', line 219

def clientX
  `#{@event}.clientX`
end

#clientYNumeric

Returns the clientY coordinate of the event


226
227
228
# File 'opal/fron/dom/event.rb', line 226

def clientY
  `#{@event}.clientY`
end

#ctrl?Boolan

Returns whether the control key has been pressed


247
248
249
# File 'opal/fron/dom/event.rb', line 247

def ctrl?
  `#{@event}.ctrlKey`
end

#dataTransferObject

Returns the native dataTransfrer object


133
134
135
# File 'opal/fron/dom/event.rb', line 133

def dataTransfer
  Native `#{@event}.dataTransfer`
end

#defaultPrevented?Boolean

Returns whether the default was prevented or not


174
175
176
# File 'opal/fron/dom/event.rb', line 174

def defaultPrevented?
  `#{@event}.defaultPrevented`
end

#keyString

Returns the string represenation of the pressed key


120
121
122
123
# File 'opal/fron/dom/event.rb', line 120

def key
  return SPECIAL_KEYS[keyCode] if SPECIAL_KEYS[keyCode]
  `String.fromCharCode(#{keyCode}).toLowerCase()`
end

#keyCodeNumeric

Returns the key code of the pressed key


161
162
163
# File 'opal/fron/dom/event.rb', line 161

def keyCode
  `#{@event}.keyCode`
end

#meta?Boolan

Returns whether the meta (apple) key has been pressed


254
255
256
# File 'opal/fron/dom/event.rb', line 254

def meta?
  `#{@event}.metaKey`
end

#pageXNumeric

Returns the pageX coordinate of the event


191
192
193
# File 'opal/fron/dom/event.rb', line 191

def pageX
  `#{@event}.pageX`
end

#pageYNumeric

Returns the pageY coordinate of the event


198
199
200
# File 'opal/fron/dom/event.rb', line 198

def pageY
  `#{@event}.pageY`
end

#preventDefaultObject

Prevents the default action of the event


179
180
181
# File 'opal/fron/dom/event.rb', line 179

def preventDefault
  `#{@event}.preventDefault()`
end

#screenXNumeric

Returns the screenX coordinate of the event


205
206
207
# File 'opal/fron/dom/event.rb', line 205

def screenX
  `#{@event}.screenX`
end

#screenYNumeric

Returns the screenY coordinate of the event


212
213
214
# File 'opal/fron/dom/event.rb', line 212

def screenY
  `#{@event}.screenY`
end

#shift?Boolan

Returns whether the shift key has been pressed


240
241
242
# File 'opal/fron/dom/event.rb', line 240

def shift?
  `#{@event}.shiftKey`
end

#stopObject

Stops the event


166
167
168
169
# File 'opal/fron/dom/event.rb', line 166

def stop
  preventDefault
  stopPropagation
end

#stopImmediatePropagationObject

Stops the immediate propagation of the event


126
127
128
# File 'opal/fron/dom/event.rb', line 126

def stopImmediatePropagation
  `#{@event}.stopImmediatePropagation()`
end

#stopPropagationObject

Stops the propagation of the event


184
185
186
# File 'opal/fron/dom/event.rb', line 184

def stopPropagation
  `#{@event}.stopPropagation()`
end

#targetDOM::NODE

Returns the target of the event


147
148
149
# File 'opal/fron/dom/event.rb', line 147

def target
  DOM::Element.fromNode `#{@event}.target`
end