Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

[WIP] Widget JS Refactor #17

Merged
merged 14 commits into from
Mar 14, 2017
Merged

[WIP] Widget JS Refactor #17

merged 14 commits into from
Mar 14, 2017

Conversation

westonruter
Copy link
Contributor

Work in progress

This PR will introduce a lot of churn but it will give a much more extensible foundation for us to extend new media widget.

Fixes #8
Fixes #7
Fixes #16

@westonruter
Copy link
Contributor Author

@obenland FYI: Here's the progress I've made so far on refactoring the JS to be extensible, with a base Backbone.View that each media type can extend. Lots more work to do, but I think this will provide us with a better foundation for this JS-driven control.

@obenland obenland mentioned this pull request Mar 13, 2017
@obenland
Copy link
Contributor

This is quite a PR. Are you still working on it? Do you think this could be split up in smaller PRs?


$( document ).on( 'widget-added', function( event, widgetContainer ) {
console.info( widgetContainer )
var widgetContent, controlContainer, widgetForm, widgetId, idBase, ControlConstructor, ModelConstructor, modelAttributes, control, model;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the order of variables organized or random?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole function is a mess and needs further cleanup.

@westonruter
Copy link
Contributor Author

This is quite a PR. Are you still working on it? Do you think this could be split up in smaller PRs?

Unfortunately, not. It can't be split up because it's a rewrite of the JS.

I am still working on it, and hope to have the changes I want to make in place be EOD today. But we should probably merge it once the image widget is completed, and then open new PRs for the audio and video widgets, do you think?

@obenland
Copy link
Contributor

obenland commented Mar 14, 2017

Is there any way I can contribute or help? Everything else seems blocked until this gets in

@westonruter westonruter merged commit 1cbff58 into master Mar 14, 2017
var control = this, previewContainer, previewTemplate;
previewContainer = control.$el.find( '.media-widget-preview .rendered' );
previewTemplate = wp.template( 'wp-media-widget-image-preview' );
previewContainer.html( previewTemplate( { attachment: control.selectedAttachment.attributes } ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason control.selectedAttachment.attributes is not passed straight to the template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@obenland Good point. Maybe not, although maybe this is anticipating the ability to pass in a url separately in the case of providing an external image by URL instead of from the media library.

wp_json_encode( $this->widget_options['mime_type'] ),
wp_json_encode( $this->l10n )
)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What made you decide to use inline scripts rather than wp_localize_script() and assigning its values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@obenland yes, by using wp_add_inline_script() it means we can avoid having to create a new global variable and can instead amend an existing object directly. Also, wp_localize_script() will cast scalar array values to strings which may not always be desired.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding a global variable doesn't come free. It makes media-image-widget.js that much harder to grok for contributors who are unfamiliar with the code

This was referenced Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants