Skip to content

Commit f19ddfb

Browse files
committed
add loading spinners
1 parent 9efae6b commit f19ddfb

File tree

9 files changed

+153
-6
lines changed

9 files changed

+153
-6
lines changed

canvas.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55
<title>Ruby.wasm Quickstart</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<script src="browser.script.iife.js"></script>
8+
<style>
9+
.spinner {
10+
border: 4px solid rgba(0, 0, 0, 0.1);
11+
width: 40px;
12+
height: 40px;
13+
border-radius: 50%;
14+
border-left-color: #09f;
15+
animation: spin 1s ease infinite;
16+
}
17+
18+
@keyframes spin {
19+
0% {
20+
transform: rotate(0deg);
21+
}
22+
100% {
23+
transform: rotate(360deg);
24+
}
25+
}
26+
</style>
827
<script type="text/ruby">
9-
require 'js'
28+
require 'js'
1029
# Create a canvas element
1130
window = JS.global
1231
document = window.document
32+
document.getElementById("spinner").style.display = "none"
33+
1334

1435
canvas = document.createElement("canvas")
1536

@@ -87,7 +108,8 @@
87108
</head>
88109
<body class="main">
89110
<h3>
90-
We are loading...
111+
Canvas Example
91112
</h3>
113+
<div id="spinner" class="spinner"></div>
92114
</body>
93115
</html>

heartbeat.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
<title>Heartbeat Monitor Animation with Ruby.wasm</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<script src="browser.script.iife.js"></script>
8+
<style>
9+
.spinner {
10+
border: 4px solid rgba(0, 0, 0, 0.1);
11+
width: 40px;
12+
height: 40px;
13+
border-radius: 50%;
14+
border-left-color: #09f;
15+
animation: spin 1s ease infinite;
16+
}
17+
18+
@keyframes spin {
19+
0% {
20+
transform: rotate(0deg);
21+
}
22+
100% {
23+
transform: rotate(360deg);
24+
}
25+
}
26+
</style>
827
<script type="text/ruby">
928
require 'js'
1029

index.html

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,35 @@
2121
margin: 20px;
2222
}
2323

24+
.spinner {
25+
border: 4px solid rgba(0, 0, 0, 0.1);
26+
width: 40px;
27+
height: 40px;
28+
border-radius: 50%;
29+
border-left-color: #09f;
30+
animation: spin 1s ease infinite;
31+
}
32+
33+
@keyframes spin {
34+
0% {
35+
transform: rotate(0deg);
36+
}
37+
100% {
38+
transform: rotate(360deg);
39+
}
40+
}
2441
</style>
2542
</head>
2643
<body>
2744
<h1>Ruby.wasm Quickstart</h1>
45+
<div id="spinner" class="spinner"></div>
2846
<script type="text/ruby" data-eval="async">
2947
require 'kramdown'
3048
$window = JS.global
3149
$d = $window.document
3250

51+
$d.getElementById("spinner").style.display = "none"
52+
3353
$d.createElement("h2").tap {|e|
3454
e.innerText = "Examples"
3555
$d.body.appendChild(e)
@@ -39,7 +59,7 @@ <h1>Ruby.wasm Quickstart</h1>
3959
div.classList.add("examples")
4060
$d.body.appendChild(div)
4161
}
42-
examples = %w(heartbeat canvas kramdown require run-code shoppingList)
62+
examples = %w(run-code shoppingList require canvas heartbeat kramdown)
4363
examples.each do |example|
4464
$d.createElement("a").tap {|link|
4565
link.href = "#{example}.html"
@@ -61,7 +81,6 @@ <h1>Ruby.wasm Quickstart</h1>
6181
$d.body.appendChild(e)
6282
}
6383
end
64-
6584
</script>
6685
</body>
6786
</html>

kramdown.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
<title>Ruby.wasm Quickstart</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<script src="browser.script.iife.js"></script>
8+
<style>
9+
.spinner {
10+
border: 4px solid rgba(0, 0, 0, 0.1);
11+
width: 40px;
12+
height: 40px;
13+
border-radius: 50%;
14+
border-left-color: #09f;
15+
animation: spin 1s ease infinite;
16+
}
17+
18+
@keyframes spin {
19+
0% {
20+
transform: rotate(0deg);
21+
}
22+
100% {
23+
transform: rotate(360deg);
24+
}
25+
}
26+
</style>
827
<script type="text/ruby">
928
require 'js'
1029
require 'kramdown'
@@ -18,12 +37,14 @@
1837
MARKDOWN
1938

2039
div.innerHTML = Kramdown::Document.new(text).to_html
40+
JS.global.document.getElementById("spinner").style.display = "none"
2141
JS.global.document.body.appendChild(div)
2242
</script>
2343
</head>
2444
<body class="main">
2545
<h3>
2646
Kramdown Example
2747
</h3>
48+
<div id="spinner" class="spinner"></div>
2849
</body>
2950
</html>

require.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@
55
<title>Multiple Files example</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<script src="browser.script.iife.js"></script>
8+
<style>
9+
.spinner {
10+
border: 4px solid rgba(0, 0, 0, 0.1);
11+
width: 40px;
12+
height: 40px;
13+
border-radius: 50%;
14+
border-left-color: #09f;
15+
animation: spin 1s ease infinite;
16+
}
17+
18+
@keyframes spin {
19+
0% {
20+
transform: rotate(0deg);
21+
}
22+
100% {
23+
transform: rotate(360deg);
24+
}
25+
}
26+
.buttons {
27+
display: none;
28+
}
29+
</style>
830
</head>
931
<body class="main">
1032
<h3>
1133
Multiple Files Example
1234
</h3>
35+
<div id="spinner" class="spinner"></div>
1336
<div class="buttons">
1437
<button id="hello">Click me</button>
1538
</div>

require/main.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ def require_relative(path)
99
end
1010
app_path = __FILE__
1111
$0 = File::basename(app_path, ".rb") if app_path
12-
require_relative "require/second" # Here it should be relative to main.rb. Note: I will upstream the fix for this.
12+
require_relative "require/second" # Here it should be relative to main.rb. Note: I will upstream the fix for this.
13+
14+
JS.global.document.getElementById("spinner").style.display = "none"
15+
JS.global.document.querySelector(".buttons").style.display = "block"

run-code.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@
1313
white-space: pre-wrap;
1414
margin-top: 20px;
1515
}
16+
.spinner {
17+
border: 4px solid rgba(0, 0, 0, 0.1);
18+
width: 40px;
19+
height: 40px;
20+
border-radius: 50%;
21+
border-left-color: #09f;
22+
animation: spin 1s ease infinite;
23+
}
24+
25+
@keyframes spin {
26+
0% {
27+
transform: rotate(0deg);
28+
}
29+
100% {
30+
transform: rotate(360deg);
31+
}
32+
}
1633
</style>
1734
</head>
1835
<body>
1936
<h1>Code Runner</h1>
37+
<div id="spinner" class="spinner"></div>
2038
<textarea id="ruby-code" rows="10" cols="50">
2139
document = JS.global.document
2240
div = document.createElement("div")

runCode.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
indentUnit: 4
88
})
99

10+
JS.global.document.getElementById("spinner").style.display = "none"
11+
1012
define_method :click_run_button do
1113
code_area = JS.global.document.getElementById("ruby-code")
1214
@window.editor.save

shoppingList.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545
:checked ~ label {
4646
text-decoration: line-through;
4747
}
48+
49+
.spinner {
50+
border: 4px solid rgba(0, 0, 0, 0.1);
51+
width: 40px;
52+
height: 40px;
53+
border-radius: 50%;
54+
border-left-color: #09f;
55+
animation: spin 1s ease infinite;
56+
}
57+
58+
@keyframes spin {
59+
0% {
60+
transform: rotate(0deg);
61+
}
62+
100% {
63+
transform: rotate(360deg);
64+
}
65+
}
4866
</style>
4967
</head>
5068
<body>
@@ -53,8 +71,10 @@ <h2>Shopping List</h2>
5371
<input type="text" id="new-item" placeholder="Add new item" />
5472
<button id="add-item">Add</button>
5573
<ul class="shopping-list" id="shopping-list"></ul>
56-
74+
<div id="spinner" class="spinner"></div>
75+
5776
<script type="text/ruby" data-eval="async">
77+
JS.global.document.getElementById("spinner").style.display = "none"
5878
require "json"
5979
@document = JS.global.document
6080
@list = @document.getElementById("shopping-list")

0 commit comments

Comments
 (0)