media-explorer icon indicating copy to clipboard operation
media-explorer copied to clipboard

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

Open r-a-y opened this issue 8 years ago • 0 comments

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.

r-a-y avatar Aug 22 '16 16:08 r-a-y