-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.html
229 lines (204 loc) · 6.92 KB
/
gui.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="webui.js"></script>
<title>Goglitch</title>
<meta charset="utf-8">
</head>
<div class="container">
<div class="tabs" id="tabs">
<script>
async function saveFile() {
const content = await webui.loadFile("test");//codeMirrorInstance.getValue();
if (supportsFilePicker) {
if (fileHandle) {
// Create a FileSystemWritableFileStream to write to
const writableStream = await fileHandle.createWritable();
await writableStream.write(content);
// Write to disk
await writableStream.close();
} else {
fileHandle = await showSaveFilePicker();
saveFile();
setFile(await fileHandle.getFile());
}
} else {
// Download the file if using filePicker with a fileHandle for saving
// is not supported by the browser. E.g., in Firefox.
const blobData = new Blob([content], { type: 'text/${currentFile.ext}' });
const urlToBlob = window.URL.createObjectURL(blobData);
const a = document.createElement('a');
a.style.setProperty('display', 'none');
a.href = urlToBlob;
a.download = document.title;
a.click();
window.URL.revokeObjectURL(urlToBlob);
a.remove();
}
saveBtn.disabled = true;
}
function setFile(file) {
currentFile.name = file.name;
currentFile.ext = file.name.split('.').pop();
// Set file title and language in editor
document.title = file.name;
setLanguage(currentFile.ext);
}
async function readFile(file) {
const reader = new FileReader();
// Add text to the editor
reader.onload = async (e) => await webui.loadFile(e.target.result);
reader.readAsText(file);
}
const supportsFilePicker = 'showSaveFilePicker' in window;
function showhide(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block') ? 'none' : 'block';
}
async function fileFieldUpdate() {
console.log("filefieldupdate")
if (supportsFilePicker) {
[fileHandle] = await showOpenFilePicker({ multiple: false });
fileData = await fileHandle.getFile();
await readFile(fileData);
setFile(fileData);
} else {
let input = document.createElement('input');
input.type = 'file';
input.onchange = async (e) => {
await readFile(e.target.files[0]);
setFile(e.target.files[0]);
};
input.click();
input.remove();
}
const fileField = document.getElementById("file-id").files[0].name;
const myInput = document.getElementById("my-input");
const result = await webui.loadFile(fileField.value);
myInput.value = result;
// and then then load event will trigger ...
};
$(document).ready(function () {
$("#fileField").on('change', async function () {
await fileFieldUpdate()
});
});
$("body").on('change', 'input#fileField', function () {
alert($(this).val());
});
</script>
<div class="goglitch-tab">
<input type="radio" id="tab-1" name="goglitch-tabs" checked>
<label for="tab-1">Setup</label>
<div class="goglitch-content">
Setup Config <button onclick="showhide('goglitchsettings')">show/hide</button><br>
<div id="goglitchsettings" style="display: block;">
==============================================<br>
Config
<button onclick="fileFieldUpdate();">load existing</button>
<button onclick="saveFile();">save</button><br>
==============================================<br>
</div>
</div>
</div>
</html>
<style>
/* ------------------- */
/* PEN STYLES -- */
/* ----------------- */
/* MAKE IT CUTE ----- */
.tabs {
position: relative;
display: flex;
height: 94vh;
border-radius: 8px 8px 0 0;
overflow: hidden;
}
.goglitch-tab {
flex: 1;
}
.goglitch-tab label {
display: block;
box-sizing: border-box;
/* tab content must clear this */
height: 40px;
padding: 5px;
text-align: center;
background: #9768D1;
cursor: pointer;
transition: background 0.5s ease;
}
.goglitch-tab label:hover {
background: #7B52AB;
}
.goglitch-content {
position: absolute;
left: 0;
bottom: 0;
right: 0;
/* clear the tab labels */
top: 40px;
padding: 5px;
border-radius: 0 0 8px 8px;
background: #553285;
transition:
opacity 0.8s ease,
transform 0.8s ease;
/* show/hide */
opacity: 0;
transform: scale(0.1);
transform-origin: top left;
height:100%
}
.goglitch-content img {
float: left;
margin-right: 20px;
border-radius: 8px;
height: 100%
}
/* MAKE IT WORK ----- */
.goglitch-tab [type=radio] {
display: none;
}
[type=radio]:checked~label {
background: #553285;
z-index: 2;
}
[type=radio]:checked~label~.goglitch-content {
z-index: 1;
/* show/hide */
opacity: 1;
transform: scale(1);
}
/* BREAKPOINTS ----- */
@media screen and (max-width: 767px) {
.tabs {
min-height:100%;
}
}
@media screen and (max-width: 480px) {
.tabs {
min-height: 100%;
}
.goglitch-tab label {
height: 60px;
}
.goglitch-content {
top: 0px;
}
.goglitch-content img {
float: none;
margin-right: 0;
margin-bottom: 20px;
}
}
html,
body {
background: linear-gradient(to left, #36265a, #654da9);
color: AliceBlue;
font: 16px sans-serif;
text-align: center;
margin-top: 5px;
height:auto;
}
</style>