Cloudinary Upload Widget V1

PHOTO EMBED

Fri Feb 09 2024 18:26:52 GMT+0000 (Coordinated Universal Time)

Saved by @FOrestNAtion

<script src="https://upload-widget.cloudinary.com/global/all.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    // Function to initialize Cloudinary widget and handle upload success
    function setupCloudinaryWidget(editButtonId, urlFieldSelector, submitButtonSelector) {
        var widget = cloudinary.createUploadWidget({
            cloudName: "drt2tlz1j",
            uploadPreset: "giftWidget",
            show_powered_by: false,
            sources: ["local"],
            showAdvancedOptions: false,
            cropping: false,
            multiple: false,
					folder: "gs-uploads",
					showCompletedButton: true,
            defaultSource: "local",
            styles: {
                palette: {
                    window: "rgba(71, 80, 72, 0.74)",
                    windowBorder: "rgba(71, 80, 72, 0.00)",
                    tabIcon: "#009A42",
                    menuIcons: "#FFFFFF",
                    textDark: "#FFFFFF",
                    textLight: "#FFFFFF",
                    link: "#009A42",
                    action: "#009A42",
                    inactiveTabIcon: "#FFFFFF",
                    error: "#FA9B32",
                    inProgress: "#009A42",
                    complete: "#009A42",
                    sourceBg: "rgba(71, 80, 72, 0.37)"
                },
                fonts: { default: { active: true } }
            }
        }, (error, result) => {
            if (!error && result && result.event === "success") {
                console.log('Done! Here is the image info: ', result.info);
                var uploadedUrl = result.info.secure_url;
                
                // Fill the ACF URL field with the uploaded URL
                $(urlFieldSelector).val(uploadedUrl);
                
                // Submit the ACF form
                $(submitButtonSelector).click();
            }
        });

        // Attach click event to the edit button to open the widget
        $(editButtonId).on('click', function() {
            widget.open();
        });
    }

    // Setup Cloudinary widget for each edit button, URL field, and submit button
    setupCloudinaryWidget("#slide1edit", "input[name='acf[field_65c630a53001b]']", "button[name='acf[field_65c630e33001f]']");
    setupCloudinaryWidget("#slide2edit", "input[name='acf[field_65c630c93001c]']", "button[name='acf[field_65c6311130020]']");
    setupCloudinaryWidget("#slide3edit", "input[name='acf[field_65c630cf3001d]']", "button[name='acf[field_65c6311930021]']");
    setupCloudinaryWidget("#slide4edit", "input[name='acf[field_62a3a9b9aa9f6]']", "button[name='acf[field_65c6312330022]']");
});
</script>
content_copyCOPY