opal-browser 0.1.0.beta1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +95 -0
- data/.gitignore +3 -0
- data/.yardopts +1 -1
- data/Gemfile +22 -3
- data/LICENSE +20 -0
- data/README.md +200 -20
- data/Rakefile +29 -1
- data/config.ru +20 -2
- data/docs/polyfills.md +24 -0
- data/examples/2048/Gemfile +6 -0
- data/examples/2048/README.md +13 -0
- data/examples/2048/app/application.rb +169 -0
- data/examples/2048/config.ru +9 -0
- data/examples/canvas/Gemfile +6 -0
- data/examples/canvas/README.md +9 -0
- data/examples/canvas/app/application.rb +55 -0
- data/examples/canvas/config.ru +9 -0
- data/examples/component/Gemfile +6 -0
- data/examples/component/README.md +10 -0
- data/examples/component/app/application.rb +66 -0
- data/examples/component/config.ru +9 -0
- data/examples/integrations/README.md +24 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/Gemfile +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/config.ru +9 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Gemfile +7 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/README.md +22 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Rakefile +4 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app.rb +32 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/config.ru +3 -0
- data/examples/integrations/dynamic-roda-tilt/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-tilt/Gemfile +8 -0
- data/examples/integrations/dynamic-roda-tilt/README.md +17 -0
- data/examples/integrations/dynamic-roda-tilt/Rakefile +6 -0
- data/examples/integrations/dynamic-roda-tilt/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-tilt/app.rb +50 -0
- data/examples/integrations/dynamic-roda-tilt/config.ru +3 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/Gemfile +7 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/config.ru +29 -0
- data/examples/integrations/static-bash/.gitignore +2 -0
- data/examples/integrations/static-bash/Gemfile +3 -0
- data/examples/integrations/static-bash/README.md +8 -0
- data/examples/integrations/static-bash/app/application.rb +6 -0
- data/examples/integrations/static-bash/build.sh +4 -0
- data/examples/integrations/static-bash/index.html +10 -0
- data/examples/integrations/static-bash-opal-parser/.gitignore +3 -0
- data/examples/integrations/static-bash-opal-parser/Gemfile +3 -0
- data/examples/integrations/static-bash-opal-parser/README.md +10 -0
- data/examples/integrations/static-bash-opal-parser/build.sh +4 -0
- data/examples/integrations/static-bash-opal-parser/index.html +19 -0
- data/examples/integrations/static-rake/.gitignore +1 -0
- data/examples/integrations/static-rake/Gemfile +4 -0
- data/examples/integrations/static-rake/README.md +7 -0
- data/examples/integrations/static-rake/Rakefile +10 -0
- data/examples/integrations/static-rake/app/application.rb +6 -0
- data/examples/integrations/static-rake/index.html +9 -0
- data/examples/integrations/static-rake-guard/.gitignore +1 -0
- data/examples/integrations/static-rake-guard/Gemfile +6 -0
- data/examples/integrations/static-rake-guard/Guardfile +3 -0
- data/examples/integrations/static-rake-guard/README.md +10 -0
- data/examples/integrations/static-rake-guard/Rakefile +10 -0
- data/examples/integrations/static-rake-guard/app/application.rb +6 -0
- data/examples/integrations/static-rake-guard/index.html +9 -0
- data/examples/svg/.gitignore +1 -0
- data/examples/svg/Gemfile +4 -0
- data/examples/svg/README.md +7 -0
- data/examples/svg/Rakefile +10 -0
- data/examples/svg/app/application.rb +11 -0
- data/examples/svg/index.html +17 -0
- data/examples/svg/index.svg +6 -0
- data/index.html.erb +24 -0
- data/lib/opal-browser.rb +1 -0
- data/opal/browser/animation_frame.rb +92 -10
- data/opal/browser/audio/node.rb +121 -0
- data/opal/browser/audio/param_schedule.rb +43 -0
- data/opal/browser/audio.rb +66 -0
- data/opal/browser/blob.rb +94 -0
- data/opal/browser/canvas/data.rb +2 -12
- data/opal/browser/canvas/gradient.rb +1 -11
- data/opal/browser/canvas/style.rb +3 -11
- data/opal/browser/canvas/text.rb +1 -11
- data/opal/browser/canvas.rb +86 -28
- data/opal/browser/console.rb +6 -38
- data/opal/browser/cookies.rb +90 -27
- data/opal/browser/crypto.rb +79 -0
- data/opal/browser/css/declaration.rb +1 -6
- data/opal/browser/css/rule.rb +1 -1
- data/opal/browser/css/style_sheet.rb +2 -2
- data/opal/browser/css.rb +23 -7
- data/opal/browser/database/sql.rb +193 -0
- data/opal/browser/delay.rb +94 -0
- data/opal/browser/dom/attribute.rb +16 -9
- data/opal/browser/dom/builder.rb +35 -25
- data/opal/browser/dom/character_data.rb +43 -7
- data/opal/browser/dom/document.rb +171 -37
- data/opal/browser/dom/document_fragment.rb +18 -0
- data/opal/browser/dom/document_or_shadow_root.rb +19 -0
- data/opal/browser/dom/element/attributes.rb +111 -0
- data/opal/browser/dom/element/button.rb +31 -0
- data/opal/browser/dom/element/custom.rb +177 -0
- data/opal/browser/dom/element/data.rb +82 -0
- data/opal/browser/dom/element/editable.rb +47 -0
- data/opal/browser/dom/element/form.rb +38 -0
- data/opal/browser/dom/element/iframe.rb +37 -0
- data/opal/browser/dom/element/image.rb +25 -0
- data/opal/browser/dom/element/input.rb +48 -1
- data/opal/browser/dom/element/media.rb +17 -0
- data/opal/browser/dom/element/offset.rb +32 -10
- data/opal/browser/dom/element/position.rb +11 -2
- data/opal/browser/dom/element/scroll.rb +139 -20
- data/opal/browser/dom/element/select.rb +42 -0
- data/opal/browser/dom/element/size.rb +46 -0
- data/opal/browser/dom/element/template.rb +11 -0
- data/opal/browser/dom/element/textarea.rb +26 -0
- data/opal/browser/dom/element.rb +496 -168
- data/opal/browser/dom/mutation_observer.rb +69 -9
- data/opal/browser/dom/node.rb +270 -83
- data/opal/browser/dom/node_set.rb +74 -41
- data/opal/browser/dom/shadow_root.rb +12 -0
- data/opal/browser/dom/text.rb +18 -3
- data/opal/browser/dom.rb +40 -18
- data/opal/browser/effects.rb +180 -3
- data/opal/browser/event/all.rb +26 -0
- data/opal/browser/event/animation.rb +40 -0
- data/opal/browser/{dom/event → event}/audio_processing.rb +10 -6
- data/opal/browser/event/base.rb +461 -0
- data/opal/browser/event/before_unload.rb +17 -0
- data/opal/browser/event/clipboard.rb +37 -0
- data/opal/browser/event/close.rb +49 -0
- data/opal/browser/event/composition.rb +52 -0
- data/opal/browser/event/custom.rb +65 -0
- data/opal/browser/event/data_transfer.rb +95 -0
- data/opal/browser/event/device_light.rb +25 -0
- data/opal/browser/{dom/event → event}/device_motion.rb +21 -6
- data/opal/browser/event/device_orientation.rb +50 -0
- data/opal/browser/{dom/event → event}/device_proximity.rb +10 -6
- data/opal/browser/event/drag.rb +123 -0
- data/opal/browser/event/focus.rb +41 -0
- data/opal/browser/event/gamepad.rb +62 -0
- data/opal/browser/{dom/event → event}/hash_change.rb +10 -6
- data/opal/browser/event/keyboard.rb +128 -0
- data/opal/browser/event/message.rb +72 -0
- data/opal/browser/{dom/event → event}/mouse.rb +37 -32
- data/opal/browser/event/page_transition.rb +25 -0
- data/opal/browser/event/pop_state.rb +35 -0
- data/opal/browser/event/progress.rb +45 -0
- data/opal/browser/event/sensor.rb +17 -0
- data/opal/browser/{dom/event → event}/storage.rb +10 -6
- data/opal/browser/{dom/event → event}/touch.rb +14 -21
- data/opal/browser/event/ui.rb +38 -0
- data/opal/browser/{dom/event → event}/wheel.rb +6 -4
- data/opal/browser/event.rb +163 -0
- data/opal/browser/event_source.rb +7 -4
- data/opal/browser/form_data.rb +225 -0
- data/opal/browser/history.rb +53 -21
- data/opal/browser/http/binary.rb +1 -0
- data/opal/browser/http/headers.rb +21 -2
- data/opal/browser/http/request.rb +83 -55
- data/opal/browser/http/response.rb +5 -1
- data/opal/browser/http.rb +47 -9
- data/opal/browser/immediate.rb +128 -10
- data/opal/browser/interval.rb +41 -23
- data/opal/browser/location.rb +20 -4
- data/opal/browser/navigator.rb +136 -13
- data/opal/browser/polyfill/visual_viewport.rb +216 -0
- data/opal/browser/screen.rb +34 -8
- data/opal/browser/setup/base.rb +6 -0
- data/opal/browser/setup/full.rb +13 -0
- data/opal/browser/setup/large.rb +17 -0
- data/opal/browser/setup/mini.rb +8 -0
- data/opal/browser/setup/traditional.rb +10 -0
- data/opal/browser/socket.rb +16 -8
- data/opal/browser/storage.rb +155 -52
- data/opal/browser/support.rb +299 -0
- data/opal/browser/utils.rb +116 -18
- data/opal/browser/version.rb +1 -1
- data/opal/browser/visual_viewport.rb +39 -0
- data/opal/browser/window/size.rb +47 -9
- data/opal/browser/window/view.rb +37 -4
- data/opal/browser/window.rb +46 -26
- data/opal/browser.rb +1 -10
- data/opal/opal-browser.rb +1 -0
- data/opal-browser.gemspec +10 -12
- data/spec/database/sql_spec.rb +139 -0
- data/spec/delay_spec.rb +41 -0
- data/spec/dom/attribute_spec.rb +49 -0
- data/spec/dom/builder_spec.rb +36 -19
- data/spec/dom/document_spec.rb +28 -6
- data/spec/dom/element/attributes_spec.rb +52 -0
- data/spec/dom/element/custom_spec.rb +106 -0
- data/spec/dom/element/subclass_spec.rb +144 -0
- data/spec/dom/element_spec.rb +184 -7
- data/spec/dom/mutation_observer_spec.rb +13 -9
- data/spec/dom/node_set_spec.rb +44 -0
- data/spec/dom/node_spec.rb +87 -27
- data/spec/dom_spec.rb +19 -9
- data/spec/event_source_spec.rb +18 -15
- data/spec/{dom/event_spec.rb → event_spec.rb} +55 -26
- data/spec/history_spec.rb +32 -19
- data/spec/http_spec.rb +25 -36
- data/spec/immediate_spec.rb +10 -7
- data/spec/interval_spec.rb +59 -0
- data/spec/native_cached_wrapper_spec.rb +46 -0
- data/spec/runner.rb +107 -0
- data/spec/socket_spec.rb +18 -14
- data/spec/spec_helper.rb +2 -4
- data/spec/spec_helper_promise.rb.erb +25 -0
- data/spec/storage_spec.rb +7 -7
- data/spec/wgxpath.install.js +49 -0
- data/spec/window_spec.rb +2 -2
- metadata +181 -93
- data/opal/browser/compatibility/animation_frame.rb +0 -93
- data/opal/browser/compatibility/dom/document/window.rb +0 -15
- data/opal/browser/compatibility/dom/element/css.rb +0 -15
- data/opal/browser/compatibility/dom/element/matches.rb +0 -31
- data/opal/browser/compatibility/dom/element/offset.rb +0 -20
- data/opal/browser/compatibility/dom/element/scroll.rb +0 -25
- data/opal/browser/compatibility/dom/element/style.rb +0 -15
- data/opal/browser/compatibility/dom/mutation_observer.rb +0 -47
- data/opal/browser/compatibility/http/request.rb +0 -15
- data/opal/browser/compatibility/immediate.rb +0 -107
- data/opal/browser/compatibility/window/scroll.rb +0 -27
- data/opal/browser/compatibility/window/size.rb +0 -13
- data/opal/browser/compatibility/window/view.rb +0 -13
- data/opal/browser/compatibility.rb +0 -59
- data/opal/browser/dom/compatibility.rb +0 -8
- data/opal/browser/dom/event/animation.rb +0 -26
- data/opal/browser/dom/event/base.rb +0 -207
- data/opal/browser/dom/event/before_unload.rb +0 -13
- data/opal/browser/dom/event/clipboard.rb +0 -26
- data/opal/browser/dom/event/close.rb +0 -35
- data/opal/browser/dom/event/composition.rb +0 -38
- data/opal/browser/dom/event/custom.rb +0 -30
- data/opal/browser/dom/event/device_light.rb +0 -21
- data/opal/browser/dom/event/device_orientation.rb +0 -36
- data/opal/browser/dom/event/drag.rb +0 -113
- data/opal/browser/dom/event/focus.rb +0 -23
- data/opal/browser/dom/event/gamepad.rb +0 -47
- data/opal/browser/dom/event/keyboard.rb +0 -93
- data/opal/browser/dom/event/message.rb +0 -50
- data/opal/browser/dom/event/page_transition.rb +0 -21
- data/opal/browser/dom/event/pop_state.rb +0 -21
- data/opal/browser/dom/event/progress.rb +0 -31
- data/opal/browser/dom/event/sensor.rb +0 -13
- data/opal/browser/dom/event/ui.rb +0 -22
- data/opal/browser/dom/event.rb +0 -240
- data/opal/browser/http/compatibility.rb +0 -1
- data/opal/browser/http/parameters.rb +0 -8
- data/opal/browser/timeout.rb +0 -60
- data/opal/browser/window/compatibility.rb +0 -3
- data/opal/browser/window/scroll.rb +0 -49
@@ -1,13 +1,17 @@
|
|
1
|
-
module Browser;
|
1
|
+
module Browser; class Event
|
2
2
|
|
3
3
|
class Mouse < UI
|
4
|
+
handles 'click', 'contextmenu', 'dblclick', 'mousedown', 'mouseenter',
|
5
|
+
'mouseleave', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
|
6
|
+
'show'
|
7
|
+
|
4
8
|
def self.supported?
|
5
9
|
not $$[:MouseEvent].nil?
|
6
10
|
end
|
7
11
|
|
8
12
|
class Definition < UI::Definition
|
9
13
|
class Client
|
10
|
-
include Native
|
14
|
+
include Native::Wrapper
|
11
15
|
|
12
16
|
def x=(value)
|
13
17
|
`#@native.clientX = #{value}`
|
@@ -19,7 +23,7 @@ class Mouse < UI
|
|
19
23
|
end
|
20
24
|
|
21
25
|
class Layer
|
22
|
-
include Native
|
26
|
+
include Native::Wrapper
|
23
27
|
|
24
28
|
def x=(value)
|
25
29
|
`#@native.layerX = #{value}`
|
@@ -31,7 +35,7 @@ class Mouse < UI
|
|
31
35
|
end
|
32
36
|
|
33
37
|
class Offset
|
34
|
-
include Native
|
38
|
+
include Native::Wrapper
|
35
39
|
|
36
40
|
def x=(value)
|
37
41
|
`#@native.offsetX = #{value}`
|
@@ -43,7 +47,7 @@ class Mouse < UI
|
|
43
47
|
end
|
44
48
|
|
45
49
|
class Page
|
46
|
-
include Native
|
50
|
+
include Native::Wrapper
|
47
51
|
|
48
52
|
def x=(value)
|
49
53
|
`#@native.pageX = #{value}`
|
@@ -55,7 +59,7 @@ class Mouse < UI
|
|
55
59
|
end
|
56
60
|
|
57
61
|
class Screen
|
58
|
-
include Native
|
62
|
+
include Native::Wrapper
|
59
63
|
|
60
64
|
def x=(value)
|
61
65
|
`#@native.screenX = #{value}`
|
@@ -67,7 +71,7 @@ class Mouse < UI
|
|
67
71
|
end
|
68
72
|
|
69
73
|
class Ancestor
|
70
|
-
include Native
|
74
|
+
include Native::Wrapper
|
71
75
|
|
72
76
|
def x=(value)
|
73
77
|
`#@native.x = #{value}`
|
@@ -139,31 +143,32 @@ class Mouse < UI
|
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
146
|
+
if Browser.supports? 'Event.constructor'
|
147
|
+
def self.construct(name, desc)
|
148
|
+
`new MouseEvent(#{name}, #{desc})`
|
149
|
+
end
|
150
|
+
elsif Browser.supports? 'Event.create'
|
151
|
+
def self.construct(name, desc)
|
152
|
+
%x{
|
153
|
+
var event = document.createEvent("MouseEvent");
|
154
|
+
event.initMouseEvent(name, desc.bubbles, desc.cancelable,
|
155
|
+
desc.view || window, desc.detail || 0,
|
156
|
+
desc.screenX || 0, desc.screenY || 0,
|
157
|
+
desc.clientX || 0, desc.clientY || 0,
|
158
|
+
desc.ctrlKey || false, desc.altKey || false,
|
159
|
+
desc.shiftKey || false, desc.metaKey || false,
|
160
|
+
desc.button || 0, desc.relatedTarget || null);
|
161
|
+
|
162
|
+
return event;
|
163
|
+
}
|
164
|
+
end
|
165
|
+
end if supported?
|
163
166
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
+
alias_native :alt?, :altKey
|
168
|
+
alias_native :ctrl?, :ctrlKey
|
169
|
+
alias_native :meta?, :metaKey
|
170
|
+
alias_native :shift?, :shiftKey
|
171
|
+
alias_native :button
|
167
172
|
|
168
173
|
def client
|
169
174
|
Position.new(`#@native.clientX`, `#@native.clientY`)
|
@@ -250,4 +255,4 @@ class Mouse < UI
|
|
250
255
|
end
|
251
256
|
end
|
252
257
|
|
253
|
-
end; end
|
258
|
+
end; end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class PageTransition < Event
|
4
|
+
handles 'pagehide', 'pageshow'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.PageTransition'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def persisted=(value)
|
12
|
+
`#@native.persisted = #{value}`
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if Browser.supports? 'Event.PageTransition'
|
17
|
+
def self.construct(name, desc)
|
18
|
+
`new PageTransitionEvent(name, desc)`
|
19
|
+
end
|
20
|
+
end if supported?
|
21
|
+
|
22
|
+
alias_native :persisted?, :persisted
|
23
|
+
end
|
24
|
+
|
25
|
+
end; end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class PopState < Event
|
4
|
+
handles 'popstate'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.PopState'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def state=(value)
|
12
|
+
`#@native.state = #{value}`
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if Browser.supports? 'Event.constructor'
|
17
|
+
def self.construct(name, desc)
|
18
|
+
`new PopStateEvent(#{name}, #{desc})`
|
19
|
+
end
|
20
|
+
elsif Browser.supports? 'Event.create'
|
21
|
+
def self.construct(name, desc)
|
22
|
+
%x{
|
23
|
+
var event = document.createEvent('PopStateEvent');
|
24
|
+
event.initPopStateEvent(name, desc.bubbles, desc.cancelable,
|
25
|
+
desc.state);
|
26
|
+
|
27
|
+
return event;
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end if supported?
|
31
|
+
|
32
|
+
alias_native :state
|
33
|
+
end
|
34
|
+
|
35
|
+
end; end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Progress < Event
|
4
|
+
handles 'progress', 'load', 'loadend', 'loadstart'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.Progress'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def computable=(value)
|
12
|
+
`#@native.computableLength = #{value}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def loaded=(value)
|
16
|
+
`#@native.loaded = #{value}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def total=(value)
|
20
|
+
`#@native.total = #{value}`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if Browser.supports? 'Event.constructor'
|
25
|
+
def self.construct(name, desc)
|
26
|
+
`new ProgressEvent(#{name}, #{desc})`
|
27
|
+
end
|
28
|
+
elsif Browser.supports? 'Event.create'
|
29
|
+
def self.construct(name, desc)
|
30
|
+
%x{
|
31
|
+
var event = document.createEvent("ProgressEvent");
|
32
|
+
event.initProgressEvent(name, desc.bubbles, desc.cancelable,
|
33
|
+
desc.computable, desc.loaded, desc.total);
|
34
|
+
|
35
|
+
return event;
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end if supported?
|
39
|
+
|
40
|
+
alias_native :computable?, :computableLength
|
41
|
+
alias_native :loaded
|
42
|
+
alias_native :total
|
43
|
+
end
|
44
|
+
|
45
|
+
end; end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Sensor < Event
|
4
|
+
handles 'compassneedscalibration', 'userproximity'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.Sensor'
|
8
|
+
end
|
9
|
+
|
10
|
+
if Browser.supports? 'Event.constructor'
|
11
|
+
def self.construct(name, desc)
|
12
|
+
`new SensorEvent(#{name}, #{desc})`
|
13
|
+
end
|
14
|
+
end if supported?
|
15
|
+
end
|
16
|
+
|
17
|
+
end; end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
module Browser;
|
1
|
+
module Browser; class Event
|
2
2
|
|
3
3
|
class Storage < Event
|
4
|
+
handles 'storage'
|
5
|
+
|
4
6
|
def self.supported?
|
5
|
-
|
7
|
+
Browser.supports? 'Event.Storage'
|
6
8
|
end
|
7
9
|
|
8
10
|
class Definition < Definition
|
@@ -27,9 +29,11 @@ class Storage < Event
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
if Browser.supports? 'Event.constructor'
|
33
|
+
def self.construct(name, desc)
|
34
|
+
`new StorageEvent(#{name}, #{desc})`
|
35
|
+
end
|
36
|
+
end if supported?
|
33
37
|
|
34
38
|
alias_native :key
|
35
39
|
alias_native :new, :newValue
|
@@ -38,4 +42,4 @@ class Storage < Event
|
|
38
42
|
alias_native :url
|
39
43
|
end
|
40
44
|
|
41
|
-
end; end
|
45
|
+
end; end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
module Browser;
|
1
|
+
module Browser; class Event
|
2
2
|
|
3
3
|
class Touch < Event
|
4
|
+
handles 'touchcancel', 'touchend', 'touchleave', 'touchmove', 'touchstart'
|
5
|
+
|
4
6
|
def self.supported?
|
5
|
-
|
7
|
+
Browser.supports? 'Event.Touch'
|
6
8
|
end
|
7
9
|
|
8
10
|
class Definition < Definition
|
@@ -23,25 +25,16 @@ class Touch < Event
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
`#@native.altKey`
|
32
|
-
end
|
33
|
-
|
34
|
-
def ctrl?
|
35
|
-
`#@native.ctrlKey`
|
36
|
-
end
|
37
|
-
|
38
|
-
def meta?
|
39
|
-
`#@native.metaKey`
|
40
|
-
end
|
28
|
+
if Browser.supports? 'Event.constructor'
|
29
|
+
def self.construct(name, desc)
|
30
|
+
`new TouchEvent(#{name}, #{desc})`
|
31
|
+
end
|
32
|
+
end if supported?
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
alias_native :alt?, :altKey
|
35
|
+
alias_native :ctrl?, :ctrlKey
|
36
|
+
alias_native :meta?, :metaKey
|
37
|
+
alias_native :shift?, :shiftKey
|
45
38
|
|
46
39
|
# TODO: implement touches and targetTouches
|
47
40
|
|
@@ -66,4 +59,4 @@ class Touch < Event
|
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
69
|
-
end; end
|
62
|
+
end; end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class UI < Event
|
4
|
+
def self.supported?
|
5
|
+
Browser.supports? 'Event.UI'
|
6
|
+
end
|
7
|
+
|
8
|
+
class Definition < Definition
|
9
|
+
def detail=(value)
|
10
|
+
`#@native.detail = #{value}`
|
11
|
+
end
|
12
|
+
|
13
|
+
def view=(value)
|
14
|
+
`#@native.view = #{value}`
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if Browser.supports? 'Event.constructor'
|
19
|
+
def self.construct(name, desc)
|
20
|
+
`new UIEvent(#{name}, #{desc})`
|
21
|
+
end
|
22
|
+
elsif Browser.supports? 'Event.create'
|
23
|
+
def self.construct(name, desc)
|
24
|
+
%x{
|
25
|
+
var event = document.createEvent("UIEvent");
|
26
|
+
event.initUIEvent(name, desc.bubbles, desc.cancelable,
|
27
|
+
desc.view || window, desc.detail || 0);
|
28
|
+
|
29
|
+
return event;
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end if supported?
|
33
|
+
|
34
|
+
alias_native :detail
|
35
|
+
alias_native :view
|
36
|
+
end
|
37
|
+
|
38
|
+
end; end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
module Browser;
|
1
|
+
module Browser; class Event
|
2
2
|
|
3
3
|
class Wheel < UI
|
4
|
+
handles 'wheel', 'mousewheel'
|
5
|
+
|
4
6
|
def self.supported?
|
5
7
|
not $$[:WheelEvent].nil?
|
6
8
|
end
|
@@ -29,8 +31,8 @@ class Wheel < UI
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
def self.
|
33
|
-
|
34
|
+
def self.construct(name, desc)
|
35
|
+
`new WheelEvent(#{name}, #{desc})`
|
34
36
|
end
|
35
37
|
|
36
38
|
alias_native :x, :deltaX
|
@@ -46,4 +48,4 @@ class Wheel < UI
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
end; end
|
51
|
+
end; end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'browser/event/base'
|
2
|
+
|
3
|
+
module Browser
|
4
|
+
|
5
|
+
class Event
|
6
|
+
def self.aliases
|
7
|
+
@aliases ||= {
|
8
|
+
'dom:load' => 'DOMContentLoaded',
|
9
|
+
'hover' => 'mouse:over'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.name_for(name)
|
14
|
+
(aliases[name] || name).gsub(?:, '')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.handlers
|
18
|
+
@handlers ||= {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.handles(*events)
|
22
|
+
events.each { |event| Event.handlers[event] = self }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Those events don't have interesting properties to warrant a custom class
|
26
|
+
# or are not currently implemented.
|
27
|
+
handles 'abort', 'afterprint', 'beforeprint', 'cached', 'canplay',
|
28
|
+
'canplaythrough', 'change', 'chargingchange', 'chargingtimechange',
|
29
|
+
'checking', 'close', 'dischargingtimechange', 'DOMContentLoaded',
|
30
|
+
'downloading', 'durationchange', 'emptied', 'ended', 'error',
|
31
|
+
'fullscreenchange', 'fullscreenerror', 'input', 'invalid',
|
32
|
+
'levelchange', 'loadeddata', 'loadedmetadata', 'noupdate', 'obsolete',
|
33
|
+
'offline', 'online', 'open', 'orientationchange', 'pause',
|
34
|
+
'pointerlockchange', 'pointerlockerror', 'play', 'playing',
|
35
|
+
'ratechange', 'readystatechange', 'reset', 'seeked', 'seeking',
|
36
|
+
'stalled', 'submit', 'success', 'suspend', 'timeupdate', 'updateready',
|
37
|
+
'visibilitychange', 'volumechange', 'waiting'
|
38
|
+
|
39
|
+
def self.class_for(name)
|
40
|
+
@handlers[name_for(name)] || Custom
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.supported?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.create(name, *args, &block)
|
48
|
+
name = name_for(name)
|
49
|
+
klass = class_for(name)
|
50
|
+
|
51
|
+
event = klass.new(klass.construct(name, klass.const_get(:Definition).new(&block)))
|
52
|
+
event.arguments = args
|
53
|
+
|
54
|
+
event
|
55
|
+
end
|
56
|
+
|
57
|
+
if Browser.supports? 'Event.constructor'
|
58
|
+
def self.construct(name, desc)
|
59
|
+
`new Event(#{name}, #{desc})`
|
60
|
+
end
|
61
|
+
elsif Browser.supports? 'Event.create'
|
62
|
+
def self.construct(name, desc)
|
63
|
+
%x{
|
64
|
+
var event = document.createEvent("HTMLEvents");
|
65
|
+
event.initEvent(name, desc.bubbles, desc.cancelable);
|
66
|
+
|
67
|
+
#{return Native(`event`).merge!(desc)};
|
68
|
+
}
|
69
|
+
end
|
70
|
+
elsif Browser.supports? 'Event.createObject'
|
71
|
+
def self.construct(name, desc)
|
72
|
+
Native(`document.createEventObject()`) \
|
73
|
+
.merge!(desc) \
|
74
|
+
.merge!(`{ type: name }`) \
|
75
|
+
.to_n
|
76
|
+
end
|
77
|
+
else
|
78
|
+
def self.construct(name, desc)
|
79
|
+
Native(desc).merge!(`{ type: name }`).to_n
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.new(value, callback = nil)
|
84
|
+
return super unless self == Event
|
85
|
+
|
86
|
+
klass = class_for(callback ? callback.name : `value.type`)
|
87
|
+
|
88
|
+
if klass == Event
|
89
|
+
super
|
90
|
+
else
|
91
|
+
klass.new(value, callback)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
attr_reader :callback
|
96
|
+
attr_writer :on
|
97
|
+
|
98
|
+
def initialize(event, callback = nil)
|
99
|
+
super(event)
|
100
|
+
|
101
|
+
@callback = callback
|
102
|
+
end
|
103
|
+
|
104
|
+
def name
|
105
|
+
`#@native.type`
|
106
|
+
end
|
107
|
+
|
108
|
+
def on
|
109
|
+
@on || Target.convert(`#@native.currentTarget`)
|
110
|
+
end
|
111
|
+
|
112
|
+
def target
|
113
|
+
Target.convert(`#@native.srcElement || #@native.target`)
|
114
|
+
end
|
115
|
+
|
116
|
+
def arguments
|
117
|
+
`#@native.arguments || []`
|
118
|
+
end
|
119
|
+
|
120
|
+
def arguments=(args)
|
121
|
+
`#@native.arguments = #{args}`
|
122
|
+
end
|
123
|
+
|
124
|
+
alias_native :bubbles?, :bubbles
|
125
|
+
alias_native :cancelable?, :cancelable
|
126
|
+
alias_native :data
|
127
|
+
alias_native :phase, :eventPhase
|
128
|
+
alias_native :at, :timeStamp
|
129
|
+
|
130
|
+
def off
|
131
|
+
@callback.off if @callback
|
132
|
+
end
|
133
|
+
|
134
|
+
def stopped?
|
135
|
+
`!!#@native.stopped`
|
136
|
+
end
|
137
|
+
|
138
|
+
def stop
|
139
|
+
`#@native.stopPropagation()` if defined?(`#@native.stopPropagation`)
|
140
|
+
`#@native.stopped = true`
|
141
|
+
end
|
142
|
+
|
143
|
+
def prevent
|
144
|
+
`#@native.preventDefault()` if defined?(`#@native.preventDefault`)
|
145
|
+
`#@native.prevented = true`
|
146
|
+
end
|
147
|
+
|
148
|
+
def prevented?
|
149
|
+
`!!#@native.prevented`
|
150
|
+
end
|
151
|
+
|
152
|
+
def stop!
|
153
|
+
prevent
|
154
|
+
stop
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
require 'browser/event/ui'
|
161
|
+
require 'browser/event/mouse'
|
162
|
+
require 'browser/event/keyboard'
|
163
|
+
require 'browser/event/custom'
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Browser
|
2
2
|
|
3
|
-
#
|
3
|
+
# An {EventSource} allows you to receive events from a server in real-time,
|
4
|
+
# similar to long-polling but not exactly.
|
5
|
+
#
|
6
|
+
# @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource
|
4
7
|
class EventSource
|
5
8
|
def self.supported?
|
6
|
-
|
9
|
+
Browser.supports? :EventSource
|
7
10
|
end
|
8
11
|
|
9
|
-
include Native
|
10
|
-
include
|
12
|
+
include Native::Wrapper
|
13
|
+
include Event::Target
|
11
14
|
|
12
15
|
target {|value|
|
13
16
|
EventSource.new(value) if Native.is_a?(value, `window.EventSource`)
|