Class: DOM::Event
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
-
#alt? ⇒ Boolan
Returns whether the alt key has been pressed.
-
#button ⇒ Numeric
Returns the index of the pressed mouse button.
-
#char_code ⇒ Numeric
Returns the character code of the pressed key.
-
#client_x ⇒ Numeric
Returns the clientX coordinate of the event.
-
#client_y ⇒ Numeric
Returns the clientY coordinate of the event.
-
#ctrl? ⇒ Boolan
Returns whether the control key has been pressed.
- #data ⇒ Object
-
#data_transfer ⇒ Object
Returns the native dataTransfrer object.
-
#default_prevented? ⇒ Boolean
Returns whether the default was prevented or not.
-
#initialize(event) ⇒ Event
constructor
Initializes the event.
-
#key ⇒ String
Returns the string represenation of the pressed key.
-
#key_code ⇒ Numeric
Returns the key code of the pressed key.
-
#meta? ⇒ Boolan
Returns whether the meta (apple) key has been pressed.
-
#method_missing(name) ⇒ Object
Runs missing method calls.
-
#page_x ⇒ Numeric
Returns the pageX coordinate of the event.
-
#page_y ⇒ Numeric
Returns the pageY coordinate of the event.
-
#prevent_default ⇒ Object
Prevents the default action of the event.
-
#screen_x ⇒ Numeric
Returns the screenX coordinate of the event.
-
#screen_y ⇒ Numeric
Returns the screenY coordinate of the event.
-
#shift? ⇒ Boolan
Returns whether the shift key has been pressed.
-
#stop ⇒ Object
Stops the event.
-
#stop_immediate_propagation ⇒ Object
Stops the immediate propagation of the event.
-
#stop_propagation ⇒ Object
Stops the propagation of the event.
-
#target ⇒ DOM::NODE
Returns the target of the event.
Constructor Details
#initialize(event) ⇒ Event
Initializes the event
105 106 107 |
# File 'opal/fron/dom/event.rb', line 105 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
112 113 114 |
# File 'opal/fron/dom/event.rb', line 112 def method_missing(name) `#{@event}[#{name}] || Opal.NIL` end |
Instance Method Details
#alt? ⇒ Boolan
Returns whether the alt key has been pressed
237 238 239 |
# File 'opal/fron/dom/event.rb', line 237 def alt? `#{@event}.altKey` end |
#button ⇒ Numeric
Returns the index of the pressed mouse button
143 144 145 |
# File 'opal/fron/dom/event.rb', line 143 def `#{@event}.button` end |
#char_code ⇒ Numeric
Returns the character code of the pressed key
157 158 159 |
# File 'opal/fron/dom/event.rb', line 157 def char_code `#{@event}.charCode` end |
#client_x ⇒ Numeric
Returns the clientX coordinate of the event
223 224 225 |
# File 'opal/fron/dom/event.rb', line 223 def client_x `#{@event}.clientX` end |
#client_y ⇒ Numeric
Returns the clientY coordinate of the event
230 231 232 |
# File 'opal/fron/dom/event.rb', line 230 def client_y `#{@event}.clientY` end |
#ctrl? ⇒ Boolan
Returns whether the control key has been pressed
251 252 253 |
# File 'opal/fron/dom/event.rb', line 251 def ctrl? `#{@event}.ctrlKey` end |
#data ⇒ Object
116 117 118 |
# File 'opal/fron/dom/event.rb', line 116 def data JSON.from_object(`#{@event}.data`) end |
#data_transfer ⇒ Object
Returns the native dataTransfrer object
136 137 138 |
# File 'opal/fron/dom/event.rb', line 136 def data_transfer Native `#{@event}.dataTransfer` end |
#default_prevented? ⇒ Boolean
Returns whether the default was prevented or not
178 179 180 |
# File 'opal/fron/dom/event.rb', line 178 def default_prevented? `#{@event}.defaultPrevented` end |
#key ⇒ String
Returns the string represenation of the pressed key
123 124 125 126 |
# File 'opal/fron/dom/event.rb', line 123 def key return SPECIAL_KEYS[key_code] if SPECIAL_KEYS[key_code] `String.fromCharCode(#{key_code}).toLowerCase()` end |
#key_code ⇒ Numeric
Returns the key code of the pressed key
164 165 166 |
# File 'opal/fron/dom/event.rb', line 164 def key_code `#{@event}.keyCode` end |
#meta? ⇒ Boolan
Returns whether the meta (apple) key has been pressed
258 259 260 |
# File 'opal/fron/dom/event.rb', line 258 def `#{@event}.metaKey` end |
#page_x ⇒ Numeric
Returns the pageX coordinate of the event
195 196 197 |
# File 'opal/fron/dom/event.rb', line 195 def page_x `#{@event}.pageX` end |
#page_y ⇒ Numeric
Returns the pageY coordinate of the event
202 203 204 |
# File 'opal/fron/dom/event.rb', line 202 def page_y `#{@event}.pageY` end |
#prevent_default ⇒ Object
Prevents the default action of the event
183 184 185 |
# File 'opal/fron/dom/event.rb', line 183 def prevent_default `#{@event}.preventDefault()` end |
#screen_x ⇒ Numeric
Returns the screenX coordinate of the event
209 210 211 |
# File 'opal/fron/dom/event.rb', line 209 def screen_x `#{@event}.screenX` end |
#screen_y ⇒ Numeric
Returns the screenY coordinate of the event
216 217 218 |
# File 'opal/fron/dom/event.rb', line 216 def screen_y `#{@event}.screenY` end |
#shift? ⇒ Boolan
Returns whether the shift key has been pressed
244 245 246 |
# File 'opal/fron/dom/event.rb', line 244 def shift? `#{@event}.shiftKey` end |
#stop ⇒ Object
Stops the event
169 170 171 172 173 |
# File 'opal/fron/dom/event.rb', line 169 def stop prevent_default stop_immediate_propagation stop_propagation end |
#stop_immediate_propagation ⇒ Object
Stops the immediate propagation of the event
129 130 131 |
# File 'opal/fron/dom/event.rb', line 129 def stop_immediate_propagation `#{@event}.stopImmediatePropagation()` end |
#stop_propagation ⇒ Object
Stops the propagation of the event
188 189 190 |
# File 'opal/fron/dom/event.rb', line 188 def stop_propagation `#{@event}.stopPropagation()` end |