mirror of
https://github.com/friendica/friendica
synced 2025-01-29 05:39:47 +00:00
add upload for video/*, audio/* and application/* via dropzone
Upload videos, audios and documents (all mimetype application/*) via Drag&Drop and Copy&Paste in new postings and comments as attachments. The same as images before with placeholder on insert-position. You can write text while upload is done.
This commit is contained in:
parent
c47323e358
commit
6e6903e073
1 changed files with 28 additions and 4 deletions
|
@ -9,7 +9,7 @@ var DzFactory = function (max_imagesize) {
|
||||||
paramName: 'userfile', // The name that will be used to transfer the file
|
paramName: 'userfile', // The name that will be used to transfer the file
|
||||||
maxFilesize: max_imagesize, // MB
|
maxFilesize: max_imagesize, // MB
|
||||||
url: '/media/photo/upload?album=',
|
url: '/media/photo/upload?album=',
|
||||||
acceptedFiles: 'image/*',
|
acceptedFiles: 'image/*,video/*,audio/*,application/*',
|
||||||
clickable: true,
|
clickable: true,
|
||||||
dictDefaultMessage: dzStrings.dictDefaultMessage,
|
dictDefaultMessage: dzStrings.dictDefaultMessage,
|
||||||
dictFallbackMessage: dzStrings.dictFallbackMessage,
|
dictFallbackMessage: dzStrings.dictFallbackMessage,
|
||||||
|
@ -25,21 +25,45 @@ var DzFactory = function (max_imagesize) {
|
||||||
accept: function(file, done) {
|
accept: function(file, done) {
|
||||||
const targetTextarea = document.getElementById(textareaElementId);
|
const targetTextarea = document.getElementById(textareaElementId);
|
||||||
if (targetTextarea.setRangeText) {
|
if (targetTextarea.setRangeText) {
|
||||||
targetTextarea.setRangeText("\n[upload-" + file.name + "]\n", targetTextarea.selectionStart, targetTextarea.selectionEnd, "end");
|
targetTextarea.setRangeText("\n[!upload-" + file.name + "]\n", targetTextarea.selectionStart, targetTextarea.selectionEnd, "end");
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
init: function() {
|
init: function() {
|
||||||
|
this.on("processing", function(file) {
|
||||||
|
switch(file.type) {
|
||||||
|
case String(file.type.match(/image\/.*/)):
|
||||||
|
this.options.url = "/media/photo/upload?album=";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.options.url = "/media/attachment/upload?response=json";
|
||||||
|
}
|
||||||
|
});
|
||||||
this.on('success', function(file, serverResponse) {
|
this.on('success', function(file, serverResponse) {
|
||||||
const targetTextarea = document.getElementById(textareaElementId);
|
const targetTextarea = document.getElementById(textareaElementId);
|
||||||
if (targetTextarea.setRangeText) {
|
if (targetTextarea.setRangeText) {
|
||||||
//if setRangeText function is supported by current browser
|
//if setRangeText function is supported by current browser
|
||||||
let u = "[upload-" + file.name + "]";
|
let u = "[!upload-" + file.name + "]";
|
||||||
|
let srp = serverResponse;
|
||||||
|
if (typeof serverResponse === 'object' &&
|
||||||
|
serverResponse.constructor === Object) {
|
||||||
|
if (serverResponse.ok) {
|
||||||
|
srp = "[attachment]" +
|
||||||
|
window.location.protocol +
|
||||||
|
"//" +
|
||||||
|
window.location.host +
|
||||||
|
"/attach/" +
|
||||||
|
serverResponse.id +
|
||||||
|
"[/attachment]";
|
||||||
|
} else {
|
||||||
|
srp = "Upload failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
let c = targetTextarea.selectionStart;
|
let c = targetTextarea.selectionStart;
|
||||||
if (c > targetTextarea.value.indexOf(u)) {
|
if (c > targetTextarea.value.indexOf(u)) {
|
||||||
c = c + serverResponse.length - u.length;
|
c = c + serverResponse.length - u.length;
|
||||||
}
|
}
|
||||||
targetTextarea.setRangeText(serverResponse, targetTextarea.value.indexOf(u), targetTextarea.value.indexOf(u) + u.length);
|
targetTextarea.setRangeText(srp, targetTextarea.value.indexOf(u), targetTextarea.value.indexOf(u) + u.length);
|
||||||
targetTextarea.selectionStart = c;
|
targetTextarea.selectionStart = c;
|
||||||
targetTextarea.selectionEnd = c;
|
targetTextarea.selectionEnd = c;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue