myGlobalFrame = null; /** * @param wp wp namespace * @param Backbone * @param $ jQuery */ ;( function( wp, Backbone, $ ) { 'use strict'; var myLibrary = wp.media.controller.FeaturedImage.extend( { defaults: _.defaults( { data : false, multiple : false, filterable : 'all', selectedImageId : 0, library : wp.media.query( { type : 'image', uploadedTo: wp.media.view.settings.post.id, } ) }, wp.media.controller.Library.prototype.defaults ), /** * update the 'selected' attachment in the GUI */ updateSelection : function() { var selection = this.get( 'selection' ), attachment; if ( 1 > this.attributes.selectedImageId ) { return; } attachment = wp.media.model.Attachment.get( this.attributes.selectedImageId ); attachment.fetch(); selection.reset( attachment ? [ attachment ] : [] ); } } ); var library = new myLibrary( { title : 'Medienverwaltung', //selectedImageId : 9 } ); var frame = myGlobalFrame = new wp.media.view.MediaFrame.Select( { title : 'Mediathek', button : { text : 'Bild Auswählen' }, state : 'library', states : [ //library new wp.media.controller.Library({ //data : false, //multiple : false, filterable : 'all', //selectedImageId : 0, library : wp.media.query( { //type : 'image', uploadedTo: wp.media.view.settings.post.id, orderBy : 'menuOrder', order : 'ASC' } ) }) ] } ); frame.on( 'select', function() { var attachment = frame.state().get( 'selection' ).first(); library.attributes.selectedImageId = attachment.id; } ); $( document ).ready( function() { frame.open(); } ); } )( window.wp = window.wp || {}, window.Backbone = window.Backbone || {}, jQuery );