-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
88 lines (79 loc) · 2.87 KB
/
editor.html
File metadata and controls
88 lines (79 loc) · 2.87 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PUZZLE Instant Editor</title>
<script type="text/javascript" src="puzzle-local.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Puzzle Shell">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<!--script src="https://unpkg.com/@isomorphic-git/lightning-fs"></script>
<script type="module">
fs = new LightningFS('fs');
import http from 'https://unpkg.com/isomorphic-git@beta/http/web/index.js';
window.http = http;
</script-->
<style type="text/css">
html, body {
height: 100%;
width: 100%;
background: #111111;
color: white;
}
textarea {
width: 100%;
height: calc(100% - 50px);
border: none;
background: #111111;
color: white;
}
input:focus, textarea {
outline: none !important;
}
</style>
</head>
<body>
<a onclick="runCode(document.getElementById('editor').value)"> ‣ Run</a>
<a onclick="saveCode(document.getElementById('editor').value)"> ✓ Save</a>
<br><br>
<textarea id="editor" placeholder="Write a script"></textarea>
</body>
<script>
function runCode(value){
if (window.parent) window.parent.postMessage(value, '*');
else if(window.opener) window.opener.postMessage(value, '*');
}
function saveCode(value){
localStorage.setItem('code', value);
}
var textareas = document.getElementsByTagName('textarea');
var count = textareas.length;
for(var i=0;i<count;i++){
textareas[i].onkeydown = function(e){
if(e.keyCode==9 || e.which==9){
e.preventDefault();
var s = this.selectionStart;
this.value = this.value.substring(0,this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
this.selectionEnd = s+1;
}
}
}
// key handlers for save, run and add tab
document.addEventListener("keydown", function(e) {
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
e.preventDefault();
saveCode(document.getElementById('editor').value);
}
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 13) {
e.preventDefault();
runCode(document.getElementById('editor').value);
}
}, false);
if(localStorage.getItem('code')){
document.getElementById('editor').innerText = localStorage.getItem('code');
}
</script>
</html>