Add pasting with the new media system

This commit is contained in:
MatthiasSaihttam 2021-05-03 02:00:50 -04:00
parent 0583ee40f0
commit 7183ca8317
1 changed files with 12 additions and 18 deletions

View File

@ -30,7 +30,7 @@
const textEl = document.getElementById("text");
const textExtEl = document.getElementById("extended_text");
textEl.addEventListener("input", evt => {
// If the length is more than 120
// If the length is more than 140
const value = textEl.value;
if (value.length > 140) {
const splitAt = value.lastIndexOf(" ", 140) + 1; // Plus 1 keeps the space in the original text instead of moving it
@ -63,23 +63,6 @@
//textEl.style.width = textEl.scrollWidth + "px";
});
//Allow pasting images into the extended text text-box
textExtEl.addEventListener("paste", (evt) => {
const items = evt.clipboardData.items;
const el = evt.target;
for (const item of items) {
//Mac clipboard at least only handles PNGs
if ("image/png" === item.type) {
const reader = new FileReader();
reader.addEventListener("load", evt => {
const newText = `![](${evt.target.result})`;
el.value = el.value.slice(0, el.selectionStart) + newText + el.value.slice(el.selectionEnd);
});
reader.readAsDataURL(item.getAsFile());
}
}
});
const textboxes = document.getElementsByClassName("thought");
for (const box of textboxes) {
//style.height doesn't include padding, .scrollHeight does
@ -91,6 +74,17 @@
box.style.height = "auto";
box.style.height = box.scrollHeight + "px";
});
//Allow pasting images into either text box
box.addEventListener("paste", evt => {
const files = evt.clipboardData.files;
// We can only use the first image from the pasteboard
if (files && files.length > 0) {
// This seems to only allow entry of a single file
const el = document.getElementById("media");
el.files = files;
}
});
}
const timezoneOffsetEl = document.getElementById("timezone_offset");