-
-
Save andrejIka/522302c00c8fa4b250f9b10159717acc to your computer and use it in GitHub Desktop.
Revisions
-
dnaber-de created this gist
Oct 21, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,94 @@ 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 );