Skip to content

Conversation

@zaxbux
Copy link
Contributor

@zaxbux zaxbux commented Apr 23, 2023

This exposes additional file metadata to the Media Manager popup onInsert() callback.

Possible Use Case

WYSIWYG editor plugin that inserts links to files which display the file size.

image

Example JavaScript

function onInsertMedia() {
    new $.wn.mediaManager.popup({
        alias: 'wnmediamanager',
        mode: 'all', // all | image | video | audio | document
        bottomToolbar: true,
        cropAndInsertButton: false,
        onInsert: function (items) {
            if (!items.length) {
                $.wn.alert($.wn.lang.get('mediamanager.invalid_file_empty_insert'))
                return
            }

            if (items.length > 1) {
                $.wn.alert($.wn.lang.get('mediamanager.invalid_file_single_insert'))
                return
            }

            const {
                // itemType,     // file | folder
                // path,         // path relative to media library root
                // title,        // file name

                /* Additional attributes */
                sizeBytes,
                lastModified,

                // documentType, // image | video | audio | document
                // folder,
                // publicUrl,
            } = item[0];

            this.hide();
        },
        onClose: function () {},
    }
}

@LukeTowers LukeTowers added Status: Completed enhancement PRs that implement a new feature or substantial change labels Apr 23, 2023
@LukeTowers LukeTowers added this to the v1.2.2 milestone Apr 23, 2023
@LukeTowers LukeTowers changed the title Media Manager file metadata enhancements Add sizeBytes & lastModified to mediamanager.js getItems() Apr 23, 2023
@LukeTowers LukeTowers merged commit fb80727 into wintercms:develop Apr 23, 2023
@zaxbux zaxbux deleted the mediamanager-file-meta-enhancement branch April 23, 2023 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that implement a new feature or substantial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants