Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Created May 16, 2016 20:41
Show Gist options
  • Save beardedtim/354e30b520830d7751401fb632c3cb8d to your computer and use it in GitHub Desktop.
Save beardedtim/354e30b520830d7751401fb632c3cb8d to your computer and use it in GitHub Desktop.
Abstraction for wp.media
var MediaGallery = {
mediaFrame : "",
setAttributes : function (title, button, type, multiple) {
this.mediaFrame = wp.media({
title: title,
button: {
text: button
},
library: {
type: type
},
multiple: multiple
});
},
open : function() {
this.mediaFrame.open();
},
on : function(event, func) {
this.mediaFrame.on(event, func);
},
selection : function() {
return this.mediaFrame.state().get( 'selection' );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment