Wall: Fix attachment of files in the comment popup

This commit is contained in:
Maxim Leshchenko 2021-12-02 14:01:48 +02:00
parent 5f9b36de5f
commit 7f43458cda
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
2 changed files with 17 additions and 12 deletions

View file

@ -49,20 +49,20 @@
<br/>
<input type="submit" value="{_'write'}" class="button" />
<div style="float: right; display: flex; flex-direction: column;">
<a href="javascript:void(u('#wallAttachmentMenu').toggleClass('hidden'));">
<a href="javascript:void(u('#post-buttons{$textAreaId} #wallAttachmentMenu').toggleClass('hidden'));">
Прикрепить
</a>
<div id="wallAttachmentMenu" class="hidden">
<a href="javascript:void(document.querySelector('input[name=_pic_attachment]').click());">
<a href="javascript:void(document.querySelector('#post-buttons{$textAreaId} input[name=_pic_attachment]').click());">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-egon.png" />
{_attach_photo}
</a>
<a href="javascript:void(document.querySelector('input[name=_vid_attachment]').click());">
<a href="javascript:void(document.querySelector('#post-buttons{$textAreaId} input[name=_vid_attachment]').click());">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-vnd.rn-realmedia.png" />
Прикрепить видео
</a>
<a n:if="$graffiti ?? false" href="javascript:initGraffiti();">
<a n:if="$graffiti ?? false" href="javascript:initGraffiti({$textAreaId});">
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/actions/draw-brush.png" />
Нарисовать граффити
</a>
@ -72,6 +72,12 @@
</form>
</div>
<script>
$(document).ready(() => u("#post-buttons{$textAreaId} .postFileSel").on("change", function() {
handleUpload.bind(this, {$textAreaId})();
}));
</script>
{if $graffiti}
{script "js/node_modules/react/dist/react-with-addons.min.js"}
{script "js/node_modules/react-dom/dist/react-dom.min.js"}

View file

@ -22,12 +22,13 @@ function trim(string) {
return newStr;
}
function handleUpload() {
function handleUpload(id) {
console.warn("блять...");
u(".postFileSel").not("#" + this.id).each(input => input.value = null);
document.querySelector("input[name='_poll_attachment']").value = "";
u(".postFileSel" + id).not("#" + this.id).each(input => input.value = null);
var indicator = u(".post-upload");
var indicator = u("#post-buttons" + id + " .post-upload");
var file = this.files[0];
if(typeof file === "undefined") {
indicator.attr("style", "display: none;");
@ -37,7 +38,7 @@ function handleUpload() {
}
}
function initGraffiti() {
function initGraffiti(id) {
let canvas = null;
let msgbox = MessageBox("Нарисовать граффити", "<div id='ovkDraw'></div>", ["Сохранить", "Отменить"], [function() {
canvas.getImage({includeWatermark: false}).toBlob(blob => {
@ -46,11 +47,11 @@ function initGraffiti() {
let trans = new DataTransfer();
trans.items.add(image);
let fileSelect = document.querySelector("input[name='_pic_attachment']");
let fileSelect = document.querySelector("#post-buttons" + id + " input[name='_pic_attachment']");
fileSelect.files = trans.files;
u(fileSelect).trigger("change");
u("#write textarea").trigger("focusin");
u("#post-buttons" + id + " #write textarea").trigger("focusin");
}, "image/jpeg", 0.92);
canvas.teardown();
@ -113,5 +114,3 @@ u("#wall-post-input").on("input", function(e) {
// revert to original size if it is larger (possibly changed by user)
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
});
u(".postFileSel").on("change", handleUpload);