Class: AttachmentViewer

AttachmentViewer()

new AttachmentViewer()

(view) Show attachment and preview if possible
Source:

Methods

(private, static) addClipboardEventHandler()

attaches the clipboard attachment handler to the page
Source:

(private, static) addDragDropHandler()

attaches the file attachment drag & drop handler to the page
Source:

(static) clearDragAndDrop()

Cleares the drag & drop data.
Source:

(static) getAttachmentMimeType(attachmentData)

Get attachment mime type
Parameters:
Name Type Description
attachmentData string Base64 string
Source:

(static) getAttachmentPreview() → {HTMLElement}

getter for attachment preview
Source:
Returns:
Type
HTMLElement

(static) getAttachments() → {array}

return the attachments
Source:
Returns:
Type
array

(static) getAttachmentsData() → {Array.<string>}

getter for attachment data
Source:
Returns:
Type
Array.<string>

(private, static) getBlobUrl(data, data) → {string}

get blob URL from string data and mime type
Parameters:
Name Type Description
data string raw data of attachment
data string mime type of attachment
Source:
Returns:
objectURL
Type
string

(static) getFiles() → {Array.<FileList>}

getter for files data, returns the file list
Source:
Returns:
Type
Array.<FileList>

(static) handleBlobAttachmentPreview(targetElementnullable, blobUrl, mimeType)

handle the preview of files decoded to blob that can either be an image, video, audio or pdf element
Parameters:
Name Type Attributes Description
targetElement HTMLElement <nullable>
element where the preview should be appended
blobUrl string as a blob URL
mimeType string type
Source:

(static) hasAttachment()

checks if there is an attachment displayed
Source:

(static) hasAttachmentData()

checks if there is attachment data (for preview!) available It returns true, when there is data that needs to be encrypted.
Source:

(static) hasAttachmentPreview() → {boolean}

checks if has any attachment preview that is currently rendered Note: This does not verify if the attachment preview is actually shown to the user, as it might be hidden ({@see AttachmentViewer.hideAttachmentPreview}).
Source:
Returns:
Type
boolean

(static) hideAttachment()

hides the attachment This will not hide the preview (see {@see AttachmentViewer.hideAttachmentPreview} for that) nor will it hide the attachment link if it was moved somewhere else (see {@see AttachmentViewer.moveAttachmentTo}).
Source:

(static) hideAttachmentPreview()

hides the attachment preview
Source:

(static) init()

initiate preloads HTMLElements
Source:

(static) isSafeMimeType() → {bool}

Evaluates whether this is known a safe mime type. This means, the media can safely be displayed and e.g. no XSS should be possible.
Parameters:
Type Description
string
Source:
Returns:
Type
bool

(static) moveAttachmentTo(element, attachment, label)

moves the attachment link to another element It is advisable to hide the attachment afterwards (AttachmentViewer.hideAttachment)
Parameters:
Name Type Description
element HTMLElement the wrapper/container element where this should be moved to
attachment array attachment data
label string the text to show (%s will be replaced with the file name), will automatically be translated
Source:

(private, static) printDragAndDropFileNames(fileNames)

Print file names added via drag & drop
Parameters:
Name Type Description
fileNames Array.<string>
Source:

(private, static) readFileData(loadedFiles)

read files data as data URL using the FileReader API
Parameters:
Name Type Description
loadedFiles Array.<FileList> (optional) loaded files array
Source:
See:

(static) removeAttachment()

removes the attachment This automatically hides the attachment containers too, to prevent an inconsistent display.
Source:

(static) removeAttachmentData()

removes the attachment data This removes the data, which would be uploaded otherwise.
Source:

(static) setAttachment(attachmentData, fileName)

sets the attachment but does not yet show it
Parameters:
Name Type Description
attachmentData string base64-encoded data of file
fileName string optional, file name
Source:

(static) showAttachment()

displays the attachment and (if possible) the preview
Source: