Gallery Views: Avoid JS errors when image attachments lack metadata.

props gcorne.
fixes #27691.


git-svn-id: https://develop.svn.wordpress.org/trunk@28008 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
nacin 2014-04-07 21:24:02 +00:00
parent c765ed8832
commit 5404d9933f
2 changed files with 11 additions and 5 deletions

View File

@ -289,10 +289,12 @@ window.wp = window.wp || {};
attachments = this.attachments.toJSON();
_.each( attachments, function( attachment ) {
if ( attachment.sizes.thumbnail ) {
attachment.thumbnail = attachment.sizes.thumbnail;
} else {
attachment.thumbnail = attachment.sizes.full;
if ( attachment.sizes ) {
if ( attachment.sizes.thumbnail ) {
attachment.thumbnail = attachment.sizes.thumbnail;
} else if ( attachment.sizes.full ) {
attachment.thumbnail = attachment.sizes.full;
}
}
} );
}

View File

@ -975,7 +975,11 @@ function wp_print_media_templates() {
<# _.each( data.attachments, function( attachment, index ) { #>
<dl class="gallery-item">
<dt class="gallery-icon">
<img src="{{{ attachment.thumbnail.url }}}" width="{{ attachment.thumbnail.width }}" height="{{ attachment.thumbnail.height }}" />
<# if ( attachment.thumbnail ) { #>
<img src="{{ attachment.thumbnail.url }}" width="{{ attachment.thumbnail.width }}" height="{{ attachment.thumbnail.height }}" />
<# } else { #>
<img src="{{ attachment.url }}" />
<# } #>
</dt>
<dd class="wp-caption-text gallery-caption">
{{ attachment.caption }}