|
|
@ -200,63 +200,66 @@ export function initGlobalCommon() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function initGlobalDropzone() { |
|
|
|
export function initGlobalDropzone() { |
|
|
|
// Dropzone
|
|
|
|
|
|
|
|
for (const el of document.querySelectorAll('.dropzone')) { |
|
|
|
for (const el of document.querySelectorAll('.dropzone')) { |
|
|
|
const $dropzone = $(el); |
|
|
|
initDropzone(el); |
|
|
|
const _promise = createDropzone(el, { |
|
|
|
} |
|
|
|
url: $dropzone.data('upload-url'), |
|
|
|
} |
|
|
|
headers: {'X-Csrf-Token': csrfToken}, |
|
|
|
|
|
|
|
maxFiles: $dropzone.data('max-file'), |
|
|
|
export function initDropzone(el) { |
|
|
|
maxFilesize: $dropzone.data('max-size'), |
|
|
|
const $dropzone = $(el); |
|
|
|
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'), |
|
|
|
const _promise = createDropzone(el, { |
|
|
|
addRemoveLinks: true, |
|
|
|
url: $dropzone.data('upload-url'), |
|
|
|
dictDefaultMessage: $dropzone.data('default-message'), |
|
|
|
headers: {'X-Csrf-Token': csrfToken}, |
|
|
|
dictInvalidFileType: $dropzone.data('invalid-input-type'), |
|
|
|
maxFiles: $dropzone.data('max-file'), |
|
|
|
dictFileTooBig: $dropzone.data('file-too-big'), |
|
|
|
maxFilesize: $dropzone.data('max-size'), |
|
|
|
dictRemoveFile: $dropzone.data('remove-file'), |
|
|
|
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'), |
|
|
|
timeout: 0, |
|
|
|
addRemoveLinks: true, |
|
|
|
thumbnailMethod: 'contain', |
|
|
|
dictDefaultMessage: $dropzone.data('default-message'), |
|
|
|
thumbnailWidth: 480, |
|
|
|
dictInvalidFileType: $dropzone.data('invalid-input-type'), |
|
|
|
thumbnailHeight: 480, |
|
|
|
dictFileTooBig: $dropzone.data('file-too-big'), |
|
|
|
init() { |
|
|
|
dictRemoveFile: $dropzone.data('remove-file'), |
|
|
|
this.on('success', (file, data) => { |
|
|
|
timeout: 0, |
|
|
|
file.uuid = data.uuid; |
|
|
|
thumbnailMethod: 'contain', |
|
|
|
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid); |
|
|
|
thumbnailWidth: 480, |
|
|
|
$dropzone.find('.files').append(input); |
|
|
|
thumbnailHeight: 480, |
|
|
|
// Create a "Copy Link" element, to conveniently copy the image
|
|
|
|
init() { |
|
|
|
// or file link as Markdown to the clipboard
|
|
|
|
this.on('success', (file, data) => { |
|
|
|
const copyLinkElement = document.createElement('div'); |
|
|
|
file.uuid = data.uuid; |
|
|
|
copyLinkElement.className = 'gt-text-center'; |
|
|
|
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid); |
|
|
|
// The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone
|
|
|
|
$dropzone.find('.files').append(input); |
|
|
|
copyLinkElement.innerHTML = `<a href="#" style="cursor: pointer;">${svg('octicon-copy', 14, 'copy link')} Copy link</a>`; |
|
|
|
// Create a "Copy Link" element, to conveniently copy the image
|
|
|
|
copyLinkElement.addEventListener('click', async (e) => { |
|
|
|
// or file link as Markdown to the clipboard
|
|
|
|
e.preventDefault(); |
|
|
|
const copyLinkElement = document.createElement('div'); |
|
|
|
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; |
|
|
|
copyLinkElement.className = 'gt-text-center'; |
|
|
|
if (file.type.startsWith('image/')) { |
|
|
|
// The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone
|
|
|
|
fileMarkdown = `!${fileMarkdown}`; |
|
|
|
copyLinkElement.innerHTML = `<a href="#" style="cursor: pointer;">${svg('octicon-copy', 14, 'copy link')} Copy link</a>`; |
|
|
|
} else if (file.type.startsWith('video/')) { |
|
|
|
copyLinkElement.addEventListener('click', async (e) => { |
|
|
|
fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`; |
|
|
|
e.preventDefault(); |
|
|
|
} |
|
|
|
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; |
|
|
|
const success = await clippie(fileMarkdown); |
|
|
|
if (file.type.startsWith('image/')) { |
|
|
|
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error); |
|
|
|
fileMarkdown = `!${fileMarkdown}`; |
|
|
|
}); |
|
|
|
} else if (file.type.startsWith('video/')) { |
|
|
|
file.previewTemplate.append(copyLinkElement); |
|
|
|
fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`; |
|
|
|
}); |
|
|
|
|
|
|
|
this.on('removedfile', (file) => { |
|
|
|
|
|
|
|
$(`#${file.uuid}`).remove(); |
|
|
|
|
|
|
|
if ($dropzone.data('remove-url')) { |
|
|
|
|
|
|
|
POST($dropzone.data('remove-url'), { |
|
|
|
|
|
|
|
data: new URLSearchParams({file: file.uuid}), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const success = await clippie(fileMarkdown); |
|
|
|
|
|
|
|
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.on('error', function (file, message) { |
|
|
|
file.previewTemplate.append(copyLinkElement); |
|
|
|
showErrorToast(message); |
|
|
|
}); |
|
|
|
this.removeFile(file); |
|
|
|
this.on('removedfile', (file) => { |
|
|
|
}); |
|
|
|
$(`#${file.uuid}`).remove(); |
|
|
|
}, |
|
|
|
if ($dropzone.data('remove-url')) { |
|
|
|
}); |
|
|
|
POST($dropzone.data('remove-url'), { |
|
|
|
} |
|
|
|
data: new URLSearchParams({file: file.uuid}), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.on('error', function (file, message) { |
|
|
|
|
|
|
|
showErrorToast(message); |
|
|
|
|
|
|
|
this.removeFile(file); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function linkAction(e) { |
|
|
|
async function linkAction(e) { |
|
|
|