Skip to content
This repository has been archived by the owner. It is now read-only.

Enable embedding images by URL #46

Merged
merged 45 commits into from Apr 5, 2017
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5e9f3db
Merge branch 'master' of github.com:xwp/wp-core-media-widgets
adamsilverstein Mar 24, 2017
806708d
Extend wp.media.view.MediaFrame.Post for our simplified media upload …
adamsilverstein Mar 24, 2017
32a13c7
Use our custom post frame for modal, restore when closing
adamsilverstein Mar 24, 2017
2c8c1f0
Use the post frame modal, start in the library state
adamsilverstein Mar 24, 2017
04da420
Clean up modal construction
adamsilverstein Mar 24, 2017
582645a
Enable insert from url
adamsilverstein Mar 25, 2017
9ef2a48
handle embed selection
adamsilverstein Mar 25, 2017
05e3086
Display the attached image by url in template
adamsilverstein Mar 26, 2017
fcf5df1
add a class to the remote loaded image for a possible load state
adamsilverstein Mar 26, 2017
c47c013
Handle embedded image on load
adamsilverstein Mar 26, 2017
2c6b1ea
Fix integration tests
obenland Mar 28, 2017
4b7d410
Merge branch 'issue-9' of github.com:xwp/wp-core-media-widgets into i…
adamsilverstein Mar 31, 2017
17d17bd
render url based images
adamsilverstein Apr 1, 2017
047e7e6
handle caption focus when model missing, fixing error an undefined er…
adamsilverstein Apr 1, 2017
179dc8a
Use caption, alt for URL based images
adamsilverstein Apr 2, 2017
2d66f5c
Support for caption, wifht, height, alt, align, link, linkUrl when in…
adamsilverstein Apr 2, 2017
5ee0f56
Embedded images: enable front end support for width, height, alignment
adamsilverstein Apr 2, 2017
d55b953
Fixes for jshint
adamsilverstein Apr 2, 2017
a75c35c
fixes for phpcs
adamsilverstein Apr 2, 2017
7cba9ca
ok phpcs, if you say so
adamsilverstein Apr 2, 2017
d4f0e25
Rely on instance defaults and escape output
obenland Apr 3, 2017
22e33c5
Revert "Rely on instance defaults and escape output"
obenland Apr 3, 2017
ad93285
Use getSelectFrameProps() for embedded images
obenland Apr 3, 2017
1d8d3ca
Make embedded images floatable
obenland Apr 3, 2017
6db30d9
Don't use private global variable
obenland Apr 3, 2017
bb30193
Update variable to reflect it's a class
obenland Apr 3, 2017
ed0194f
Add PHP unit tests
obenland Apr 3, 2017
31bd79e
Merge branch 'issue-9' of github.com:xwp/wp-core-media-widgets into i…
adamsilverstein Apr 4, 2017
02bd3e1
Remove modal focusing code
adamsilverstein Apr 4, 2017
d608e9f
Correct update triggering when first embedding remote url - ensure wi…
adamsilverstein Apr 4, 2017
d1f9439
Correct `_getEmbedProps` function naming
adamsilverstein Apr 4, 2017
6db576e
Embed attachment id is always 0
adamsilverstein Apr 4, 2017
a3b5a69
Correct link construction
adamsilverstein Apr 4, 2017
f36d84f
whitespace cleanup
adamsilverstein Apr 4, 2017
4e22228
remove unusued `mediaFrameContentView`
adamsilverstein Apr 4, 2017
50f8f67
Ensure attachment is present before attempting to get_attachment_link…
westonruter Apr 4, 2017
d284087
Use insert event instead of close event for updating model
westonruter Apr 4, 2017
ce93c37
Eliminate need to temporarily override media props
westonruter Apr 4, 2017
8c3ae25
Fix updating of preview when changing embedded image
westonruter Apr 4, 2017
d4fe47d
Add todo comments and give names to functions
westonruter Apr 5, 2017
0b84597
Eliminate deferring setting selectedAttachment in favor of calling re…
westonruter Apr 5, 2017
3059d84
Restore display settings
westonruter Apr 5, 2017
1ca00e5
Restore initial selection when changing media
westonruter Apr 5, 2017
7dd19e8
Merge branch 'issue-9' of github.com:xwp/wp-core-media-widgets into i…
adamsilverstein Apr 5, 2017
36fc725
Simplify the widget image preview - only use image url
adamsilverstein Apr 5, 2017
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -372,6 +372,22 @@ function test_render_media() {
$this->assertContains( 'width="100"', $output );
$this->assertContains( 'height="100"', $output );
// Embeded images.
ob_start();
$widget->render_media( array(
'attachment_id' => null,
'align' => 'none',
'caption' => 'With caption',
'height' => 100,
'link_type' => 'file',
'url' => 'http://example.org/url/to/image.jpg',
'width' => 100,
) );
$output = ob_get_clean();
// Custom image class.
$this->assertContains( 'src="http://example.org/url/to/image.jpg"', $output );
// Link settings.
ob_start();
$widget->render_media( array(
@@ -43,32 +43,83 @@
* @returns {object} Props
*/
getSelectFrameProps: function getSelectFrameProps( mediaFrame ) {
var attachment, displaySettings, props;

attachment = mediaFrame.state().get( 'selection' ).first().toJSON();
if ( _.isEmpty( attachment ) ) {
return {};
var control = this,
state = mediaFrame.state(),
props = {};

if ( 'embed' === state.get( 'id' ) ) {
props = control._getEmbedProps( mediaFrame, state.props.toJSON() );
} else {
props = control._getAttachmentProps( mediaFrame, state.get( 'selection' ).first().toJSON() );
}

return props;
},

/**
* Get the instance props from the media selection frame.
*
* @param {wp.media.view.MediaFrame.Select} mediaFrame Select frame.
* @param {object} attachment Attachment object.
* @returns {object} Props
*/
_getAttachmentProps: function _getAttachmentProps( mediaFrame, attachment ) {
var props = {}, displaySettings;

displaySettings = mediaFrame.content.get( '.attachments-browser' ).sidebar.get( 'display' ).model.toJSON();

props = {
attachment_id: attachment.id,
align: displaySettings.align,
alt: attachment.alt,
caption: attachment.caption,
image_classes: '',
image_title: '',
link_classes: '',
link_rel: '',
link_url: displaySettings.linkUrl,
link_target_blank: false,
link_type: displaySettings.link,
size: displaySettings.size,
url: attachment.sizes[ displaySettings.size ].url,
width: 0, // Reset.
height: 0 // Reset.
};
if ( ! _.isEmpty( attachment ) ) {
_.extend( props, {
attachment_id: attachment.id,
align: displaySettings.align,
alt: attachment.alt,
caption: attachment.caption,
image_classes: '',
image_title: '',
link_classes: '',
link_rel: '',
link_url: displaySettings.linkUrl,
link_target_blank: false,
link_type: displaySettings.link,
size: displaySettings.size,
url: attachment.sizes[ displaySettings.size ].url,
width: 0, // Reset.
height: 0 // Reset.
} );
}

return props;
},

/**
* Get the instance props from the media selection frame.
*
* @param {wp.media.view.MediaFrame.Select} mediaFrame Select frame.
* @param {object} attachment Attachment object.
* @returns {object} Props
*/
_getEmbedProps: function _getEmbedProps( mediaFrame, attachment ) {
var props = {};

if ( ! _.isEmpty( attachment ) ) {
_.extend( props, {
attachment_id: 0,
align: attachment.align,
alt: attachment.alt,
caption: attachment.caption,
image_classes: '',
image_title: '',
link_classes: '',
link_rel: '',
link_url: attachment.linkUrl,
link_target_blank: false,
link_type: attachment.link,
size: 'full',
url: attachment.url,
width: attachment.width,
height: attachment.height
} );
}

return props;
},
@@ -79,7 +130,7 @@
* @returns {void}
*/
editMedia: function editMedia() {
var control = this, mediaFrame, metadata, updateCallback, mediaFrameContentView;
var control = this, mediaFrame, metadata, updateCallback;

metadata = {
attachment_id: control.model.get( 'attachment_id' ),
@@ -141,17 +192,6 @@

mediaFrame.open();

/*
* Make sure focus is set inside of modal so that hitting Esc will close
* the modal and not inadvertently cause the widget to collapse in the
* customizer.
*/
mediaFrameContentView = mediaFrame.views.get( '.media-frame-content' )[0];
mediaFrameContentView.model.dfd.done( function() {
_.defer( function() { // Next tick.
mediaFrameContentView.$el.find( '[data-setting="caption"]:first' ).focus();
} );
} );
}
} );

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.