On one of my custom posts edit page I have a button that triggers the media popup onclick, with: wp.media.editor.open();
and while it brings up the media manager I’m not sure if that’s the proper way to do it. Is it?
But real question is about something else. How do I attach event listeners to various events that media popup should trigger? Like open
or close
or is there any event for switched view?
You can use several event handlers.
Where
frame
is a reference towp.media()
Full example
Script en-queued with jQuery and media editor as dependencies.
Script contains:
Window triggered by a button with a classname of
media
Media javascript dependencies enqueued via function.
Last I checked the best documentation was the source code – see media-views.js, media-models.js here: http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/js/
Experimenting with the console can be helpful – It’s mostly backbone objects, you can watch events triggered using something like this script I made some time ago – http://userscripts.org/scripts/show/161075