Files
elementor-category-grid-widget/admin/js/category-image.js
2025-05-23 09:54:50 +00:00

33 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
jQuery( document ).ready( function( $ ) {
var frame;
// Quand on clique sur "Choisir une image"
$( '.ccgw-upload-image' ).on( 'click', function( e ) {
e.preventDefault();
// Si le frame existe déjà, on louvre
if ( frame ) {
frame.open();
return;
}
// Créer le frame
frame = wp.media({
title: ccgw_data.title || 'Choisir une image de catégorie',
button: { text: ccgw_data.button || 'Sélectionner' },
multiple: false
});
// Quand on sélectionne une image
frame.on( 'select', function() {
var attachment = frame.state().get('selection').first().toJSON();
$( '#category-image-id' ).val( attachment.id );
$( '#category-image-wrapper' ).html( '<img src="' + attachment.sizes.thumbnail.url + '" style="max-width:100px;height:auto;" />' );
});
frame.open();
});
// Quand on clique sur "Supprimer limage"
$( '.ccgw-remove-image' ).on( 'click', function( e ) {
e.preventDefault();
$( '#category-image-id' ).val('');
$( '#category-image-wrapper' ).html('');
});
});