Wall: Fix pasting attachments from the clipboard in the post creation form

Also fixup previous commit
This commit is contained in:
Maxim Leshchenko 2021-12-02 14:37:16 +02:00
parent 7f43458cda
commit 34f4f8fc5d
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
2 changed files with 29 additions and 24 deletions

View file

@ -73,9 +73,13 @@
</div>
<script>
$(document).ready(() => u("#post-buttons{$textAreaId} .postFileSel").on("change", function() {
handleUpload.bind(this, {$textAreaId})();
}));
$(document).ready(() => {
u("#post-buttons{$textAreaId} .postFileSel").on("change", function() {
handleUpload.bind(this, {$textAreaId})();
});
setupWallPostInputHandlers({$textAreaId});
});
</script>
{if $graffiti}

View file

@ -25,8 +25,7 @@ function trim(string) {
function handleUpload(id) {
console.warn("блять...");
document.querySelector("input[name='_poll_attachment']").value = "";
u(".postFileSel" + id).not("#" + this.id).each(input => input.value = null);
u("#post-buttons" + id + " .postFileSel").not("#" + this.id).each(input => input.value = null);
var indicator = u("#post-buttons" + id + " .post-upload");
var file = this.files[0];
@ -74,15 +73,6 @@ function initGraffiti(id) {
});
}
u("#wall-post-input").on("paste", function(e) {
if(e.clipboardData.files.length === 1) {
var input = u("input[name=_pic_attachment]").nodes[0];
input.files = e.clipboardData.files;
u(input).trigger("change");
}
});
u(".post-like-button").on("click", function(e) {
e.preventDefault();
@ -103,14 +93,25 @@ u(".post-like-button").on("click", function(e) {
return false;
});
u("#wall-post-input").on("input", function(e) {
var boost = 5;
var textArea = e.target;
textArea.style.height = "5px";
var newHeight = textArea.scrollHeight;
textArea.style.height = newHeight + boost;
return;
function setupWallPostInputHandlers(id) {
u("#wall-post-input" + id).on("paste", function(e) {
if(e.clipboardData.files.length === 1) {
var input = u("#post-buttons" + id + " input[name=_pic_attachment]").nodes[0];
input.files = e.clipboardData.files;
u(input).trigger("change");
}
});
// revert to original size if it is larger (possibly changed by user)
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
});
u("#wall-post-input" + id).on("input", function(e) {
var boost = 5;
var textArea = e.target;
textArea.style.height = "5px";
var newHeight = textArea.scrollHeight;
textArea.style.height = newHeight + boost;
return;
// revert to original size if it is larger (possibly changed by user)
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
});
}