Hello, I'm trying to create a gallery element. The purpose of this item is to select several media images and get a preview.
showmodal : function() {
// If we already have a media modal, open it.
if ( ! _.isUndefined( this.media_modal ) ) {
this.media_modal.open();
return;
}
// Create a new media modal.
this.media_modal = wp.media( {
frame : 'select',
multiple : true,
editing : true,
title : this.model.get( 'l10n' ).choose,
library : { type : 'image' },
button : { text: this.model.get( 'l10n' ).set }
} );
// Runs when an image is selected in the media modal.
this.media_modal.on( 'select', function() {
// Gets the JSON data for the first selection.
//var media = this.media_modal.state().get( 'selection' ).first().toJSON();
var media = this.media_modal.state().get( 'selection' ).toJSON();
// Size of image to display.
var size = this.model.attributes.size;
;
// Updates the model for the view.
this.model.set( 'selection' , media ).trigger( 'change', this.model );
}, this );
// Opens the media modal.
this.media_modal.open();
},
I'm gettin an array of selected images in console.log(), but functiont this.model.set() doesnt work at all. Someone know an issue?
Hello, I'm trying to create a gallery element. The purpose of this item is to select several media images and get a preview.
I'm gettin an array of selected images in console.log(), but functiont this.model.set() doesnt work at all. Someone know an issue?