Cloudinary Upload Widget V3
Mon Feb 12 2024 17:24:20 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", "image_search", "camera"],
defaultSource: "local",
googleApiKey: "AIzaSyAhy7PJXH7_3t9qbIiczK5nZHsaUOGEFMM",
showAdvancedOptions: false,
cropping: false,
multiple: false,
folder: "gs-uploads",
clientAllowedFormats: ["image/*", "video/*", "mp4", "mov", "webm", "webp", "gif", "jpg", "png", "svg"],
showCompletedButton: true,
styles: {
palette: {
window: "rgba(71, 80, 72, 0.74)",
windowBorder: "#FFFFFF",
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_65c630d63001e]']", "button[name='acf[field_65c6312330022]']");
});
</script>



Comments