|
10 | 10 | <!-- no web site meta data here -->
|
11 | 11 | <link Content-Type="text/css" href="iotstyle.css" rel="stylesheet" />
|
12 | 12 | <script src="micro.js"></script>
|
| 13 | + <link Content-Type="text/css" href="/u-toast.css" rel="stylesheet" /> |
| 14 | + <script src="u-toast.js"></script> |
13 | 15 | <style>
|
14 | 16 | #files {
|
15 | 17 | border: solid 1px black;
|
|
58 | 60 | width: 100%;
|
59 | 61 | }
|
60 | 62 |
|
61 |
| - #dropzone { |
62 |
| - color: black; |
63 |
| - background-color: #dddd88; |
64 |
| - padding: 0.6rem; |
65 |
| - border: 1px dashed black; |
66 |
| - } |
67 |
| - |
68 |
| - #progress { |
69 |
| - position: absolute; |
70 |
| - top: 0.6rem; |
71 |
| - right: 0.1rem; |
72 |
| - width: 300px; |
73 |
| - height: 1.4rem; |
74 |
| - border: 0.1rem solid black; |
75 |
| - opacity: 1; |
76 |
| - pointer-events: none; |
77 |
| - background-color: white; |
78 |
| - } |
79 |
| - |
80 |
| - #progress.fadeout { |
81 |
| - transition-delay: 2s; |
82 |
| - transition-property: opacity; |
83 |
| - transition-duration: 1s; |
84 |
| - transition-timing-function: linear; |
85 |
| - opacity: 0; |
86 |
| - } |
87 |
| - |
88 | 63 | #checker {
|
89 | 64 | min-width: 3rem;
|
90 | 65 | text-align: center;
|
|
136 | 111 |
|
137 | 112 | <body style="margin: 0; padding: 0">
|
138 | 113 | <div class="grid-container" style="padding: 1rem">
|
139 |
| - <progress id="progress" class="fadeout" max="1" value="0"></progress> |
140 |
| - |
141 | 114 | <div class="u-header">
|
142 | 115 | <svg class="icon">
|
143 | 116 | <use href="./icons.svg#ide" />
|
144 | 117 | </svg>
|
145 | 118 | <h1>HomeDing IDE</h1>
|
146 | 119 |
|
147 | 120 | <span style="flex-grow: 1"></span>
|
148 |
| - <div id="dropzone">Drop here.</div> |
149 | 121 | </div>
|
150 | 122 |
|
151 | 123 | <div class="u-navbar">
|
@@ -183,11 +155,12 @@ <h3 style="display: inline-block; margin: 0">
|
183 | 155 | <pre style="grid-column: 2" class="code" contenteditable id="content" autocomplete="off" autocorrect="off"
|
184 | 156 | autocapitalize="off" spellcheck="false"></pre>
|
185 | 157 | </div>
|
| 158 | + <u-toast></u-toast> |
186 | 159 |
|
187 | 160 | <script>
|
188 | 161 | const filesObj = document.getElementById('files');
|
189 | 162 | const contentObj = document.getElementById('content');
|
190 |
| - const progressObj = document.getElementById('progress'); |
| 163 | + const toastObj = document.querySelector('u-toast'); |
191 | 164 |
|
192 | 165 | const activeFileObj = document.getElementById('activeFile');
|
193 | 166 | const checkerObj = document.getElementById('checker');
|
@@ -325,41 +298,20 @@ <h3 style="display: inline-block; margin: 0">
|
325 | 298 |
|
326 | 299 | // start uploading file content
|
327 | 300 | function startUpload(filename, contentType, content) {
|
328 |
| - progressObj.classList.remove('fadeout'); |
329 |
| - |
| 301 | + toastObj.info(`Uploading ${filename}`); |
330 | 302 | const formData = new FormData();
|
331 | 303 | const blob = new Blob([content], {
|
332 | 304 | type: contentType,
|
333 | 305 | });
|
334 | 306 | formData.append(filename, blob, filename);
|
335 | 307 |
|
336 |
| - const objHTTP = new XMLHttpRequest(); |
337 |
| - objHTTP.open('POST', '/'); |
338 |
| - |
339 |
| - if (objHTTP.upload) { |
340 |
| - objHTTP.upload.addEventListener('progress', function(e) { |
341 |
| - progressObj.max = e.total; |
342 |
| - progressObj.value = e.loaded; |
343 |
| - }); |
344 |
| - } // if |
345 |
| - |
346 |
| - objHTTP.addEventListener('readystatechange', function(p) { |
347 |
| - if ( |
348 |
| - objHTTP.readyState === 4 && |
349 |
| - objHTTP.status >= 200 && |
350 |
| - objHTTP.status < 300 |
351 |
| - ) { |
352 |
| - window.setTimeout(handleReloadFS, 200); |
353 |
| - progressObj.classList.add('fadeout'); |
354 |
| - } // if |
| 308 | + fetch('/', { method: 'POST', body: formData }).then(function() { |
| 309 | + toastObj.info(`done.`); |
355 | 310 | });
|
356 |
| - objHTTP.send(formData); |
357 | 311 | }
|
358 | 312 |
|
359 | 313 | // save file from editor back to server.
|
360 | 314 | function handleSave() {
|
361 |
| - progressObj.value = 0; |
362 |
| - progressObj.max = 1; |
363 | 315 | thisFile = window.prompt('Upload File:', thisFile);
|
364 | 316 | if (thisFile !== undefined)
|
365 | 317 | startUpload(thisFile, 'text/html', contentObj.innerText);
|
@@ -398,46 +350,25 @@ <h3 style="display: inline-block; margin: 0">
|
398 | 350 |
|
399 | 351 | // files was dropped on dropzone
|
400 | 352 | function drop(e) {
|
401 |
| - progressObj.classList.remove('fadeout'); |
402 |
| - progressObj.value = 0; |
403 |
| - progressObj.max = 1; |
404 | 353 | e.stopPropagation();
|
405 | 354 | e.preventDefault();
|
406 | 355 |
|
407 | 356 | const dtFiles = e.dataTransfer.files;
|
| 357 | + toastObj.info(`Uploading ${dtFiles.length} files...`); |
408 | 358 |
|
409 | 359 | const formData = new FormData();
|
410 | 360 | const path = getPath();
|
411 | 361 | for (let i = 0; i < dtFiles.length; i++) {
|
412 | 362 | formData.append('file', dtFiles[i], path + dtFiles[i].name);
|
413 | 363 | }
|
414 |
| - |
415 |
| - const xmlHttp = new XMLHttpRequest(); |
416 |
| - |
417 |
| - xmlHttp.upload.addEventListener('progress', function(e) { |
418 |
| - progressObj.max = e.total; |
419 |
| - progressObj.value = e.loaded; |
420 |
| - }); |
421 |
| - |
422 |
| - xmlHttp.addEventListener('readystatechange', function(p) { |
423 |
| - if ( |
424 |
| - xmlHttp.readyState === 4 && |
425 |
| - xmlHttp.status >= 200 && |
426 |
| - xmlHttp.status < 300 |
427 |
| - ) { |
428 |
| - window.setTimeout(handleReloadFS, 100); |
429 |
| - progressObj.classList.add('fadeout'); |
430 |
| - // fade progress |
431 |
| - } // if |
| 364 | + fetch('/', { method: 'POST', body: formData }).then(function() { |
| 365 | + toastObj.info(`done.`); |
432 | 366 | });
|
433 |
| - xmlHttp.open('POST', '/'); |
434 |
| - xmlHttp.send(formData); |
435 | 367 | }
|
436 | 368 |
|
437 |
| - const box = document.getElementById('dropzone'); |
438 |
| - box.addEventListener('dragenter', dragHelper, false); |
439 |
| - box.addEventListener('dragover', dragHelper, false); |
440 |
| - box.addEventListener('drop', drop, false); |
| 369 | + filesObj.addEventListener('dragenter', dragHelper, false); |
| 370 | + filesObj.addEventListener('dragover', dragHelper, false); |
| 371 | + filesObj.addEventListener('drop', drop, false); |
441 | 372 |
|
442 | 373 | window.addEventListener('DOMContentLoaded', handleReloadFS);
|
443 | 374 | window.addEventListener('hashchange', handleReloadFS);
|
@@ -484,12 +415,12 @@ <h3 style="display: inline-block; margin: 0">
|
484 | 415 | // eslint-disable-next-line @typescript-eslint/no-this-alias
|
485 | 416 | var scope = this;
|
486 | 417 | this.disabled = true;
|
487 |
| - DelayPromise(90) // give some time to display progress stuff |
| 418 | + DelayPromise(20) // give some time to display progress stuff |
488 | 419 | .then(function() {
|
489 | 420 | return fetch('/api/reboot');
|
490 | 421 | })
|
491 | 422 | .then(function() {
|
492 |
| - return DelayPromise(90); |
| 423 | + return DelayPromise(20); |
493 | 424 | })
|
494 | 425 | .finally(function(result) {
|
495 | 426 | scope.disabled = false;
|
|
0 commit comments