opal-browser 0.2.0 → 0.3.3
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 +78 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +17 -3
- data/LICENSE +2 -1
- data/README.md +131 -54
- data/Rakefile +29 -1
- data/config.ru +20 -3
- 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 +2 -3
- 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 +1 -1
- data/opal/browser/canvas/gradient.rb +1 -1
- data/opal/browser/canvas/style.rb +3 -1
- data/opal/browser/canvas/text.rb +1 -1
- data/opal/browser/canvas.rb +17 -3
- data/opal/browser/console.rb +3 -1
- data/opal/browser/cookies.rb +72 -34
- data/opal/browser/crypto.rb +79 -0
- data/opal/browser/css/declaration.rb +1 -1
- 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 +7 -8
- data/opal/browser/delay.rb +16 -0
- data/opal/browser/dom/attribute.rb +1 -1
- data/opal/browser/dom/builder.rb +29 -10
- data/opal/browser/dom/document.rb +81 -13
- 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 +28 -4
- 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 +17 -2
- 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 +2 -0
- data/opal/browser/dom/element/input.rb +36 -0
- data/opal/browser/dom/element/media.rb +17 -0
- data/opal/browser/dom/element/scroll.rb +106 -74
- data/opal/browser/dom/element/select.rb +6 -0
- data/opal/browser/dom/element/size.rb +12 -0
- data/opal/browser/dom/element/template.rb +2 -0
- data/opal/browser/dom/element/textarea.rb +2 -0
- data/opal/browser/dom/element.rb +194 -50
- data/opal/browser/dom/mutation_observer.rb +2 -2
- data/opal/browser/dom/node.rb +53 -13
- data/opal/browser/dom/node_set.rb +13 -2
- data/opal/browser/dom/shadow_root.rb +12 -0
- data/opal/browser/dom/text.rb +2 -2
- data/opal/browser/dom.rb +38 -5
- data/opal/browser/effects.rb +170 -4
- data/opal/browser/event/all.rb +26 -0
- data/opal/browser/event/animation.rb +2 -0
- data/opal/browser/event/audio_processing.rb +2 -0
- data/opal/browser/event/base.rb +35 -4
- data/opal/browser/event/before_unload.rb +2 -0
- data/opal/browser/event/clipboard.rb +9 -0
- data/opal/browser/event/close.rb +2 -0
- data/opal/browser/event/composition.rb +2 -0
- data/opal/browser/event/custom.rb +1 -1
- data/opal/browser/event/data_transfer.rb +95 -0
- data/opal/browser/event/device_light.rb +2 -0
- data/opal/browser/event/device_motion.rb +2 -0
- data/opal/browser/event/device_orientation.rb +2 -0
- data/opal/browser/event/device_proximity.rb +2 -0
- data/opal/browser/event/drag.rb +9 -5
- data/opal/browser/event/focus.rb +2 -0
- data/opal/browser/event/gamepad.rb +3 -1
- data/opal/browser/event/hash_change.rb +2 -0
- data/opal/browser/event/keyboard.rb +14 -1
- data/opal/browser/event/message.rb +2 -0
- data/opal/browser/event/mouse.rb +10 -6
- data/opal/browser/event/page_transition.rb +2 -0
- data/opal/browser/event/pop_state.rb +2 -0
- data/opal/browser/event/progress.rb +2 -0
- data/opal/browser/event/sensor.rb +2 -0
- data/opal/browser/event/storage.rb +2 -0
- data/opal/browser/event/touch.rb +2 -0
- data/opal/browser/event/wheel.rb +2 -0
- data/opal/browser/event.rb +26 -116
- data/opal/browser/event_source.rb +1 -1
- data/opal/browser/form_data.rb +225 -0
- data/opal/browser/history.rb +4 -8
- data/opal/browser/http/request.rb +32 -10
- data/opal/browser/http/response.rb +5 -1
- data/opal/browser/http.rb +0 -2
- data/opal/browser/immediate.rb +0 -2
- data/opal/browser/location.rb +7 -1
- data/opal/browser/navigator.rb +105 -4
- data/opal/browser/polyfill/visual_viewport.rb +216 -0
- data/opal/browser/screen.rb +2 -2
- 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 +3 -3
- data/opal/browser/storage.rb +2 -2
- data/opal/browser/support.rb +46 -22
- data/opal/browser/utils.rb +94 -14
- data/opal/browser/version.rb +1 -1
- data/opal/browser/visual_viewport.rb +39 -0
- data/opal/browser/window/size.rb +14 -0
- data/opal/browser/window/view.rb +15 -0
- data/opal/browser/window.rb +29 -16
- data/opal/browser.rb +1 -11
- data/opal-browser.gemspec +3 -3
- data/spec/database/sql_spec.rb +43 -35
- data/spec/delay_spec.rb +15 -12
- data/spec/dom/document_spec.rb +10 -8
- data/spec/dom/element/custom_spec.rb +106 -0
- data/spec/dom/element/subclass_spec.rb +144 -0
- data/spec/dom/element_spec.rb +42 -0
- data/spec/dom/mutation_observer_spec.rb +12 -8
- data/spec/dom/node_spec.rb +48 -0
- data/spec/dom_spec.rb +8 -0
- data/spec/event_source_spec.rb +15 -12
- data/spec/{dom/event_spec.rb → event_spec.rb} +44 -15
- data/spec/history_spec.rb +23 -19
- data/spec/http_spec.rb +19 -31
- data/spec/immediate_spec.rb +5 -4
- data/spec/interval_spec.rb +18 -9
- data/spec/native_cached_wrapper_spec.rb +46 -0
- data/spec/runner.rb +37 -62
- data/spec/socket_spec.rb +15 -12
- data/spec/spec_helper.rb +2 -1
- data/spec/spec_helper_promise.rb.erb +25 -0
- metadata +120 -16
- data/.travis.yml +0 -74
- data/opal/browser/window/scroll.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ca31ac16a859cb8e8e2d033f9654d73f69af51fb370b84c4eea90c11d854b591
|
4
|
+
data.tar.gz: cf292f8f778e76a8a0552a57d608cafbd975653df39df2f79e6d0ea1f8600d5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b6ebdb57718727af8443be34513c614d49d6a182a7a1189bf37ecf2998e8895a8ed6b321455be04e45ce94815e762d93cd1ad3d35b9bf8c1257b5a9face39e
|
7
|
+
data.tar.gz: 0eda48ea9ba83c04929266bb2c664290d22389a6ff16aef4faab3b4a055c7510ed2e9734d6f6d7b409a79ecb56086627df559ea2c0d8ce3281a9e13472731adc
|
@@ -0,0 +1,78 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
- "*-stable"
|
8
|
+
- "*/ci-check"
|
9
|
+
pull_request: {}
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: ${{ matrix.combo.name }}
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
combo:
|
18
|
+
- name: Chromium/Linux/Opal-master
|
19
|
+
opal: master
|
20
|
+
- name: Chromium/Linux/Opal-1.4
|
21
|
+
opal: 1.4
|
22
|
+
- name: Chromium/Linux/Opal-1.3/PromiseV2
|
23
|
+
opal: 1.3
|
24
|
+
promise: v2
|
25
|
+
- name: Chromium/Linux/Opal-1.3
|
26
|
+
opal: 1.3
|
27
|
+
- name: Chromium/Linux/Opal-1.0
|
28
|
+
opal: '1.0'
|
29
|
+
- name: Chromium/Linux/Ruby-2.7
|
30
|
+
ruby: 2.7
|
31
|
+
- name: Chromium/Linux/Ruby-2.6
|
32
|
+
ruby: 2.6
|
33
|
+
- name: Firefox/Linux
|
34
|
+
browser: gecko
|
35
|
+
- name: Chromium/Windows
|
36
|
+
os: windows-latest
|
37
|
+
- name: Firefox/Windows
|
38
|
+
browser: gecko
|
39
|
+
os: windows-latest
|
40
|
+
- name: Edge/Windows
|
41
|
+
browser: edge
|
42
|
+
os: windows-latest
|
43
|
+
- name: Chromium/macOS
|
44
|
+
os: macos-latest
|
45
|
+
- name: Firefox/macOS
|
46
|
+
browser: gecko
|
47
|
+
os: macos-latest
|
48
|
+
- name: Safari/macOS
|
49
|
+
browser: safari
|
50
|
+
os: macos-latest
|
51
|
+
|
52
|
+
runs-on: ${{ matrix.combo.os || 'ubuntu-latest' }}
|
53
|
+
|
54
|
+
steps:
|
55
|
+
- uses: actions/checkout@v2
|
56
|
+
- name: set environment variables
|
57
|
+
run: |
|
58
|
+
echo "OPAL_VERSION=${{ matrix.combo.opal || '1.3' }}" >> $GITHUB_ENV
|
59
|
+
echo "OPAL_BROWSER_PROMISE=${{ matrix.combo.promise || 'v1' }}" >> $GITHUB_ENV
|
60
|
+
- uses: ruby/setup-ruby@v1
|
61
|
+
with:
|
62
|
+
ruby-version: ${{ matrix.combo.ruby || '3.0' }}
|
63
|
+
- run: bundle lock
|
64
|
+
- uses: actions/cache@v2
|
65
|
+
with:
|
66
|
+
path: ./vendor/bundle
|
67
|
+
key: ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
|
68
|
+
restore-keys: |
|
69
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-${{ github.ref }}
|
70
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-master
|
71
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-
|
72
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-
|
73
|
+
- name: bundle install
|
74
|
+
run: |
|
75
|
+
bundle config path $PWD/vendor/bundle
|
76
|
+
bundle install --jobs 4 --retry 3
|
77
|
+
bundle clean
|
78
|
+
- run: bundle exec rake selenium_${{ matrix.combo.browser || 'chrome' }}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## 0.3.3
|
2
|
+
* Compatibility fix for Opal 1.4
|
3
|
+
|
4
|
+
## 0.3.2
|
5
|
+
* Cookie: refactor the module
|
6
|
+
* Note in documentation it's available as `$document.cookies` and it's the preferred way to access it
|
7
|
+
* Always encode a cookie with JSON, unless a new parameter `raw:` is provided
|
8
|
+
|
9
|
+
## 0.3.1
|
10
|
+
* Element#inner_dom: Reduce flickering - first build tree, then insert it
|
11
|
+
* NodeSet#to_a to be aliased to #to_ary
|
data/Gemfile
CHANGED
@@ -2,15 +2,29 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
# specs
|
5
|
+
gem 'rake'
|
5
6
|
gem 'rack'
|
6
7
|
gem 'sinatra'
|
7
8
|
gem 'sinatra-websocket'
|
8
|
-
gem 'opal-rspec'
|
9
|
+
gem 'opal-rspec'
|
10
|
+
gem 'opal-sprockets'
|
11
|
+
# Force build of eventmachine... I wish we could find a way to not use
|
12
|
+
# this unmaintained library anymore.
|
13
|
+
gem 'eventmachine', github: 'eventmachine/eventmachine'
|
14
|
+
gem 'thin', github: 'macournoyer/thin' unless RUBY_PLATFORM =~ /mingw/
|
9
15
|
|
10
16
|
# runner
|
11
17
|
gem 'selenium-webdriver', require: false
|
12
18
|
gem 'rest-client', require: false
|
19
|
+
gem 'webdrivers', require: false
|
20
|
+
gem 'rexml', require: false
|
13
21
|
|
14
22
|
# browser
|
15
|
-
|
16
|
-
|
23
|
+
case ENV['OPAL_VERSION']
|
24
|
+
when nil
|
25
|
+
when /\./
|
26
|
+
gem 'opal', "~> #{ENV['OPAL_VERSION']}.0a"
|
27
|
+
else
|
28
|
+
gem 'opal', github: 'opal/opal', ref: ENV['OPAL_VERSION']
|
29
|
+
end
|
30
|
+
|
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (C)
|
1
|
+
Copyright (C) 2013-2018 by meh
|
2
|
+
Copyright (C) 2019-2021 hmdne and the Opal-Browser contributors
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,18 +1,33 @@
|
|
1
|
-
Browser
|
2
|
-
|
1
|
+
Opal-Browser - Client side web development in pure Ruby, using Opal
|
2
|
+
===================================================================
|
3
3
|
|
4
|
-
[![Build Status](https://secure.travis-ci.org/opal/opal-browser.svg?branch=master)](http://travis-ci.org/opal/opal-browser)
|
5
4
|
[![Gem Version](https://badge.fury.io/rb/opal-browser.svg)](http://badge.fury.io/rb/opal-browser)
|
6
|
-
[![Code Climate](
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/maintainability-percentage/opal/opal-browser.svg)](https://codeclimate.com/github/opal/opal-browser)
|
6
|
+
[![Build Status](https://github.com/opal/opal-browser/workflows/build/badge.svg)](https://github.com/opal/opal-browser/actions?query=workflow%3Abuild)
|
7
|
+
[![Join Chat](https://img.shields.io/badge/slack-join%20chat-46BC99?logo=slack&style=flat)](https://slack.opalrb.com/)
|
8
|
+
[![Stack Overflow](https://img.shields.io/badge/stackoverflow-%23opalrb-orange.svg?style=flat)](https://stackoverflow.com/questions/ask?tags=opalrb,opal-browser)
|
9
|
+
[![Documentation](https://img.shields.io/badge/docs-updated-blue.svg)](https://rubydoc.info/gems/opal-browser)
|
7
10
|
|
8
|
-
|
9
|
-
This library aims to be a full-blown wrapper for all the browser API including
|
11
|
+
This library aims to be a full-blown wrapper for all the browser API as defined by
|
10
12
|
HTML5.
|
11
13
|
|
14
|
+
It provides a very JQuery-like interface to DOM, but itself it doesn't use nor
|
15
|
+
require JQuery nor opal-jquery (which is an alternative library for interfacing
|
16
|
+
the web browser). The main difference though is that Opal-Browser goes far beyond
|
17
|
+
what JQuery does.
|
18
|
+
|
12
19
|
Usage
|
13
20
|
=====
|
14
21
|
|
15
|
-
|
22
|
+
_Gemfile_
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
source 'https://rubygems.org/'
|
26
|
+
|
27
|
+
gem 'opal-browser'
|
28
|
+
```
|
29
|
+
|
30
|
+
_Server side (config.ru, Rakefile, Rails, Sinatra, Roda, etc. - not needed for static compilation)_
|
16
31
|
|
17
32
|
```ruby
|
18
33
|
require 'opal-browser'
|
@@ -23,15 +38,47 @@ _Browser side_
|
|
23
38
|
|
24
39
|
```ruby
|
25
40
|
require 'opal'
|
26
|
-
require '
|
41
|
+
require 'native'
|
42
|
+
require 'promise'
|
43
|
+
require 'browser/setup/full'
|
44
|
+
|
27
45
|
# Your Opal code here
|
46
|
+
$document.body << "Hello world!"
|
47
|
+
```
|
48
|
+
|
49
|
+
_Static Compile Opal + Opal-Browser library_
|
50
|
+
|
51
|
+
```bash
|
52
|
+
bundle exec opal -c -q opal-browser -p native -p promise -p browser/setup/full -e '#' -E > opal-browser.js
|
53
|
+
```
|
54
|
+
|
55
|
+
_Static Compile your application_
|
56
|
+
|
57
|
+
```bash
|
58
|
+
bundle exec opal -Oc -s opal -s native -s promise -s browser/setup/full app/application.rb > application.js
|
28
59
|
```
|
29
60
|
|
61
|
+
_And load it in HTML!_
|
62
|
+
|
63
|
+
```html
|
64
|
+
<!DOCTYPE html>
|
65
|
+
<html>
|
66
|
+
<head>
|
67
|
+
<title>My Application</title>
|
68
|
+
</head>
|
69
|
+
<body>
|
70
|
+
<script src='opal-browser.js' onload='Opal.require("native"); Opal.require("promise"); Opal.require("browser/setup/full");'></script>
|
71
|
+
<script src='application.js'></script>
|
72
|
+
</body>
|
73
|
+
</html>
|
74
|
+
```
|
30
75
|
|
76
|
+
See the `examples/integrations/` directory for various ideas on how to quickly start
|
77
|
+
development using opal-browser.
|
31
78
|
|
32
79
|
Features
|
33
80
|
========
|
34
|
-
This is a list of
|
81
|
+
This is a list of many currently wrapped features and some details on them.
|
35
82
|
|
36
83
|
DOM
|
37
84
|
---
|
@@ -44,8 +91,8 @@ $document.ready do
|
|
44
91
|
end
|
45
92
|
```
|
46
93
|
|
47
|
-
It also supports a markaby inspired builder DSL which generates
|
48
|
-
directly instead of creating a string.
|
94
|
+
It also supports a markaby inspired builder DSL (using Paggio) which generates
|
95
|
+
DOM nodes directly instead of creating a string.
|
49
96
|
|
50
97
|
```ruby
|
51
98
|
$document.ready do
|
@@ -57,12 +104,38 @@ $document.ready do
|
|
57
104
|
end
|
58
105
|
```
|
59
106
|
|
107
|
+
Events
|
108
|
+
------
|
109
|
+
|
110
|
+
Add an event to a given element:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
$document.at_css("button").on(:click) do |e|
|
114
|
+
e.prevent # Prevent the default action (eg. form submission)
|
115
|
+
# You can also use `e.stop` to stop propagating the event to other handlers.
|
116
|
+
alert "Button clicked!"
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
Or add it to a parent element and use a delegator, so that an event gets fired
|
121
|
+
when any button children of `$document` is clicked:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
$document.on(:click, "button") do |e|
|
125
|
+
e.prevent
|
126
|
+
# e.on is a button that has been clicked
|
127
|
+
e.on.inner_text = "Clicked!"
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
Run an event once with `#one` instead of `#on`, or disable an event with `#off`.
|
132
|
+
|
60
133
|
CSSOM
|
61
134
|
-----
|
62
|
-
CSSOM support is still incomplete but the useful parts are
|
63
|
-
includes a DSL for generating a CSS style and the same DSL
|
64
|
-
change style declarations (which can either belong to a
|
65
|
-
`CSS::Rule::Style`).
|
135
|
+
CSSOM support (using Paggio) is still incomplete but the useful parts are
|
136
|
+
implemented, this includes a DSL for generating a CSS style and the same DSL
|
137
|
+
is also used to change style declarations (which can either belong to a
|
138
|
+
`DOM::Element` or a `CSS::Rule::Style`).
|
66
139
|
|
67
140
|
```ruby
|
68
141
|
$document.body.style.apply {
|
@@ -80,6 +153,8 @@ supports binary results as typed-arrays.
|
|
80
153
|
It easily allows for synchronous and asynchronous requests.
|
81
154
|
|
82
155
|
```ruby
|
156
|
+
require 'browser/http'
|
157
|
+
|
83
158
|
Browser::HTTP.get "/something.json" do
|
84
159
|
on :success do |res|
|
85
160
|
alert res.json.inspect
|
@@ -93,6 +168,8 @@ Websockets have been fully wrapped and they are easily configurable with
|
|
93
168
|
blocks.
|
94
169
|
|
95
170
|
```ruby
|
171
|
+
require 'browser/socket'
|
172
|
+
|
96
173
|
Browser::Socket.new 'ws://echo.websocket.org' do
|
97
174
|
on :open do
|
98
175
|
every 1 do
|
@@ -111,6 +188,8 @@ EventSource
|
|
111
188
|
Event sources have been implemented and are easily configurable with blocks.
|
112
189
|
|
113
190
|
```ruby
|
191
|
+
require 'browser/event_source'
|
192
|
+
|
114
193
|
Browser::EventSource.new '/events' do |es|
|
115
194
|
es.on :message do |e|
|
116
195
|
alert e.data
|
@@ -126,16 +205,36 @@ History
|
|
126
205
|
-------
|
127
206
|
The HTML5 History API has been fully wrapped.
|
128
207
|
|
208
|
+
```ruby
|
209
|
+
current = $window.history.current
|
210
|
+
$window.history.replace("?get=params")
|
211
|
+
$window.history.push("?get=params")
|
212
|
+
$window.history.back
|
213
|
+
|
214
|
+
$window.on :popstate do |e|
|
215
|
+
p "User clicked a back button! He is now on #{$window.history.current}"
|
216
|
+
end
|
217
|
+
```
|
218
|
+
|
129
219
|
Storage
|
130
220
|
-------
|
131
221
|
The HTML5 Storage API has been wrapped and it exports a single Storage class
|
132
222
|
that uses the most appropriate and available API to store data locally.
|
133
223
|
|
224
|
+
```ruby
|
225
|
+
require 'browser/storage'
|
226
|
+
|
227
|
+
$storage = $window.storage
|
228
|
+
$storage[:hello] = "world"
|
229
|
+
```
|
230
|
+
|
134
231
|
Database SQL
|
135
232
|
------------
|
136
|
-
WebSQL has been fully wrapped
|
233
|
+
WebSQL has been fully wrapped (Chromium-only)
|
137
234
|
|
138
235
|
```ruby
|
236
|
+
require 'browser/database/sql'
|
237
|
+
|
139
238
|
db = Browser::Database::SQL.new 'test'
|
140
239
|
db.transaction {|t|
|
141
240
|
t.query('CREATE TABLE test(ID INTEGER PRIMARY KEY ASC, text TEXT)').then {
|
@@ -155,55 +254,33 @@ db.transaction {|t|
|
|
155
254
|
Browser support
|
156
255
|
===============
|
157
256
|
|
158
|
-
*
|
159
|
-
* Firefox (Current -
|
160
|
-
* Chrome (Current -
|
161
|
-
* Safari
|
162
|
-
* Opera
|
257
|
+
* Edge (Current - 3) to Current
|
258
|
+
* Firefox (Current - 3) to Current
|
259
|
+
* Chrome (Current - 3) to Current
|
260
|
+
* Safari (Current - 3) to Current
|
261
|
+
* Opera (Current - 3) to Current
|
163
262
|
|
164
263
|
Any problem above browsers should be considered and reported as a bug.
|
165
264
|
|
166
|
-
(Current -
|
167
|
-
the browser and
|
168
|
-
|
169
|
-
|
170
|
-
12.1x or (Current - 1) or Current denotes that we support Opera 12.1x as well
|
171
|
-
as last 2 versions of Opera. For example, if the current Opera version is 20.x,
|
172
|
-
we support Opera 12.1x, 19.x and 20.x but not Opera 15.x through 18.x.
|
173
|
-
|
174
|
-
Cross-browser testing sponsored by [BrowserStack](http://browserstack.com).
|
175
|
-
|
176
|
-
CSS selectors
|
177
|
-
-------------
|
178
|
-
Older browsers do not support CSS selector in queries, this means you'll need
|
179
|
-
external polyfills for this.
|
180
|
-
|
181
|
-
The suggested polyfill is [Sizzle](http://sizzlejs.com/), require it **before**
|
182
|
-
opal-browser.
|
183
|
-
|
184
|
-
JSON parsing
|
185
|
-
------------
|
186
|
-
Older browsers don't support JSON parsing natively, this means you'll need
|
187
|
-
external polyfills for this.
|
188
|
-
|
189
|
-
The suggested polyfill is [json2](https://github.com/douglascrockford/JSON-js),
|
190
|
-
require it **before** opal-browser.
|
265
|
+
(Current - 3) to Current denotes that we support the current major stable version
|
266
|
+
of the browser and 3 versions preceding it. For example, if the current version
|
267
|
+
of a browser is 24.x, we support all versions between 21.x to 24.x.
|
191
268
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
269
|
+
We will accept compatibility patches for even earlier browser versions. Opal-Browser
|
270
|
+
is written in such a way, that it integrates a robust compatibility check system,
|
271
|
+
similar to Modernizr, and the history of this library goes even as far as supporting
|
272
|
+
Internet Explorer 6.
|
196
273
|
|
197
|
-
|
198
|
-
|
199
|
-
opal-browser.
|
274
|
+
See the [polyfills documentation](docs/polyfills.md) if you wish to polyfill some
|
275
|
+
behaviors not supported by the ancient web browsers (like `querySelectorAll`).
|
200
276
|
|
201
277
|
License
|
202
278
|
=======
|
203
279
|
|
204
280
|
(The MIT License)
|
205
281
|
|
206
|
-
Copyright (C)
|
282
|
+
Copyright (C) 2013-2018 by meh<br>
|
283
|
+
Copyright (C) 2019-2021 hmdne and the Opal-Browser contributors
|
207
284
|
|
208
285
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
209
286
|
of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'webdrivers'
|
6
|
+
load 'webdrivers/Rakefile'
|
3
7
|
|
4
8
|
require 'opal/rspec/rake_task'
|
5
|
-
Opal::RSpec::RakeTask.new(:
|
9
|
+
Opal::RSpec::RakeTask.new(:broken_rspec) do |_, task|
|
10
|
+
task.default_path = 'spec'
|
11
|
+
task.pattern = 'spec/**/*_spec.{rb,opal}'
|
12
|
+
end
|
13
|
+
|
14
|
+
task(:nil) {}
|
15
|
+
|
16
|
+
%w[chrome edge gecko safari].each do |i|
|
17
|
+
dependency = nil
|
18
|
+
if %w[chrome edge gecko].include? i
|
19
|
+
dependency = "webdrivers:#{i}driver:update"
|
20
|
+
end
|
21
|
+
desc "Run Selenium tests with #{i}"
|
22
|
+
task :"selenium_#{i}" => dependency do
|
23
|
+
server = Process.spawn("bundle", "exec", "rackup")
|
24
|
+
at_exit { Process.kill(9, server) rescue nil }
|
25
|
+
sleep 2
|
26
|
+
ENV['BROWSER'] = i
|
27
|
+
load 'spec/runner.rb'
|
28
|
+
ensure
|
29
|
+
Process.kill(9, server) rescue nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :selenium_chrome
|
data/config.ru
CHANGED
@@ -2,11 +2,17 @@ require 'bundler'
|
|
2
2
|
Bundler.require
|
3
3
|
|
4
4
|
apps = []
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
sprockets_env = Opal::RSpec::SprocketsEnvironment.new(spec_pattern = 'spec/**/*_spec.{rb,opal}',
|
7
|
+
spec_exclude_pattern = nil,
|
8
|
+
spec_files = nil,
|
9
|
+
default_path = 'spec')
|
10
|
+
|
11
|
+
apps << Opal::Sprockets::Server.new(sprockets: sprockets_env) { |s|
|
7
12
|
s.main = 'opal/rspec/sprockets_runner'
|
13
|
+
s.append_path 'spec'
|
8
14
|
s.index_path = 'index.html.erb'
|
9
|
-
s.debug =
|
15
|
+
s.debug = true
|
10
16
|
}
|
11
17
|
|
12
18
|
apps << Class.new(Sinatra::Base) {
|
@@ -34,6 +40,17 @@ apps << Class.new(Sinatra::Base) {
|
|
34
40
|
"lol"
|
35
41
|
end
|
36
42
|
|
43
|
+
post '/http-file' do
|
44
|
+
if params['lol'] == 'wut' &&
|
45
|
+
params['file'][:filename] == 'yay.txt' &&
|
46
|
+
params['file'][:tempfile].read == 'content'
|
47
|
+
|
48
|
+
"ok"
|
49
|
+
else
|
50
|
+
"fail"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
37
54
|
get '/events' do
|
38
55
|
headers 'Content-Type' => 'text/event-stream'
|
39
56
|
|
data/docs/polyfills.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
CSS selectors
|
2
|
+
-------------
|
3
|
+
Older browsers do not support CSS selector in queries, this means you'll need
|
4
|
+
external polyfills for this.
|
5
|
+
|
6
|
+
The suggested polyfill is [Sizzle](http://sizzlejs.com/), require it **before**
|
7
|
+
opal-browser.
|
8
|
+
|
9
|
+
JSON parsing
|
10
|
+
------------
|
11
|
+
Older browsers don't support JSON parsing natively, this means you'll need
|
12
|
+
external polyfills for this.
|
13
|
+
|
14
|
+
The suggested polyfill is [json2](https://github.com/douglascrockford/JSON-js),
|
15
|
+
require it **before** opal-browser.
|
16
|
+
|
17
|
+
XPath support
|
18
|
+
-------------
|
19
|
+
Not all browsers support XPath queries, I'm looking at you Internet Explorer,
|
20
|
+
this means you'll need external polyfills for this.
|
21
|
+
|
22
|
+
The suggested polyfill is
|
23
|
+
[wgxpath](https://code.google.com/p/wicked-good-xpath/), require it **before**
|
24
|
+
opal-browser.
|