-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.html
249 lines (224 loc) · 8.25 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<script>
var getID = function() {
return window.location.hash.substring(1, window.location.hash.length);
}
if (getID() != '') {
window.location = './create.html#' + getID()
}
</script>
<link rel="shortcut icon" type="image/png" href="./favicon.png"/>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:url" content="https://woofjs.com">
<meta name="twitter:title" content="WoofJS">
<meta name="twitter:description" content="WoofJS is a Scratch-inspired Javascript library for making games.">
<meta name="twitter:image" content="./images/qIgC8Ae.png">
<meta property="og:image" content="./images/qIgC8Ae.png">
<meta property="og:title" content="WoofJS">
<meta property="og:description" content="WoofJS is a Scratch-inspired Javascript library for making games.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./vendor/codemirror/codemirror.css">
<script src="//load.sumome.com/" data-sumo-site-id="44245233c319d8fe9fb7ce8c7ed64db9381aa56477888a10319261f655cfffe2" async="async"></script>
<script type="text/javascript" src="./vendor/codemirror/codemirror.js"></script>
<script type="text/javascript" src="./vendor/codemirror/javascript.js"></script>
<script type="text/javascript" src="./vendor/codemirror/closebrackets.js"></script>
<script type="text/javascript" src="./vendor/codemirror/javascript-hint.js"></script>
<script type="text/javascript" src="./vendor/codemirror/javascript-lint.js"></script>
<script type="text/javascript" src="./vendor/codemirror/matchbrackets.js"></script>
<script type="text/javascript" src="./vendor/codemirror/search.js"></script>
<script type="text/javascript" src="./vendor/codemirror/searchcursor.js"></script>
<script type="text/javascript" src="./vendor/codemirror/show-hint.js"></script>
<script type="text/javascript" src="./vendor/codemirror/comment.js"></script>
<script type="text/javascript" src="./vendor/codemirror/sublime.js"></script>
<script type="text/javascript" src="./vendor/codemirror/foldcode.js"></script>
<link rel="stylesheet" href="./vendor/codemirror/foldgutter.css" />
<script src="./vendor/codemirror/foldcode.js"></script>
<script src="./vendor/codemirror/foldgutter.js"></script>
<script src="./vendor/codemirror/brace-fold.js"></script>
<script src="./vendor/codemirror/comment-fold.js"></script>
<link rel="stylesheet" href="./vendor/codemirror/dialog.css">
<link rel="stylesheet" href="./vendor/codemirror/show-hint.css">
<script src="./vendor/codemirror/dialog.js"></script>
<link rel="stylesheet" href="./vendor/codemirror/lint.css">
<script src="./vendor/codemirror/jshint.min.js"></script>
<script src="./vendor/codemirror/lint.js"></script>
<style type="text/css">
@media (max-width: 600px) {
#all {
width: 95% !important;
height: 60% !important;
}
button {
width: 100% !important;
}
#start{display:none;}
}
#all {
margin: auto;
z-index: 100;
position: absolute;
/* left: 45%; */
top: 30px;
left: 0;
right: 0;
height: 75%;
width: 60%;
background: rgba(255, 255, 255, 0.5);
}
.CodeMirror {
height: 100%;
background: rgba(255, 255, 255, 0.5);
font-size: 1.4em;
}
iframe {
width: 100%;
height: 97%;
border: none;
overflow: hidden;
z-index: -100;
}
button {
z-index: 200;
width: 375px;
height: 80px;
border: none;
margin-left: auto;
margin-right: auto;
margin: 10px;
background-color: #AD5FC2;
border-radius: 20px;
color: white;
font-size: 150%;
}
#start {
background-color: #6FCF97;
}
#educator {
background-color: #56CCF2;
}
#click {
display: flex;
width: 100%;
margin-left: auto;
margin-right: auto;
}
</style>
<div id="all">
<div id="editor"></div>
<div id="click" style="display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: center; align-items: center;">
<a href="./create.html"><button id="start">Start Coding</button></a>
<a href="./teach.html"><button id="educator">For Educators</button></a>
</div>
</div>
<iframe id="output"></iframe>
<script>
var readOnly = true
var cm = CodeMirror(document.getElementById('editor'), {
value: "",
mode: "javascript",
theme: "eclipse",
keyMap: "sublime",
lineWrapping: true,
scrollbarStyle: "null",
autofocus: false,
readOnly: readOnly
});
cm.on("mousedown", function(e) {
if (readOnly) {
e.preventDefault()
}
})
cm.on("touchstart", function(e) {
if (readOnly) {
e.preventDefault()
}
})
var pos = 0
var code = "// Hey there, welcome to WoofJS! WoofJS is a Scratch-inspired JavaScript library for making games.\n" +
"\n" +
"// Want to code something together? :-)\n" +
"every(.001, 'seconds', () => {" +
" var circle = new Circle()\n" +
"\n" +
" // Go, little circles, go!\n" +
" forever(() => {\n" +
" circle.move(5)\n" +
" })\n\n" +
" // Let's randomize size\n" +
" circle.radius = random(5, 20)\n\n" +
" // Colors are fun!\n" +
" circle.color = randomColor()\n" +
"\n" +
" // I say scatter!\n" +
" circle.angle = random(0, 360)\n\n" +
" // Now it's your turn. Play with this code by changing any of the numbers above.";
function runCode() {
var iframe = document.getElementById('output');
iframe.src = "";
setTimeout(function() {
var script = iframe.contentWindow.document.createElement("script");
script.type = "text/javascript";
script.src = "./woof.js";
iframe.contentWindow.document.body.appendChild(script);
iframe.contentWindow.document.body.style.overflow = "hidden"
script.onload = function() {
var evt = document.createEvent('Event');
evt.initEvent('load', false, false);
iframe.contentWindow.dispatchEvent(evt);
document.getElementById('output').contentWindow.eval(cm.getValue());
}
}, 10)
}
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
var debouncedRunCode = debounce(runCode, 1000, false)
var doc = cm.getDoc()
setInterval(function() {
if (pos < code.length) {
doc.replaceSelection(code[pos])
pos++
if (code.substring(pos - 9, pos) == ", () => {") {
doc.replaceSelection("\n\n\n")
doc.replaceSelection("})")
doc.setCursor({
line: doc.getCursor().line - 2,
ch: 1
})
}
cm.scrollIntoView({
line: doc.getCursor().line + 2
})
if (code[pos] == "\n" && !doc.getLine(doc.getCursor().line).startsWith('//')) {
runCode()
}
}
else if (pos == code.length) {
runCode()
pos++
cm.setOption("readOnly", false)
readOnly = false
cm.on("change", function(){
debouncedRunCode()
});
}
}, 50)
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-82374072-1', 'auto');
ga('send', 'pageview');
</script>