Allow pasting images

- Update CSS on post button
This commit is contained in:
MatthiasSaihttam 2020-12-02 15:28:15 -05:00
parent 7f52c5de98
commit d4c73bae29
2 changed files with 18 additions and 1 deletions

View File

@ -25,5 +25,5 @@ textarea.thought {
font-size: 32px;
color: var(--text-color);
cursor: pointer;
float: right;
font-family: Georgia, Libre Baskerville, serif;
}

View File

@ -68,6 +68,23 @@
//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