TinyMCE gallery preview: fix errors when an image doesn't have/is smaller than thumbnail size, props gcorne, see #26959

git-svn-id: https://develop.svn.wordpress.org/trunk@27580 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2014-03-18 03:24:17 +00:00
parent 30a83e48e2
commit 8e403519db
2 changed files with 14 additions and 11 deletions

View File

@ -268,14 +268,25 @@ window.wp = window.wp || {};
getHtml: function() {
var attrs = this.shortcode.attrs.named,
options;
options,
attachments;
if ( ! this.attachments.length ) {
return;
}
attachments = this.attachments.toJSON();
_.each( attachments, function( attachment ) {
if ( attachment.sizes.thumbnail ) {
attachment.thumbnail = attachment.sizes.thumbnail;
} else {
attachment.thumbnail = attachment.sizes.full;
}
} );
options = {
attachments: this.attachments.toJSON(),
attachments: attachments,
columns: attrs.columns ? parseInt( attrs.columns, 10 ) : 3
};

View File

@ -897,12 +897,6 @@ function wp_print_media_templates() {
</div>
</div>
</script>
<?php
//TODO: do we want to deal with the fact that the elements used for gallery items are filterable and can be overriden via shortcode attributes
// do we want to deal with the difference between display and edit context at all? (e.g. wptexturize() being applied to the caption.
?>
<script type="text/html" id="tmpl-editor-gallery">
<div class="toolbar">
<div class="dashicons dashicons-edit edit"></div>
@ -912,14 +906,12 @@ function wp_print_media_templates() {
<# _.each( data.attachments, function( attachment, index ) { #>
<dl class="gallery-item">
<dt class="gallery-icon">
<?php // TODO: need to figure out the best way to make sure that we have thumbnails ?>
<img src="{{{ attachment.sizes.thumbnail.url }}}" />
<img src="{{{ attachment.thumbnail.url }}}" width="{{ attachment.thumbnail.width }}" height="{{ attachment.thumbnail.height }}" />
</dt>
<dd class="wp-caption-text gallery-caption">
{{ attachment.caption }}
</dd>
</dl>
<?php // this is kind silly, but copied from the gallery shortcode. Maybe it should be removed ?>
<# if ( index % data.columns === data.columns - 1 ) { #>
<br style="clear: both;">
<# } #>