I’m working on a plugin that extends the media manager, load JSON based input data to render an own collection of images and may upload them to my wordpress media library.
So far I got my own tab, can put my own content to the frame but the only way I figured out to put my JSON data to the content was with “basic” jQuery stuff.
Primary I’m looking for the possibility to make my own attachement-collection and mostly handle it with the given function to make it look like in the “gallery”-tab for example. To have the images clickable and the selected ones uploadable to my library.
Here is a snippet of my extended content view so far:
wp.media.view.CustomView = wp.media.View.extend({
className: 'media-fap',
initialize: function() {
this.input = "asdf";
var el = this.$el;
jQuery.getJSON( "http://192.168.11.47/fap/wp-json/image", function( data ) {
console.log("get json");
var output="<ul>";
for(i in data) {
var item = data[i];
output += '<li><img src="' + item.thumbnail + '"></li>';
}
output += '</ul>';
el.append(output);
});
// insert it in the view
//this.$el.append("this.input");
console.log("custom content");
// re-render the view when the model changes
this.model.on( 'change:custom_data', this.render, this );
},
render: function(){
this.input.value = this.model.get('custom_data');
return this;
},
custom_update: function( event ) {
this.model.set( 'custom_data', event.target.value );
}
});