1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-21 21:30:08 +00:00

Add preview for non-images in attachment dialog

This commit is contained in:
Maximilian Mader 2021-02-04 22:45:02 +01:00
parent c241df9470
commit 57fbe3d3e9
Signed by: Max
GPG Key ID: F71D56A3151C4FB3

View File

@ -48,7 +48,6 @@ define([
super(buttonContainerId, previewContainerId, { super(buttonContainerId, previewContainerId, {
className: 'wcf\\data\\attachment\\AttachmentAction', className: 'wcf\\data\\attachment\\AttachmentAction',
acceptableFiles: ['.png', '.gif', '.jpg', '.jpeg'],
}) })
this.input = input this.input = input
@ -209,8 +208,11 @@ define([
* @see WoltLabSuite/Core/Upload#_success * @see WoltLabSuite/Core/Upload#_success
*/ */
_success(uploadId, data, responseText, xhr, requestOptions) { _success(uploadId, data, responseText, xhr, requestOptions) {
if (data.returnValues.errors && data.returnValues.errors[0]) { const target = this._fileElements[uploadId][0]
const error = data.returnValues.errors[0] const progress = target.querySelector(':scope > progress')
if (data.returnValues.errors && data.returnValues.errors[uploadId]) {
const error = data.returnValues.errors[uploadId]
elInnerError( elInnerError(
this._button, this._button,
@ -219,6 +221,8 @@ define([
}) })
) )
progress.remove()
return return
} else { } else {
elInnerError(this._button, '') elInnerError(this._button, '')
@ -237,6 +241,8 @@ define([
elHide(this.uploadDescription) elHide(this.uploadDescription)
const attachment = data.returnValues.attachments[uploadId] const attachment = data.returnValues.attachments[uploadId]
if (attachment.isImage) {
const url = const url =
attachment.thumbnailURL || attachment.tinyURL || attachment.url attachment.thumbnailURL || attachment.tinyURL || attachment.url
@ -244,9 +250,6 @@ define([
throw new Error('Missing image URL') throw new Error('Missing image URL')
} }
const target = this._fileElements[uploadId][0]
const progress = target.querySelector(':scope > progress')
const img = document.createElement('img') const img = document.createElement('img')
img.setAttribute('src', url) img.setAttribute('src', url)
img.setAttribute('alt', '') img.setAttribute('alt', '')
@ -261,6 +264,13 @@ define([
img.dataset.height = attachment.height img.dataset.height = attachment.height
DomUtil.replaceElement(progress, img) DomUtil.replaceElement(progress, img)
} else {
const anchor = document.createElement('a')
anchor.setAttribute('href', attachment.url)
anchor.innerText = attachment.filename
DomUtil.replaceElement(progress, anchor)
}
this.createButtons(uploadId, attachment.attachmentID, this.tmpHash) this.createButtons(uploadId, attachment.attachmentID, this.tmpHash)