opal-browser 0.1.0.beta1 → 0.2.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +60 -0
- data/.yardopts +1 -1
- data/Gemfile +7 -2
- data/LICENSE +19 -0
- data/README.md +74 -10
- data/config.ru +2 -1
- data/index.html.erb +22 -0
- data/opal-browser.gemspec +9 -11
- data/opal/browser.rb +1 -1
- data/opal/browser/animation_frame.rb +66 -9
- data/opal/browser/canvas.rb +72 -18
- data/opal/browser/canvas/data.rb +1 -1
- data/opal/browser/console.rb +3 -37
- data/opal/browser/cookies.rb +80 -24
- data/opal/browser/css/declaration.rb +0 -5
- data/opal/browser/{timeout.rb → delay.rb} +13 -13
- data/opal/browser/dom.rb +0 -2
- data/opal/browser/dom/attribute.rb +6 -0
- data/opal/browser/dom/builder.rb +4 -8
- data/opal/browser/dom/character_data.rb +43 -7
- data/opal/browser/dom/document.rb +13 -11
- data/opal/browser/dom/element.rb +127 -29
- data/opal/browser/dom/element/image.rb +23 -0
- data/opal/browser/dom/element/offset.rb +27 -10
- data/opal/browser/dom/element/scroll.rb +32 -12
- data/opal/browser/dom/element/size.rb +29 -0
- data/opal/browser/dom/event.rb +88 -75
- data/opal/browser/dom/event/animation.rb +16 -4
- data/opal/browser/dom/event/audio_processing.rb +6 -4
- data/opal/browser/dom/event/base.rb +229 -64
- data/opal/browser/dom/event/before_unload.rb +6 -4
- data/opal/browser/dom/event/clipboard.rb +6 -4
- data/opal/browser/dom/event/close.rb +16 -4
- data/opal/browser/dom/event/composition.rb +16 -4
- data/opal/browser/dom/event/custom.rb +43 -8
- data/opal/browser/dom/event/device_light.rb +6 -4
- data/opal/browser/dom/event/device_motion.rb +17 -4
- data/opal/browser/dom/event/device_orientation.rb +16 -4
- data/opal/browser/dom/event/device_proximity.rb +6 -4
- data/opal/browser/dom/event/drag.rb +34 -28
- data/opal/browser/dom/event/focus.rb +21 -5
- data/opal/browser/dom/event/gamepad.rb +33 -20
- data/opal/browser/dom/event/hash_change.rb +6 -4
- data/opal/browser/dom/event/keyboard.rb +45 -23
- data/opal/browser/dom/event/message.rb +28 -8
- data/opal/browser/dom/event/mouse.rb +26 -25
- data/opal/browser/dom/event/page_transition.rb +6 -4
- data/opal/browser/dom/event/pop_state.rb +16 -4
- data/opal/browser/dom/event/progress.rb +16 -4
- data/opal/browser/dom/event/sensor.rb +6 -4
- data/opal/browser/dom/event/storage.rb +6 -4
- data/opal/browser/dom/event/touch.rb +10 -19
- data/opal/browser/dom/event/ui.rb +19 -3
- data/opal/browser/dom/event/wheel.rb +2 -2
- data/opal/browser/dom/mutation_observer.rb +65 -5
- data/opal/browser/dom/node.rb +164 -59
- data/opal/browser/dom/node_set.rb +4 -0
- data/opal/browser/dom/text.rb +16 -1
- data/opal/browser/event_source.rb +5 -2
- data/opal/browser/history.rb +51 -15
- data/opal/browser/http.rb +22 -7
- data/opal/browser/http/headers.rb +5 -0
- data/opal/browser/http/request.rb +40 -10
- data/opal/browser/immediate.rb +123 -9
- data/opal/browser/interval.rb +8 -13
- data/opal/browser/location.rb +13 -3
- data/opal/browser/navigator.rb +9 -6
- data/opal/browser/screen.rb +31 -5
- data/opal/browser/socket.rb +8 -4
- data/opal/browser/storage.rb +118 -33
- data/opal/browser/support.rb +232 -0
- data/opal/browser/utils.rb +24 -6
- data/opal/browser/version.rb +1 -1
- data/opal/browser/window.rb +1 -2
- data/opal/browser/window/scroll.rb +21 -11
- data/opal/browser/window/size.rb +16 -6
- data/opal/browser/window/view.rb +23 -5
- data/spec/dom/builder_spec.rb +19 -19
- data/spec/dom/document_spec.rb +6 -6
- data/spec/dom/element_spec.rb +5 -5
- data/spec/dom/event_spec.rb +20 -20
- data/spec/dom/mutation_observer_spec.rb +5 -5
- data/spec/dom/node_spec.rb +39 -27
- data/spec/dom_spec.rb +10 -8
- data/spec/event_source_spec.rb +12 -12
- data/spec/history_spec.rb +24 -15
- data/spec/http_spec.rb +18 -17
- data/spec/immediate_spec.rb +9 -7
- data/spec/runner.rb +114 -0
- data/spec/socket_spec.rb +8 -8
- data/spec/spec_helper.rb +1 -0
- data/spec/storage_spec.rb +6 -6
- data/spec/wgxpath.install.js +49 -0
- data/spec/window_spec.rb +2 -2
- metadata +21 -54
- data/opal/browser/compatibility.rb +0 -59
- 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/dom/compatibility.rb +0 -8
- data/opal/browser/http/compatibility.rb +0 -1
- data/opal/browser/window/compatibility.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b0aa6c5110fd5e167607dbdea62c227163d95be
|
|
4
|
+
data.tar.gz: 666fc17d0cb5be69e9acf8a2f2d526e4995b7496
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bdb5103e7c85d23815225544ee28a504a024cc61beb58c5ca77e1af6c0b33853c6bc0b5cc530975039f28151572b423725e6abc7bf5aa22bd4fe82ec4ef68ed8
|
|
7
|
+
data.tar.gz: 4c08aa42993c6e63623dae9d5b9b09ed722801bf771c1527c56bb0791807958ffbb2d5c80904ae457c0686cf15ea597176de7269f9862a0d014f7171d7597f35
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
rvm: 2.0.0
|
|
3
|
+
cache: bundler
|
|
4
|
+
|
|
5
|
+
env:
|
|
6
|
+
global:
|
|
7
|
+
- SELENIUM_HOST=hub.browserstack.com
|
|
8
|
+
- SELENIUM_PORT=80
|
|
9
|
+
|
|
10
|
+
- BS_AUTOMATE_PROJECT="$TRAVIS_REPO_SLUG"
|
|
11
|
+
- BS_AUTOMATE_BUILD="Travis build No. $TRAVIS_BUILD_NUMBER for $TRAVIS_REPO_SLUG"
|
|
12
|
+
- secure: "L70bh0nIOaIoS7Va4Mr0GsdRlAjOILsNNrfwFDr3RjM2HaR3oeEKK1tJIEDEMamgBw6Ljhz7EWdDwt3bQ0HrhO9cI0kuzl+dA9Obf3+gucPSdi8QCZbjZDkwA56srsDEAMGAKkNWI1kmQTbPUPUoIuKmjj3Y3T68Ud2qi+hi5ag="
|
|
13
|
+
- secure: "T7RSwd/aIYwsbuoyLPLzB0ZwOATDAFrpi9GQSVIbV1rZV2oGq+yisjeARUPyRfKTI0Q08CNgarLWfL/kONR6AL19XUD3Rm1+hag8bNixRYot2c65We6d40BMtPfZyO13kSWlTtDnzotYavhXoXujJNLfSjbdLdTlmy2m9Q0UfQc="
|
|
14
|
+
|
|
15
|
+
matrix:
|
|
16
|
+
- SELENIUM_BROWSER=firefox SELENIUM_VERSION=25
|
|
17
|
+
- SELENIUM_BROWSER=firefox SELENIUM_VERSION=26
|
|
18
|
+
|
|
19
|
+
- SELENIUM_BROWSER=safari SELENIUM_VERSION=5.1
|
|
20
|
+
- SELENIUM_BROWSER=safari SELENIUM_VERSION=6.1
|
|
21
|
+
- SELENIUM_BROWSER=safari SELENIUM_VERSION=7.0
|
|
22
|
+
|
|
23
|
+
- SELENIUM_BROWSER=opera SELENIUM_VERSION=12.15
|
|
24
|
+
- SELENIUM_BROWSER=opera SELENIUM_VERSION=12.16
|
|
25
|
+
|
|
26
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=6
|
|
27
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=7
|
|
28
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=8
|
|
29
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=9
|
|
30
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=10
|
|
31
|
+
- SELENIUM_BROWSER=ie SELENIUM_VERSION=11
|
|
32
|
+
|
|
33
|
+
- SELENIUM_BROWSER=chrome SELENIUM_VERSION=30
|
|
34
|
+
- SELENIUM_BROWSER=chrome SELENIUM_VERSION=31
|
|
35
|
+
|
|
36
|
+
matrix:
|
|
37
|
+
allow_failures:
|
|
38
|
+
# I know these fail
|
|
39
|
+
- env: SELENIUM_BROWSER=ie SELENIUM_VERSION=6
|
|
40
|
+
- env: SELENIUM_BROWSER=ie SELENIUM_VERSION=7
|
|
41
|
+
|
|
42
|
+
# ChromeDriver be broken
|
|
43
|
+
- env: SELENIUM_BROWSER=chrome SELENIUM_VERSION=31
|
|
44
|
+
- env: SELENIUM_BROWSER=chrome SELENIUM_VERSION=30
|
|
45
|
+
|
|
46
|
+
before_install:
|
|
47
|
+
- gem update bundler
|
|
48
|
+
- bundle --version
|
|
49
|
+
- gem update --system
|
|
50
|
+
- gem --version
|
|
51
|
+
|
|
52
|
+
before_script:
|
|
53
|
+
- bundle exec rackup -p 9292 &
|
|
54
|
+
- sleep 10
|
|
55
|
+
|
|
56
|
+
script:
|
|
57
|
+
- bundle exec spec/runner.rb
|
|
58
|
+
|
|
59
|
+
notifications:
|
|
60
|
+
irc: "irc.freenode.org#opal"
|
data/.yardopts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
--no-private opal/**/*.rb
|
|
1
|
+
--no-private opal/**/*.rb --markup markdown
|
data/Gemfile
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# specs
|
|
5
5
|
gem 'rack'
|
|
6
6
|
gem 'sinatra'
|
|
7
7
|
gem 'sinatra-websocket'
|
|
8
|
+
gem 'opal-rspec', '0.3.0.beta3'
|
|
8
9
|
|
|
10
|
+
# runner
|
|
11
|
+
gem 'selenium-webdriver', require: false
|
|
12
|
+
gem 'rest-client', require: false
|
|
13
|
+
|
|
14
|
+
# browser
|
|
9
15
|
gem 'opal', github: 'opal/opal'
|
|
10
|
-
gem 'opal-rspec', '0.3.0.beta2'
|
|
11
16
|
gem 'paggio', github: 'meh/paggio'
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (C) 2014 by meh
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
Browser support for Opal
|
|
2
2
|
========================
|
|
3
|
+
|
|
4
|
+
[](http://travis-ci.org/opal/opal-browser)
|
|
5
|
+
[](http://badge.fury.io/rb/opal-browser)
|
|
6
|
+
[](https://codeclimate.com/github/opal/opal-browser)
|
|
7
|
+
|
|
3
8
|
This library aims to be a full-blown wrapper for all the browser API including
|
|
4
9
|
HTML5.
|
|
5
10
|
|
|
@@ -13,7 +18,7 @@ DOM support is complete as far as I know, it has a very Nokogiri feel to it
|
|
|
13
18
|
with obvious differences where relevant (for instance, event handling).
|
|
14
19
|
|
|
15
20
|
```ruby
|
|
16
|
-
$document.on :load do
|
|
21
|
+
$document.on 'dom:load' do
|
|
17
22
|
alert "yo dawg, I'm all loaded up in here"
|
|
18
23
|
end
|
|
19
24
|
```
|
|
@@ -22,7 +27,7 @@ It also supports a markaby inspired builder DSL which generates DOM nodes
|
|
|
22
27
|
directly instead of creating a string.
|
|
23
28
|
|
|
24
29
|
```ruby
|
|
25
|
-
$document.on :load do
|
|
30
|
+
$document.on 'dom:load' do
|
|
26
31
|
DOM {
|
|
27
32
|
div.info {
|
|
28
33
|
span.red "I'm all cooked up."
|
|
@@ -93,14 +98,73 @@ Storage
|
|
|
93
98
|
The HTML5 Storage API has been wrapped and it exports a single Storage class
|
|
94
99
|
that uses the most appropriate and available API to store data locally.
|
|
95
100
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
Browser support
|
|
102
|
+
===============
|
|
103
|
+
|
|
104
|
+
* Internet Explorer 6+
|
|
105
|
+
* Firefox (Current - 1) or Current
|
|
106
|
+
* Chrome (Current - 1) or Current
|
|
107
|
+
* Safari 5.1+
|
|
108
|
+
* Opera 12.1x or (Current - 1) or Current
|
|
109
|
+
|
|
110
|
+
Any problem above browsers should be considered and reported as a bug.
|
|
111
|
+
|
|
112
|
+
(Current - 1) or Current denotes that we support the current stable version of
|
|
113
|
+
the browser and the version that preceded it. For example, if the current
|
|
114
|
+
version of a browser is 24.x, we support the 24.x and 23.x versions.
|
|
115
|
+
|
|
116
|
+
12.1x or (Current - 1) or Current denotes that we support Opera 12.1x as well
|
|
117
|
+
as last 2 versions of Opera. For example, if the current Opera version is 20.x,
|
|
118
|
+
we support Opera 12.1x, 19.x and 20.x but not Opera 15.x through 18.x.
|
|
119
|
+
|
|
120
|
+
Cross-browser testing sponsored by [BrowserStack](http://browserstack.com).
|
|
121
|
+
|
|
122
|
+
CSS selectors
|
|
123
|
+
-------------
|
|
124
|
+
Older browsers do not support CSS selector in queries, this means you'll need
|
|
125
|
+
external polyfills for this.
|
|
126
|
+
|
|
127
|
+
The suggested polyfill is [Sizzle](http://sizzlejs.com/), require it **before**
|
|
128
|
+
opal-browser.
|
|
129
|
+
|
|
130
|
+
JSON parsing
|
|
131
|
+
------------
|
|
132
|
+
Older browsers don't support JSON parsing natively, this means you'll need
|
|
133
|
+
external polyfills for this.
|
|
134
|
+
|
|
135
|
+
The suggested polyfill is [json2](https://github.com/douglascrockford/JSON-js),
|
|
136
|
+
require it **before** opal-browser.
|
|
137
|
+
|
|
138
|
+
XPath support
|
|
139
|
+
-------------
|
|
140
|
+
Not all browsers support XPath queries, I'm looking at you Internet Explorer,
|
|
141
|
+
this means you'll need external polyfills for this.
|
|
142
|
+
|
|
143
|
+
The suggested polyfill is
|
|
144
|
+
[wgxpath](https://code.google.com/p/wicked-good-xpath/), require it **before**
|
|
145
|
+
opal-browser.
|
|
146
|
+
|
|
147
|
+
License
|
|
148
|
+
=======
|
|
149
|
+
|
|
150
|
+
(The MIT License)
|
|
151
|
+
|
|
152
|
+
Copyright (C) 2014 by meh
|
|
100
153
|
|
|
101
|
-
|
|
102
|
-
|
|
154
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
155
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
156
|
+
in the Software without restriction, including without limitation the rights
|
|
157
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
158
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
159
|
+
furnished to do so, subject to the following conditions:
|
|
103
160
|
|
|
104
|
-
|
|
161
|
+
The above copyright notice and this permission notice shall be included in
|
|
162
|
+
all copies or substantial portions of the Software.
|
|
105
163
|
|
|
106
|
-
|
|
164
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
165
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
166
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
167
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
168
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
169
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
170
|
+
THE SOFTWARE.
|
data/config.ru
CHANGED
data/index.html.erb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Opal Browser - RSpec Runner</title>
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
window.onerror = function(msg, url, line) {
|
|
8
|
+
var error = document.createElement("div");
|
|
9
|
+
error.setAttribute("id", "rspec-error");
|
|
10
|
+
error.innerHTML = "Error: " + msg + "<br/>";
|
|
11
|
+
error.innerHTML += "Line: " + line + "<br/>";
|
|
12
|
+
error.innerHTML += "URL: " + url + "<br/>";
|
|
13
|
+
|
|
14
|
+
document.body.appendChild(error);
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<%= javascript_include_tag @server.main %>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
|
22
|
+
|
data/opal-browser.gemspec
CHANGED
|
@@ -2,22 +2,20 @@ $LOAD_PATH << File.expand_path('../opal', __FILE__)
|
|
|
2
2
|
require 'browser/version'
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new {|s|
|
|
5
|
-
s.name
|
|
6
|
-
s.version
|
|
7
|
-
s.author
|
|
8
|
-
s.email
|
|
9
|
-
s.homepage
|
|
10
|
-
s.platform
|
|
11
|
-
s.summary
|
|
5
|
+
s.name = 'opal-browser'
|
|
6
|
+
s.version = Browser::VERSION
|
|
7
|
+
s.author = 'meh.'
|
|
8
|
+
s.email = 'meh@schizofreni.co'
|
|
9
|
+
s.homepage = 'http://github.com/opal/opal-browser'
|
|
10
|
+
s.platform = Gem::Platform::RUBY
|
|
11
|
+
s.summary = 'Browser support for Opal.'
|
|
12
|
+
s.license = 'MIT'
|
|
12
13
|
|
|
13
14
|
s.files = `git ls-files`.split("\n")
|
|
14
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
15
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
17
|
s.require_paths = ['lib']
|
|
17
18
|
|
|
18
|
-
s.add_dependency 'opal', '
|
|
19
|
+
s.add_dependency 'opal', '~> 0.6.0'
|
|
19
20
|
s.add_dependency 'paggio'
|
|
20
|
-
|
|
21
|
-
s.add_development_dependency 'opal-rspec'
|
|
22
|
-
s.add_development_dependency 'rake'
|
|
23
21
|
}
|
data/opal/browser.rb
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
require 'browser/compatibility/animation_frame'
|
|
2
|
-
|
|
3
1
|
module Browser
|
|
4
2
|
|
|
5
|
-
# FIXME: drop the method_defined? checks when require order is fixed
|
|
6
3
|
class AnimationFrame
|
|
7
4
|
def initialize(window, &block)
|
|
8
5
|
@window = window
|
|
@@ -10,13 +7,73 @@ class AnimationFrame
|
|
|
10
7
|
@id = request(block)
|
|
11
8
|
end
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if Browser.supports? 'Animation.request'
|
|
11
|
+
def request(block)
|
|
12
|
+
`#@native.requestAnimationFrame(#{block.to_n})`
|
|
13
|
+
end
|
|
14
|
+
elsif Browser.supports? 'Animation.request (Chrome)'
|
|
15
|
+
def request(block)
|
|
16
|
+
`#@native.webkitRequestAnimationFrame(#{block.to_n})`
|
|
17
|
+
end
|
|
18
|
+
elsif Browser.supports? 'Animation.request (Firefox)'
|
|
19
|
+
def request(block)
|
|
20
|
+
`#@native.mozRequestAnimationFrame(#{block.to_n})`
|
|
21
|
+
end
|
|
22
|
+
elsif Browser.supports? 'Animation.request (Opera)'
|
|
23
|
+
def request(block)
|
|
24
|
+
`#@native.oRequestAnimationFrame(#{block.to_n})`
|
|
25
|
+
end
|
|
26
|
+
elsif Browser.supports? 'Animation.request (Internet Explorer)'
|
|
27
|
+
def request(block)
|
|
28
|
+
`#@native.msRequestAnimationFrame(#{block.to_n})`
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
def request
|
|
32
|
+
raise NotImplementedError, 'window requestAnimationFrame unsupported'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
16
35
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
36
|
+
if Browser.supports? 'Animation.cancel'
|
|
37
|
+
def cancel
|
|
38
|
+
`#@native.cancelAnimationFrame(#@id)`
|
|
39
|
+
end
|
|
40
|
+
elsif Browser.supports? 'Animation.cancel (Chrome)'
|
|
41
|
+
def cancel
|
|
42
|
+
`#@native.webkitCancelAnimationFrame(#@id)`
|
|
43
|
+
end
|
|
44
|
+
elsif Browser.supports? 'Animation.cancelRequest (Chrome)'
|
|
45
|
+
def cancel
|
|
46
|
+
`#@native.webkitCancelRequestAnimationFrame(#@id)`
|
|
47
|
+
end
|
|
48
|
+
elsif Browser.supports? 'Animation.cancel (Firefox)'
|
|
49
|
+
def cancel
|
|
50
|
+
`#@native.mozCancelAnimationFrame(#@id)`
|
|
51
|
+
end
|
|
52
|
+
elsif Browser.supports? 'Animation.cancelRequest (Firefox)'
|
|
53
|
+
def cancel
|
|
54
|
+
`#@native.mozCancelRequestAnimationFrame(#@id)`
|
|
55
|
+
end
|
|
56
|
+
elsif Browser.supports? 'Animation.cancel (Opera)'
|
|
57
|
+
def cancel
|
|
58
|
+
`#@native.oCancelAnimationFrame(#@id)`
|
|
59
|
+
end
|
|
60
|
+
elsif Browser.supports? 'Animation.cancelRequest (Opera)'
|
|
61
|
+
def cancel
|
|
62
|
+
`#@native.oCancelRequestAnimationFrame(#@id)`
|
|
63
|
+
end
|
|
64
|
+
elsif Browser.supports? 'Animation.cancel (Internet Explorer)'
|
|
65
|
+
def cancel
|
|
66
|
+
`#@native.msCancelAnimationFrame(#@id)`
|
|
67
|
+
end
|
|
68
|
+
elsif Browser.supports? 'Animation.cancelRequest (Internet Explorer)'
|
|
69
|
+
def cancel
|
|
70
|
+
`#@native.msCancelRequestAnimationFrame(#@id)`
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
def cancel
|
|
74
|
+
raise NotImplementedError, 'window cancelAnimationFrame unsupported'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
20
77
|
end
|
|
21
78
|
|
|
22
79
|
end
|
data/opal/browser/canvas.rb
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
9
9
|
#++
|
|
10
10
|
|
|
11
|
+
require 'promise'
|
|
12
|
+
|
|
11
13
|
require 'browser/canvas/style'
|
|
12
14
|
require 'browser/canvas/text'
|
|
13
15
|
require 'browser/canvas/data'
|
|
@@ -21,12 +23,28 @@ class Canvas
|
|
|
21
23
|
attr_reader :element, :style, :text
|
|
22
24
|
|
|
23
25
|
def initialize(*args)
|
|
24
|
-
if DOM::
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
if DOM::Element === args.first
|
|
27
|
+
element = args.shift
|
|
28
|
+
|
|
29
|
+
if DOM::Element::Image === element
|
|
30
|
+
@image = element
|
|
31
|
+
else
|
|
32
|
+
@element = element
|
|
33
|
+
end
|
|
34
|
+
elsif Canvas === args.first
|
|
35
|
+
@image = args.first
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
unless @element
|
|
27
39
|
@element = $document.create_element('canvas')
|
|
28
|
-
|
|
29
|
-
@
|
|
40
|
+
|
|
41
|
+
if @image
|
|
42
|
+
@element[:width] = @image.width
|
|
43
|
+
@element[:height] = @image.height
|
|
44
|
+
else
|
|
45
|
+
@element[:width] = args.shift
|
|
46
|
+
@element[:height] = args.shift
|
|
47
|
+
end
|
|
30
48
|
end
|
|
31
49
|
|
|
32
50
|
if @element.node_name != 'CANVAS'
|
|
@@ -37,6 +55,35 @@ class Canvas
|
|
|
37
55
|
|
|
38
56
|
@style = Style.new(self)
|
|
39
57
|
@text = Text.new(self)
|
|
58
|
+
|
|
59
|
+
if @image
|
|
60
|
+
draw_image(@image)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def width
|
|
65
|
+
@element[:width].to_i
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def height
|
|
69
|
+
@element[:height].to_i
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def append_to(parent)
|
|
73
|
+
@element.append_to(parent)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def load(path)
|
|
77
|
+
promise = Promise.new
|
|
78
|
+
image = $document.create_element('img')
|
|
79
|
+
|
|
80
|
+
image.on :load do
|
|
81
|
+
promise.resolve(image)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
image[:src] = path
|
|
85
|
+
|
|
86
|
+
promise
|
|
40
87
|
end
|
|
41
88
|
|
|
42
89
|
def data(x = nil, y = nil, width = nil, height = nil)
|
|
@@ -49,7 +96,7 @@ class Canvas
|
|
|
49
96
|
end
|
|
50
97
|
|
|
51
98
|
def pattern(image, type = :repeat)
|
|
52
|
-
`#@native.createPattern(#{
|
|
99
|
+
`#@native.createPattern(#{DOM(image).to_n}, type)`
|
|
53
100
|
end
|
|
54
101
|
|
|
55
102
|
def gradient(*args, &block)
|
|
@@ -143,17 +190,28 @@ class Canvas
|
|
|
143
190
|
self
|
|
144
191
|
end
|
|
145
192
|
|
|
146
|
-
def draw_image(*args)
|
|
147
|
-
|
|
193
|
+
def draw_image(image, *args)
|
|
194
|
+
if Canvas === image
|
|
195
|
+
image = image.element
|
|
196
|
+
else
|
|
197
|
+
image = DOM(image)
|
|
198
|
+
end
|
|
148
199
|
|
|
149
200
|
if args.first.is_a?(Hash)
|
|
150
201
|
source, destination = args
|
|
151
202
|
|
|
152
203
|
`#@native.drawImage(#{image.to_n}, #{source[:x]}, #{source[:y]}, #{source[:width]}, #{source[:height]}, #{destination[:x]}, #{destination[:y]}, #{destination[:width]}, #{destination[:height]})`
|
|
153
204
|
else
|
|
154
|
-
|
|
205
|
+
case args.length
|
|
206
|
+
when 0
|
|
207
|
+
`#@native.drawImage(#{image.to_n}, 0, 0)`
|
|
208
|
+
|
|
209
|
+
when 2
|
|
210
|
+
`#@native.drawImage(#{image.to_n}, #{args[0]}, #{args[1]})`
|
|
155
211
|
|
|
156
|
-
|
|
212
|
+
when 4
|
|
213
|
+
`#@native.drawImage(#{image.to_n}, #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]})`
|
|
214
|
+
end
|
|
157
215
|
end
|
|
158
216
|
|
|
159
217
|
self
|
|
@@ -261,17 +319,13 @@ class Canvas
|
|
|
261
319
|
`#@native.isPointInPath(x, y)`
|
|
262
320
|
end
|
|
263
321
|
|
|
264
|
-
def width
|
|
265
|
-
@element[:width]
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def height
|
|
269
|
-
@element[:height]
|
|
270
|
-
end
|
|
271
|
-
|
|
272
322
|
def to_data(type = undefined)
|
|
273
323
|
`#{@element.to_n}.toDataUrl(type)`
|
|
274
324
|
end
|
|
275
325
|
end
|
|
276
326
|
|
|
327
|
+
Browser::DOM::Builder.for Canvas do |b, item|
|
|
328
|
+
item.element
|
|
329
|
+
end
|
|
330
|
+
|
|
277
331
|
end
|