Fossil SCM

Added a Cancel button to the drag/drop file/image field to clear the pending blob. Still need to hook it up to interact with the file input field, but that will have to wait a bit.

stephan 2020-12-23 10:41 UTC chatroom-dev
Commit 018084c50ed42659c7276eef388c6cb38576c1284a5ac0ef0bdae0beb79ff134
1 file changed +4
--- src/chat.js
+++ src/chat.js
@@ -14,19 +14,23 @@
1414
data. */
1515
const updateDropZoneContent = function(blob){
1616
const bx = BlobXferState, dd = bx.dropDetails;
1717
bx.blob = blob;
1818
D.clearElement(dd);
19
+ if(!blob) return;
1920
D.append(dd, D.br(), "Name: ", blob.name,
2021
D.br(), "Size: ",blob.size);
2122
if(blob.type && blob.type.startsWith("image/")){
2223
const img = D.img();
2324
D.append(dd, D.br(), img);
2425
const reader = new FileReader();
2526
reader.onload = (e)=>img.setAttribute('src', e.target.result);
2627
reader.readAsDataURL(blob);
2728
}
29
+ const btn = D.button("Cancel");
30
+ D.append(dd, D.br(), btn);
31
+ btn.addEventListener('click', ()=>updateDropZoneContent(), false);
2832
};
2933
////////////////////////////////////////////////////////////
3034
// File drag/drop.
3135
// Adapted from: https://stackoverflow.com/a/58677161
3236
const dropHighlight = BlobXferState.dropZone /* target zone */;
3337
--- src/chat.js
+++ src/chat.js
@@ -14,19 +14,23 @@
14 data. */
15 const updateDropZoneContent = function(blob){
16 const bx = BlobXferState, dd = bx.dropDetails;
17 bx.blob = blob;
18 D.clearElement(dd);
 
19 D.append(dd, D.br(), "Name: ", blob.name,
20 D.br(), "Size: ",blob.size);
21 if(blob.type && blob.type.startsWith("image/")){
22 const img = D.img();
23 D.append(dd, D.br(), img);
24 const reader = new FileReader();
25 reader.onload = (e)=>img.setAttribute('src', e.target.result);
26 reader.readAsDataURL(blob);
27 }
 
 
 
28 };
29 ////////////////////////////////////////////////////////////
30 // File drag/drop.
31 // Adapted from: https://stackoverflow.com/a/58677161
32 const dropHighlight = BlobXferState.dropZone /* target zone */;
33
--- src/chat.js
+++ src/chat.js
@@ -14,19 +14,23 @@
14 data. */
15 const updateDropZoneContent = function(blob){
16 const bx = BlobXferState, dd = bx.dropDetails;
17 bx.blob = blob;
18 D.clearElement(dd);
19 if(!blob) return;
20 D.append(dd, D.br(), "Name: ", blob.name,
21 D.br(), "Size: ",blob.size);
22 if(blob.type && blob.type.startsWith("image/")){
23 const img = D.img();
24 D.append(dd, D.br(), img);
25 const reader = new FileReader();
26 reader.onload = (e)=>img.setAttribute('src', e.target.result);
27 reader.readAsDataURL(blob);
28 }
29 const btn = D.button("Cancel");
30 D.append(dd, D.br(), btn);
31 btn.addEventListener('click', ()=>updateDropZoneContent(), false);
32 };
33 ////////////////////////////////////////////////////////////
34 // File drag/drop.
35 // Adapted from: https://stackoverflow.com/a/58677161
36 const dropHighlight = BlobXferState.dropZone /* target zone */;
37

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button