feat: first working version

This commit is contained in:
MrRaph_
2025-05-23 09:54:50 +00:00
parent acbd9bbad5
commit 20f9c31008
3 changed files with 468 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
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('');
});
});