Opened 12 years ago
Closed 10 years ago
#23096 closed enhancement (fixed)
Provide callback before setting state of the editor media manager
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
In the current setup, there is no way to modify the current state or views when the media manager is opened from the "Add Media" button. By the time you can modify anything, all the default views have been rendered and all of the events have been fired.
It would be helpful to check for the existence of a callback, and if it exists, run that before returning the workflow.
My patch does this, which you could invoke in this way:
wp.media.editor.extend = function(workflow){ // Manipulate the workflow here }
Thoughts? This is only for the default media manager that is invoked by clicking the Add Media button.
Attachments (2)
Change History (12)
#6
@
11 years ago
What is your goal here?
You can extend/override the controller media.view.MediaFrame.Whatever
to do whatever you want.
I think you may be dreaming of #21170.
#7
@
10 years ago
- Keywords dev-feedback removed
- Milestone changed from Awaiting Review to 4.1
If you want to override the click handler, you should remove it and add your own - since the current click
handler is delegated, and isn't namespaced, this is messy. My patch 23096.2.diff namespaces the click handler: click.add_media_button
With it, you can just do:
$( document.body ) .off( 'click.add_media_button' ) .on( 'click.add_media_button', '.insert-media', function ( event ) { var elem = $( event.currentTarget ), editor = elem.data('editor'), options = { frame: '{WHATEVER_YOU_WANT}', state: '{WHATEVER_YOU_WANT}', title: '{WHATEVER_YOU_WANT}', }; event.preventDefault(); elem.blur(); wp.media.editor.open( editor, options ); } )
#8
@
10 years ago
We should probably use hyphens for these namespaces.
I'm mostly good with this except that we're solving a bit of an interesting line of code in the existing callback:
// Remove focus from the `.insert-media` button. // Prevents Opera from showing the outline of the button // above the modal. // // See: http://core.trac.wordpress.org/ticket/22445 elem.blur();
We probably shouldn't expect plugin authors to see this and copy this over. but also, might there be something else we'll want to always do in the future?
This is a good use case for firing a custom event inside the callback, seems like. Or could we suggest they attach an event and call stopImmediatePropagation? Probably not, as they'd want to set media-editor.js as a dependency and then it'd load first...
#9
@
10 years ago
I think there is an overall issue with separating library code and docReady init code. Our Backbone code should be a library of classes that can be overridden by extension/inheritance (already is), and the "init" portion should be what can easily be short-circuited.
For this particular instance, I will add the namespace (with dashes!) to the click registration, which will allow devs to turn off the default behavior. Messy, but solves the immediate problem.
The docReady code problem is across the codebase, and something I hope to address soon when an elegant solution arises.
Oops, wrong syntax for code block. This should look better: