Fossil SCM

Chat clipboard paste: pasted text, regardless of event target, now goes to the input field and pasted images, regardless of the event target, now go into the image-submit slot.

stephan 2020-12-23 08:33 UTC chatroom-dev
Commit 02fa19aa996d44be5732ac36434d256becb2ceb29a8b3bf45416b2c91ede3505
1 file changed +15 -8
+15 -8
--- src/chat.js
+++ src/chat.js
@@ -28,18 +28,25 @@
2828
});
2929
/* Handle image paste from clipboard. TODO: confirm that we only
3030
paste images here (silently ignore non-image data), or change the
3131
related code to support non-image pasting/posting. */
3232
document.onpaste = function(event){
33
- if(form.msg === event.target) return;
34
- const items = event.clipboardData.items;
35
- ImagePasteState.blob = items[0].getAsFile();
36
- const reader = new FileReader();
37
- reader.onload = function(event){
38
- ImagePasteState.imgTag.setAttribute('src', event.target.result);
39
- };
40
- reader.readAsDataURL(ImagePasteState.blob);
33
+ const items = event.clipboardData.items,
34
+ item = items[0];
35
+ if(!item || !item.type) return;
36
+ //console.debug("pasted item =",item);
37
+ if('file'===item.kind && item.type.startsWith("image/")){
38
+ ImagePasteState.blob = items[0].getAsFile();
39
+ //console.debug("pasted blob =",ImagePasteState.blob);
40
+ const reader = new FileReader();
41
+ reader.onload = function(event){
42
+ ImagePasteState.imgTag.setAttribute('src', event.target.result);
43
+ };
44
+ reader.readAsDataURL(ImagePasteState.blob);
45
+ }else if('string'===item.kind){
46
+ item.getAsString((v)=>form.msg.value = v);
47
+ }
4148
};
4249
/* Injects element e as a new row in the chat, at the top of the list */
4350
const injectMessage = function f(e){
4451
if(!f.injectPoint){
4552
f.injectPoint = document.querySelector('#message-inject-point');
4653
--- src/chat.js
+++ src/chat.js
@@ -28,18 +28,25 @@
28 });
29 /* Handle image paste from clipboard. TODO: confirm that we only
30 paste images here (silently ignore non-image data), or change the
31 related code to support non-image pasting/posting. */
32 document.onpaste = function(event){
33 if(form.msg === event.target) return;
34 const items = event.clipboardData.items;
35 ImagePasteState.blob = items[0].getAsFile();
36 const reader = new FileReader();
37 reader.onload = function(event){
38 ImagePasteState.imgTag.setAttribute('src', event.target.result);
39 };
40 reader.readAsDataURL(ImagePasteState.blob);
 
 
 
 
 
 
 
41 };
42 /* Injects element e as a new row in the chat, at the top of the list */
43 const injectMessage = function f(e){
44 if(!f.injectPoint){
45 f.injectPoint = document.querySelector('#message-inject-point');
46
--- src/chat.js
+++ src/chat.js
@@ -28,18 +28,25 @@
28 });
29 /* Handle image paste from clipboard. TODO: confirm that we only
30 paste images here (silently ignore non-image data), or change the
31 related code to support non-image pasting/posting. */
32 document.onpaste = function(event){
33 const items = event.clipboardData.items,
34 item = items[0];
35 if(!item || !item.type) return;
36 //console.debug("pasted item =",item);
37 if('file'===item.kind && item.type.startsWith("image/")){
38 ImagePasteState.blob = items[0].getAsFile();
39 //console.debug("pasted blob =",ImagePasteState.blob);
40 const reader = new FileReader();
41 reader.onload = function(event){
42 ImagePasteState.imgTag.setAttribute('src', event.target.result);
43 };
44 reader.readAsDataURL(ImagePasteState.blob);
45 }else if('string'===item.kind){
46 item.getAsString((v)=>form.msg.value = v);
47 }
48 };
49 /* Injects element e as a new row in the chat, at the top of the list */
50 const injectMessage = function f(e){
51 if(!f.injectPoint){
52 f.injectPoint = document.querySelector('#message-inject-point');
53

Keyboard Shortcuts

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