HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/admin-modal/general/Media.js
import { __wprm } from 'Shared/Translations';

const Media = {
    selectImage( callback ) {
        this.select( 'image', callback );
    },
    selectVideo( callback ) {
        this.select( 'video', callback );
    },
    select( type, callback ) {
        let media_arguments = {
            title: __wprm( 'Select Media' ),
            button: {
                text: __wprm( 'Select' ),
            },
            multiple: false,
        };
    
        // Check what media type we're getting.
        if ( 'video' === type ) {
            media_arguments.frame = 'video';
            media_arguments.state = 'video-details';
        } else {
            // Default to image.
            media_arguments.library = {
                type: 'image',
            };
        }
    
        // Create a new media frame (don't reuse because we have multiple different inputs)
        let frame = wp.media(media_arguments);
    
        // Handle image selection
        frame.on('select', function() {
            var attachment = frame.state().get('selection').first().toJSON();
            callback( attachment );
        });
    
        // Handle video selection
        frame.on('update', function() {
            let attachment = frame.state().media.attachment;
    
            if ( attachment ) {
                callback( attachment );
            }
        });
    
        // Finally, open the modal on click
        frame.open();
    }
}
export default Media;