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> </div>
<script> <script>
$(document).ready(() => u("#post-buttons{$textAreaId} .postFileSel").on("change", function() { $(document).ready(() => {
u("#post-buttons{$textAreaId} .postFileSel").on("change", function() {
handleUpload.bind(this, {$textAreaId})(); handleUpload.bind(this, {$textAreaId})();
})); });
setupWallPostInputHandlers({$textAreaId});
});
</script> </script>
{if $graffiti} {if $graffiti}

View file

@ -25,8 +25,7 @@ function trim(string) {
function handleUpload(id) { function handleUpload(id) {
console.warn("блять..."); console.warn("блять...");
document.querySelector("input[name='_poll_attachment']").value = ""; u("#post-buttons" + id + " .postFileSel").not("#" + this.id).each(input => input.value = null);
u(".postFileSel" + id).not("#" + this.id).each(input => input.value = null);
var indicator = u("#post-buttons" + id + " .post-upload"); var indicator = u("#post-buttons" + id + " .post-upload");
var file = this.files[0]; 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) { u(".post-like-button").on("click", function(e) {
e.preventDefault(); e.preventDefault();
@ -103,7 +93,17 @@ u(".post-like-button").on("click", function(e) {
return false; return false;
}); });
u("#wall-post-input").on("input", function(e) { 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");
}
});
u("#wall-post-input" + id).on("input", function(e) {
var boost = 5; var boost = 5;
var textArea = e.target; var textArea = e.target;
textArea.style.height = "5px"; textArea.style.height = "5px";
@ -113,4 +113,5 @@ u("#wall-post-input").on("input", function(e) {
// revert to original size if it is larger (possibly changed by user) // revert to original size if it is larger (possibly changed by user)
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px"; // textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
}); });
}