atome-opal-browser 0.3.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +33 -0
- data/Gemfile.lock +122 -0
- data/LICENSE +20 -0
- data/README.md +301 -0
- data/Rakefile +63 -0
- data/bin/rake +7 -0
- data/bin/setup +8 -0
- data/config.ru +81 -0
- data/docs/polyfills.md +24 -0
- data/examples/2048/Gemfile +13 -0
- data/examples/2048/Gemfile.lock +41 -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 +9 -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 +9 -0
- data/examples/component/Gemfile.lock +45 -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 +7 -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 +8 -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 +9 -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 +10 -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 +7 -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 +9 -0
- data/examples/integrations/static-rake-guard/Gemfile.lock +69 -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 +4 -0
- data/lib/opal-browser.rb +1 -0
- data/opal/browser/animation_frame.rb +111 -0
- 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 +63 -0
- data/opal/browser/canvas/gradient.rb +27 -0
- data/opal/browser/canvas/style.rb +115 -0
- data/opal/browser/canvas/text.rb +45 -0
- data/opal/browser/canvas.rb +335 -0
- data/opal/browser/console.rb +105 -0
- data/opal/browser/cookies.rb +171 -0
- data/opal/browser/crypto.rb +79 -0
- data/opal/browser/css/declaration.rb +83 -0
- data/opal/browser/css/rule/style.rb +16 -0
- data/opal/browser/css/rule.rb +48 -0
- data/opal/browser/css/style_sheet.rb +83 -0
- data/opal/browser/css/unit.rb +188 -0
- data/opal/browser/css.rb +40 -0
- data/opal/browser/database/sql.rb +193 -0
- data/opal/browser/delay.rb +94 -0
- data/opal/browser/dom/attribute.rb +26 -0
- data/opal/browser/dom/builder.rb +107 -0
- data/opal/browser/dom/cdata.rb +9 -0
- data/opal/browser/dom/character_data.rb +73 -0
- data/opal/browser/dom/comment.rb +9 -0
- data/opal/browser/dom/document.rb +217 -0
- data/opal/browser/dom/document_fragment.rb +25 -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 +64 -0
- data/opal/browser/dom/element/media.rb +43 -0
- data/opal/browser/dom/element/offset.rb +89 -0
- data/opal/browser/dom/element/position.rb +46 -0
- data/opal/browser/dom/element/scroll.rb +168 -0
- 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 +618 -0
- data/opal/browser/dom/mutation_observer.rb +178 -0
- data/opal/browser/dom/node.rb +504 -0
- data/opal/browser/dom/node_set.rb +121 -0
- data/opal/browser/dom/shadow_root.rb +12 -0
- data/opal/browser/dom/text.rb +36 -0
- data/opal/browser/dom.rb +124 -0
- data/opal/browser/effects.rb +216 -0
- data/opal/browser/event/all.rb +26 -0
- data/opal/browser/event/animation.rb +40 -0
- data/opal/browser/event/audio_processing.rb +35 -0
- 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/event/device_motion.rb +53 -0
- data/opal/browser/event/device_orientation.rb +50 -0
- data/opal/browser/event/device_proximity.rb +35 -0
- 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/event/hash_change.rb +30 -0
- data/opal/browser/event/keyboard.rb +128 -0
- data/opal/browser/event/message.rb +72 -0
- data/opal/browser/event/mouse.rb +258 -0
- 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/event/storage.rb +45 -0
- data/opal/browser/event/touch.rb +62 -0
- data/opal/browser/event/ui.rb +38 -0
- data/opal/browser/event/wheel.rb +51 -0
- data/opal/browser/event.rb +162 -0
- data/opal/browser/event_source.rb +70 -0
- data/opal/browser/form_data.rb +225 -0
- data/opal/browser/history.rb +86 -0
- data/opal/browser/http/binary.rb +58 -0
- data/opal/browser/http/headers.rb +109 -0
- data/opal/browser/http/request.rb +359 -0
- data/opal/browser/http/response.rb +119 -0
- data/opal/browser/http.rb +167 -0
- data/opal/browser/immediate.rb +161 -0
- data/opal/browser/interval.rb +111 -0
- data/opal/browser/location.rb +93 -0
- data/opal/browser/navigator.rb +274 -0
- data/opal/browser/polyfill/visual_viewport.rb +216 -0
- data/opal/browser/screen.rb +66 -0
- 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 +123 -0
- data/opal/browser/storage.rb +252 -0
- data/opal/browser/support.rb +299 -0
- data/opal/browser/utils.rb +154 -0
- data/opal/browser/version.rb +3 -0
- data/opal/browser/visual_viewport.rb +39 -0
- data/opal/browser/window/size.rb +73 -0
- data/opal/browser/window/view.rb +51 -0
- data/opal/browser/window.rb +133 -0
- data/opal/browser.rb +1 -0
- data/opal/opal-browser.rb +1 -0
- data/opal-browser.gemspec +27 -0
- 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 +86 -0
- data/spec/dom/document_spec.rb +62 -0
- 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 +223 -0
- data/spec/dom/mutation_observer_spec.rb +41 -0
- data/spec/dom/node_set_spec.rb +44 -0
- data/spec/dom/node_spec.rb +214 -0
- data/spec/dom_spec.rb +23 -0
- data/spec/event_source_spec.rb +45 -0
- data/spec/event_spec.rb +156 -0
- data/spec/history_spec.rb +61 -0
- data/spec/http_spec.rb +76 -0
- data/spec/immediate_spec.rb +15 -0
- data/spec/interval_spec.rb +59 -0
- data/spec/json2.js +486 -0
- data/spec/native_cached_wrapper_spec.rb +46 -0
- data/spec/runner.rb +107 -0
- data/spec/sizzle.js +5 -0
- data/spec/socket_spec.rb +47 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/spec_helper_promise.rb.erb +25 -0
- data/spec/storage_spec.rb +26 -0
- data/spec/wgxpath.install.js +49 -0
- data/spec/window_spec.rb +10 -0
- metadata +500 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'browser/blob'
|
2
|
+
|
3
|
+
module Browser; class Event
|
4
|
+
|
5
|
+
# {DataTransfer} is an object which manages included data to
|
6
|
+
# an event of type {Event::Drag} or {Event::Clipboard}.
|
7
|
+
class DataTransfer
|
8
|
+
include NativeCachedWrapper
|
9
|
+
|
10
|
+
# @!attribute [rw] effect
|
11
|
+
# @return [Symbol] Effect of this drop operation.
|
12
|
+
# Must be one of: :none, :copy, :link or :move.
|
13
|
+
def effect
|
14
|
+
`#@native.dropEffect`
|
15
|
+
end
|
16
|
+
|
17
|
+
def effect= (effect)
|
18
|
+
`#@native.dropEffect = #{effect}`
|
19
|
+
end
|
20
|
+
|
21
|
+
# Extract some text data from this {DataTransfer} instance.
|
22
|
+
def [] (type)
|
23
|
+
`#@native.getData(#{type})`
|
24
|
+
end
|
25
|
+
|
26
|
+
# Embed some text data in this {DataTransfer} instance.
|
27
|
+
def []= (type, value)
|
28
|
+
`#@native.setData(#{type}, #{Native.convert(value)})`
|
29
|
+
end
|
30
|
+
|
31
|
+
# Clear some (or all, if type is not specified) text data from
|
32
|
+
# this {DataTransfer} instance.
|
33
|
+
def clear (type=nil)
|
34
|
+
`#@native.clearData(#{type.to_n})`
|
35
|
+
end
|
36
|
+
|
37
|
+
# @!attribute [w] drag_image
|
38
|
+
# Sets a drag image for this {DataTransfer}. Use some
|
39
|
+
# {DOM::Element::Image} or {Canvas} as a value.
|
40
|
+
def drag_image= (image)
|
41
|
+
`#@native.setDragImage(#{Native.convert(image)})`
|
42
|
+
end
|
43
|
+
|
44
|
+
# @!attribute [r] files
|
45
|
+
# @return [Array<File>] list of files attached to this {DataTransfer}
|
46
|
+
def files
|
47
|
+
Native::Array.new(`#@native.files`).map { |f| File.new(f.to_n) }
|
48
|
+
end
|
49
|
+
|
50
|
+
# @!attribute [r] items
|
51
|
+
# @return [Array<Item>] list of items attached to this {DataTransfer}
|
52
|
+
def items
|
53
|
+
Native::Array.new(`#@native.items`).map { |i| Item.new(i.to_n) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# An instance of `DataTransferItem`
|
57
|
+
class Item
|
58
|
+
include NativeCachedWrapper
|
59
|
+
|
60
|
+
# @!attribute [r] kind
|
61
|
+
# @return [Symbol] kind of an item: :string or :file
|
62
|
+
def kind
|
63
|
+
`#@native.kind`
|
64
|
+
end
|
65
|
+
|
66
|
+
def string?; kind == 'string'; end
|
67
|
+
def file?; kind == 'file' && to_file; end # Some files can't be resolved...
|
68
|
+
|
69
|
+
# @!attribute [r] type
|
70
|
+
# @return [String] mime type of an item
|
71
|
+
def type
|
72
|
+
`#@native.type`
|
73
|
+
end
|
74
|
+
|
75
|
+
# Convert to string and call back once ready, or return a
|
76
|
+
# promise if a block isn't given.
|
77
|
+
def to_string(&block)
|
78
|
+
promise = nil
|
79
|
+
if !block
|
80
|
+
promise = Promise.new
|
81
|
+
block = proc { |i| promise.resolve(i) }
|
82
|
+
end
|
83
|
+
`#@native.getAsString(#{block.to_n})`
|
84
|
+
return promise
|
85
|
+
end
|
86
|
+
|
87
|
+
# Convert to file or return nil if impossible
|
88
|
+
def to_file
|
89
|
+
as_file = `#@native.getAsFile()`
|
90
|
+
File.new(as_file) if as_file
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end; end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class DeviceLight < Event
|
4
|
+
handles 'devicelight'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.DeviceLight'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def value=(value)
|
12
|
+
`#@native.value = #{value}`
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if Browser.supports? 'Event.constructor'
|
17
|
+
def self.construct(name, desc)
|
18
|
+
`new DeviceLightEvent(#{name}, #{desc})`
|
19
|
+
end
|
20
|
+
end if supported?
|
21
|
+
|
22
|
+
alias_native :value
|
23
|
+
end
|
24
|
+
|
25
|
+
end; end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class DeviceMotion < Event
|
4
|
+
handles 'devicemotion'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.DeviceMotion'
|
8
|
+
end
|
9
|
+
|
10
|
+
Acceleration = Struct.new(:x, :y, :z)
|
11
|
+
|
12
|
+
class Definition < Definition
|
13
|
+
def acceleration=(value)
|
14
|
+
`#@native.acceleration = #{value.to_n}`
|
15
|
+
end
|
16
|
+
|
17
|
+
def acceleration_with_gravity=(value)
|
18
|
+
`#@native.accelerationIncludingGravity = #{value.to_n}`
|
19
|
+
end
|
20
|
+
|
21
|
+
def rotation=(value)
|
22
|
+
`#@native.rotationRate = #{value}`
|
23
|
+
end
|
24
|
+
|
25
|
+
def interval=(value)
|
26
|
+
`#@native.interval = #{value}`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if Browser.supports? 'Event.constructor'
|
31
|
+
def self.construct(name, desc)
|
32
|
+
`new DeviceMotionEvent(#{name}, #{desc})`
|
33
|
+
end
|
34
|
+
elsif Browser.supports? 'Event.create'
|
35
|
+
def self.construct(name, desc)
|
36
|
+
%x{
|
37
|
+
var event = document.createEvent("DeviceMotionEvent");
|
38
|
+
event.initDeviceMotionEvent(name, desc.bubbles, desc.cancelable,
|
39
|
+
desc.acceleration, desc.accelerationIncludingGravity,
|
40
|
+
desc.rotationRate, desc.interval);
|
41
|
+
|
42
|
+
return event;
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end if supported?
|
46
|
+
|
47
|
+
alias_native :acceleration
|
48
|
+
alias_native :acceleration_with_gravity, :accelerationIncludingGravity
|
49
|
+
alias_native :rotation, :rotationRate
|
50
|
+
alias_native :interval
|
51
|
+
end
|
52
|
+
|
53
|
+
end; end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class DeviceOrientation < Event
|
4
|
+
handles 'deviceorientation'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.DeviceOrientation'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def absolute=(value)
|
12
|
+
`#@native.absolute = #{value}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def alpha=(value)
|
16
|
+
`#@native.alpha = #{value}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def beta=(value)
|
20
|
+
`#@native.beta = #{value}`
|
21
|
+
end
|
22
|
+
|
23
|
+
def gamma=(value)
|
24
|
+
`#@native.gamma = #{value}`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if Browser.supports? 'Event.constructor'
|
29
|
+
def self.construct(name, desc)
|
30
|
+
`new DeviceOrientationEvent(#{name}, #{desc})`
|
31
|
+
end
|
32
|
+
elsif Browser.supports? 'Event.create'
|
33
|
+
def self.construct(name, desc)
|
34
|
+
%x{
|
35
|
+
var event = document.createEvent("DeviceOrientationEvent");
|
36
|
+
event.initDeviceOrientationEvent(name, desc.bubbles, desc.cancelable,
|
37
|
+
desc.alpha, desc.beta, desc.gamma, desc.absolute);
|
38
|
+
|
39
|
+
return event;
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end if supported?
|
43
|
+
|
44
|
+
alias_native :absolute
|
45
|
+
alias_native :alpha
|
46
|
+
alias_native :beta
|
47
|
+
alias_native :gamma
|
48
|
+
end
|
49
|
+
|
50
|
+
end; end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class DeviceProximity < Event
|
4
|
+
handles 'deviceproximity'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.DeviceProximity'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def value=(value)
|
12
|
+
`#@native.value = #{value}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def min=(value)
|
16
|
+
`#@native.min = #{value}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def max=(value)
|
20
|
+
`#@native.max = #{value}`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if Browser.supports? 'Event.constructor'
|
25
|
+
def self.construct(name, desc)
|
26
|
+
`new DeviceProximityEvent(#{name}, #{desc})`
|
27
|
+
end
|
28
|
+
end if supported?
|
29
|
+
|
30
|
+
alias_native :value
|
31
|
+
alias_native :min
|
32
|
+
alias_native :max
|
33
|
+
end
|
34
|
+
|
35
|
+
end; end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Drag < Event
|
4
|
+
handles 'drag', 'dragend', 'dragenter', 'dragexit', 'dragleave', 'dragover',
|
5
|
+
'dragstart', 'drop'
|
6
|
+
|
7
|
+
def self.supported?
|
8
|
+
Browser.supports? 'Event.Drag'
|
9
|
+
end
|
10
|
+
|
11
|
+
class Definition < Definition
|
12
|
+
class Client
|
13
|
+
include Native::Wrapper
|
14
|
+
|
15
|
+
def x=(value)
|
16
|
+
`#@native.clientX = #{value}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def y=(value)
|
20
|
+
`#@native.clientY = #{value}`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Screen
|
25
|
+
include Native::Wrapper
|
26
|
+
|
27
|
+
def x=(value)
|
28
|
+
`#@native.screenX = #{value}`
|
29
|
+
end
|
30
|
+
|
31
|
+
def y=(value)
|
32
|
+
`#@native.screenY = #{value}`
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def alt!
|
37
|
+
`#@native.altKey = true`
|
38
|
+
end
|
39
|
+
|
40
|
+
def ctrl!
|
41
|
+
`#@native.ctrlKey = true`
|
42
|
+
end
|
43
|
+
|
44
|
+
def meta!
|
45
|
+
`#@native.metaKey = true`
|
46
|
+
end
|
47
|
+
|
48
|
+
def button=(value)
|
49
|
+
`#@native.button = #{value}`
|
50
|
+
end
|
51
|
+
|
52
|
+
def client
|
53
|
+
Client.new(@native)
|
54
|
+
end
|
55
|
+
|
56
|
+
def screen
|
57
|
+
Screen.new(@native)
|
58
|
+
end
|
59
|
+
|
60
|
+
def related=(elem)
|
61
|
+
`#@native.relatedTarget = #{Native.convert(elem)}`
|
62
|
+
end
|
63
|
+
|
64
|
+
def transfer=(value)
|
65
|
+
`#@native.dataTransfer = #{Native.convert(value)}`
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if Browser.supports? 'Event.constructor'
|
70
|
+
def self.construct(name, desc)
|
71
|
+
`new DragEvent(#{name}, #{desc})`
|
72
|
+
end
|
73
|
+
elsif Browser.supports? 'Event.create'
|
74
|
+
def self.construct(name, desc)
|
75
|
+
%x{
|
76
|
+
var event = document.createEvent("DragEvent");
|
77
|
+
event.initDragEvent(name, desc.bubbles, desc.cancelable,
|
78
|
+
desc.view || window, 0,
|
79
|
+
desc.screenX || 0, desc.screenY || 0,
|
80
|
+
desc.clientX || 0, desc.clientY || 0,
|
81
|
+
desc.ctrlKey, desc.altKey, desc.shiftKey, desc.metaKey,
|
82
|
+
desc.button || 0, desc.relatedTarget, desc.dataTransfer);
|
83
|
+
|
84
|
+
return event;
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end if supported?
|
88
|
+
|
89
|
+
alias_native :alt?, :altKey
|
90
|
+
alias_native :ctrl?, :ctrlKey
|
91
|
+
alias_native :meta?, :metaKey
|
92
|
+
alias_native :shift?, :shiftKey
|
93
|
+
alias_native :button
|
94
|
+
|
95
|
+
def client
|
96
|
+
Position.new(`#@native.clientX`, `#@native.clientY`)
|
97
|
+
end
|
98
|
+
|
99
|
+
def screen
|
100
|
+
Position.new(`#@native.screenX`, `#@native.screenY`) if defined?(`#@native.screenX`)
|
101
|
+
end
|
102
|
+
|
103
|
+
def x
|
104
|
+
screen.x
|
105
|
+
end
|
106
|
+
|
107
|
+
def y
|
108
|
+
screen.y
|
109
|
+
end
|
110
|
+
|
111
|
+
def related
|
112
|
+
DOM(`#@native.relatedTarget`)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns a {DataTransfer} related to this event
|
116
|
+
#
|
117
|
+
# @see https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
|
118
|
+
def transfer
|
119
|
+
DataTransfer.new(`#@native.dataTransfer`)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end; end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Focus < UI
|
4
|
+
handles 'blur', 'focus', 'focusin', 'focusout'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.Focus'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < UI::Definition
|
11
|
+
def view=(value)
|
12
|
+
`#@native.view = #{Native.convert(value)}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def related=(elem)
|
16
|
+
`#@native.relatedTarget = #{Native.convert(elem)}`
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if Browser.supports? 'Event.constructor'
|
21
|
+
def self.construct(name, desc)
|
22
|
+
`new FocusEvent(#{name}, #{desc})`
|
23
|
+
end
|
24
|
+
elsif Browser.supports? 'Event.create'
|
25
|
+
def self.construct(name, desc)
|
26
|
+
%x{
|
27
|
+
var event = document.createEvent("FocusEvent");
|
28
|
+
event.initFocusEvent(name, desc.bubbles, desc.cancelable,
|
29
|
+
desc.view || window, 0, desc.relatedTarget);
|
30
|
+
|
31
|
+
return event;
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end if supported?
|
35
|
+
|
36
|
+
def related
|
37
|
+
DOM(`#@native.relatedTarget`)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end; end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Gamepad < Event
|
4
|
+
handles 'gamepadconnected', 'gamepaddisconnected'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.Gamepad'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def id=(value)
|
12
|
+
`#@native.id = #{value}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def index=(value)
|
16
|
+
`#@native.index = #{value}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def at=(value)
|
20
|
+
`#@native.timestamp = #{value}`
|
21
|
+
end
|
22
|
+
|
23
|
+
def axes=(value)
|
24
|
+
`#@native.axes = #{value}`
|
25
|
+
end
|
26
|
+
|
27
|
+
def buttons=(value)
|
28
|
+
`#@native.buttons = #{value}`
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if Browser.supports? 'Event.constructor'
|
33
|
+
def self.construct(name, desc)
|
34
|
+
`return new GamepadEvent(#{name}, {
|
35
|
+
bubbles: desc.bubbles,
|
36
|
+
cancelable: desc.cancelable,
|
37
|
+
gamepad: desc })`
|
38
|
+
end
|
39
|
+
end if supported?
|
40
|
+
|
41
|
+
def id
|
42
|
+
`#@native.gamepad.id`
|
43
|
+
end
|
44
|
+
|
45
|
+
def index
|
46
|
+
`#@native.gamepad.index`
|
47
|
+
end
|
48
|
+
|
49
|
+
def at
|
50
|
+
`#@native.gamepad.timestamp`
|
51
|
+
end
|
52
|
+
|
53
|
+
def axes
|
54
|
+
`#@native.gamepad.axes`
|
55
|
+
end
|
56
|
+
|
57
|
+
def buttons
|
58
|
+
`#@native.gamepad.buttons`
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end; end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class HashChange < Event
|
4
|
+
handles 'hashchange'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.HashChange'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < Definition
|
11
|
+
def old=(value)
|
12
|
+
`#@native.oldURL = #{value}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def new=(value)
|
16
|
+
`#@native.newURL = #{value}`
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if Browser.supports? 'Event.constructor'
|
21
|
+
def self.construct(name, desc)
|
22
|
+
`new HashChangeEvent(#{name}, #{desc})`
|
23
|
+
end
|
24
|
+
end if supported?
|
25
|
+
|
26
|
+
alias_native :old, :oldURL
|
27
|
+
alias_native :new, :newURL
|
28
|
+
end
|
29
|
+
|
30
|
+
end; end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Browser; class Event
|
2
|
+
|
3
|
+
class Keyboard < UI
|
4
|
+
handles 'keydown', 'keypress', 'keyup'
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
Browser.supports? 'Event.Keyboard'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Definition < UI::Definition
|
11
|
+
def alt!
|
12
|
+
`#@native.altKey = true`
|
13
|
+
end
|
14
|
+
|
15
|
+
def ctrl!
|
16
|
+
`#@native.ctrlKey = true`
|
17
|
+
end
|
18
|
+
|
19
|
+
def meta!
|
20
|
+
`#@native.metaKey = true`
|
21
|
+
end
|
22
|
+
|
23
|
+
def shift!
|
24
|
+
`#@native.shiftKey = true`
|
25
|
+
end
|
26
|
+
|
27
|
+
def code=(code)
|
28
|
+
`#@native.keyCode = #@native.which = #{code}`
|
29
|
+
end
|
30
|
+
|
31
|
+
def key=(key)
|
32
|
+
`#@native.key = #{key}`
|
33
|
+
end
|
34
|
+
|
35
|
+
def char=(char)
|
36
|
+
`#@native.char = #@native.charCode = #{char}`
|
37
|
+
end
|
38
|
+
|
39
|
+
def repeat!
|
40
|
+
`#@native.repeat = true`
|
41
|
+
end
|
42
|
+
|
43
|
+
def locale=(value)
|
44
|
+
`#@native.locale = value`
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if Browser.supports? 'Event.constructor'
|
49
|
+
def self.construct(name, desc)
|
50
|
+
`new KeyboardEvent(#{name}, #{desc})`
|
51
|
+
end
|
52
|
+
elsif Browser.supports? 'Event.create'
|
53
|
+
def self.construct(name, desc)
|
54
|
+
%x{
|
55
|
+
var modifiers = "";
|
56
|
+
|
57
|
+
if (desc.altKey) {
|
58
|
+
modifiers += "Alt ";
|
59
|
+
}
|
60
|
+
|
61
|
+
if (desc.ctrlKey) {
|
62
|
+
modifiers += "Ctrl ";
|
63
|
+
}
|
64
|
+
|
65
|
+
if (desc.shiftKey) {
|
66
|
+
modifiers += "Shift" ;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (desc.metaKey) {
|
70
|
+
modifiers += "Meta ";
|
71
|
+
}
|
72
|
+
|
73
|
+
var event = document.createEvent("KeyboardEvent");
|
74
|
+
event.initKeyboardEvent(name, desc.bubbles, desc.cancelable,
|
75
|
+
desc.view || window, desc.which, 0,
|
76
|
+
modifiers, desc.repeat, desc.locale);
|
77
|
+
|
78
|
+
return event;
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end if supported?
|
82
|
+
|
83
|
+
alias_native :alt?, :altKey
|
84
|
+
alias_native :ctrl?, :ctrlKey
|
85
|
+
alias_native :meta?, :metaKey
|
86
|
+
alias_native :shift?, :shiftKey
|
87
|
+
alias_native :locale
|
88
|
+
alias_native :repeat?, :repeat
|
89
|
+
|
90
|
+
# IE 11 at least has different names for those keys.
|
91
|
+
IE_MAP = {
|
92
|
+
'Down' => 'ArrowDown',
|
93
|
+
'Up' => 'ArrowUp',
|
94
|
+
'Left' => 'ArrowLeft',
|
95
|
+
'Right' => 'ArrowRight',
|
96
|
+
'Esc' => 'Escape',
|
97
|
+
'Del' => 'Delete'
|
98
|
+
}
|
99
|
+
|
100
|
+
def key
|
101
|
+
key = `#@native.key || #@native.keyIdentifier || nil`
|
102
|
+
IE_MAP[key] || key
|
103
|
+
end
|
104
|
+
|
105
|
+
def code
|
106
|
+
`#@native.keyCode || #@native.which || nil`
|
107
|
+
end
|
108
|
+
|
109
|
+
def char
|
110
|
+
`#@native.char || #@native.charCode || #{code ? code.chr : nil}`
|
111
|
+
end
|
112
|
+
|
113
|
+
alias to_i key
|
114
|
+
|
115
|
+
def down?
|
116
|
+
name.downcase == 'keydown'
|
117
|
+
end
|
118
|
+
|
119
|
+
def press?
|
120
|
+
name.downcase == 'keypress'
|
121
|
+
end
|
122
|
+
|
123
|
+
def up?
|
124
|
+
name.downcase == 'keyup'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end; end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'buffer'
|
2
|
+
|
3
|
+
module Browser; class Event
|
4
|
+
|
5
|
+
class Message < Event
|
6
|
+
handles 'message'
|
7
|
+
|
8
|
+
def self.supported?
|
9
|
+
Browser.supports? 'Event.Message'
|
10
|
+
end
|
11
|
+
|
12
|
+
class Definition < Definition
|
13
|
+
def data=(value)
|
14
|
+
`#@native.data = value`
|
15
|
+
end
|
16
|
+
|
17
|
+
def origin=(value)
|
18
|
+
`#@native.origin = value`
|
19
|
+
end
|
20
|
+
|
21
|
+
def source=(value)
|
22
|
+
`#@native.source = #{Native.convert(value)}`
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if Browser.supports? 'Event.constructor'
|
27
|
+
def self.construct(name, desc)
|
28
|
+
`new MessageEvent(#{name}, #{desc})`
|
29
|
+
end
|
30
|
+
elsif Browser.supports? 'Event.create'
|
31
|
+
def self.construct(name, desc)
|
32
|
+
%x{
|
33
|
+
var event = document.createEvent("MessageEvent");
|
34
|
+
event.initMessageEvent(name, desc.bubbles, desc.cancelable,
|
35
|
+
desc.data, desc.origin, "", desc.source || window);
|
36
|
+
|
37
|
+
return event;
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end if supported?
|
41
|
+
|
42
|
+
def data
|
43
|
+
%x{
|
44
|
+
if (window.ArrayBuffer && #@native.data instanceof ArrayBuffer) {
|
45
|
+
return #{Buffer.new(`#@native.data`)};
|
46
|
+
}
|
47
|
+
else if (window.Blob && #@native.data instanceof Blob) {
|
48
|
+
return #{Blob.new(`#@native.data`)};
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
return #@native.data;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_native :origin
|
57
|
+
|
58
|
+
def source
|
59
|
+
%x{
|
60
|
+
var source = #@native.source;
|
61
|
+
|
62
|
+
if (window.Window && source instanceof window.Window) {
|
63
|
+
return #{Window.new(`source`)};
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
return nil;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end; end
|