Allow 3rd-party plugins to use custom views and controllers #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MEXP's JS has hardcoded references to its own views and controllers. This makes things impossible for more than one plugin to override these internals.
For example, MEXP's built-in YouTube service manually overrides MEXP's own
media.view.MEXP
andmedia.view.Toolbar.MEXP
, so no other plugin can touch these without conflicts occurring:https://github.com/Automattic/media-explorer/blob/master/js/mexp.js#L85
https://github.com/Automattic/media-explorer/blob/master/services/youtube/js.js#L11
https://github.com/Automattic/media-explorer/blob/master/js/mexp.js#L36
https://github.com/Automattic/media-explorer/blob/master/services/youtube/js.js#L219
This commit allows each service to set their own views and controllers and refactors MEXP to allow these views and controllers to be initialized.
Specifically, adds a JS utility function -
stringToFunction()
- so we can instantiate custom views (could do better here).Plugins can override the default views and controllers by registering them on the
"mexp_js_{$service_id}"
hook. See how we're using this hook with our Google Drive MEXP plugin.I didn't change MEXP's YouTube JS to do this yet. If this commit looks good in your eyes, then I'll add a commit for YouTube.