feat: first working version
This commit is contained in:
32
admin/js/category-image.js
Normal file
32
admin/js/category-image.js
Normal 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 l’ouvre
|
||||
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 l’image"
|
||||
$( '.ccgw-remove-image' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
$( '#category-image-id' ).val('');
|
||||
$( '#category-image-wrapper' ).html('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user