HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/dreamsrent-wp/wp-content/themes/dreamsrent/assets/js/brand-image-upload.js
jQuery(document).ready(function ($) {
    function openMediaUploader(button, input, preview) {
        var frame = wp.media({
            title: 'Select or Upload Image',
            button: { text: 'Use this image' },
            multiple: false
        });

        frame.on('select', function () {
            var attachment = frame.state().get('selection').first().toJSON();
            input.val(attachment.id);
            preview.html('<img src="' + attachment.url + '" style="max-width:100px;" />');
        });

        frame.open();
    }

    $(document).on('click', '.brand-image-upload-button', function (e) {
        e.preventDefault();
        var $button = $(this);
        var $parent = $button.closest('.form-field, .form-table');
        var $input = $parent.find('input[name="brand_image"]');
        var $preview = $parent.find('#brand_image_preview');
        openMediaUploader($button, $input, $preview);
    });
});