Opened 9 years ago
Last modified 6 years ago
#36842 new feature request
More global event hooks using the media.events, like "modal:open", "modal:close", etc
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.6 |
Component: | Media | Keywords: | |
Focuses: | javascript, administration | Cc: |
Description
There seem to be plentiful hooks in the media backbone system, but most require listening to the frame/controller/etc vs having global hooks/events to listen to. This, obviously, would be much like WP's do_action
. Each event should pass contextual info including the frame/controller/etc object.
Select2 (as well as most JS modal libs) provides an example of prior art: https://select2.github.io/examples.html#events
Using that implementation as an example, we could do something like:
wp:media:open
is fired whenever the modal is opened. wp:media:opening
is fired before this and can be prevented.
wp:media:close
is fired whenever the modal is closed. wp:media:closing
is fired before this and can be prevented.
wp:media:highlight
is fired whenever a result is highlighted (clicked).
wp:media:unhighlight
is fired whenever a result is unhighlighted.
wp:media:select
is fired when a result is chosen and modal is closed. wp:media:selecting
is fired before this and can be prevented.
wp:media:change
is fired whenever the modal changes state. wp:media:changing
is fired before this and can be prevented.
https://core.trac.wordpress.org/ticket/27698 Is similar, and introduced
wp.media.events
which, I assume, is what we would use to create this API.