Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 3rd-party plugins to use custom views and controllers #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

r-a-y
Copy link

@r-a-y r-a-y commented Aug 22, 2016

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 and media.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.

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 and media.view.Toolbar.MEXP, so no other plugin
can touch these without conflicts occurring.

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 on the "mexp_js_{$service_id}" hook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant