Skip to content

Commit

Permalink
Improve image html and fix empty wrap issue
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianengine committed Feb 28, 2016
1 parent 2d85493 commit 6dd5501
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions spectragram.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,52 @@ if ( typeof Object.create !== "function" ) {
display: function ( results ) {
var $element,
$image,
isWrapperEmpty,
imageGroup = [],
imageCaption,
imageHeight,
imageWidth,
max,
setSize,
size;

isWrapperEmpty = $( this.options.wrapEachWith ).length === 0;

if ( results.data === undefined || results.meta.code !== 200 || results.data.length === 0 ) {
this.$elem.append( $( this.options.wrapEachWith ).append( this.messages.notFound ) );
if ( isWrapperEmpty ) {
this.$elem.append( this.messages.notFound );
} else {
this.$elem.append( $( this.options.wrapEachWith ).append( this.messages.notFound ) );
}
} else {
max = ( this.options.max >= results.data.length ) ? results.data.length : this.options.max;
setSize = this.options.size;

for ( var i = 0; i < max; i++ ) {
if ( setSize === "small" ) {
size = results.data[i].images.thumbnail.url;
imageHeight = results.data[i].images.thumbnail.height;
imageWidth = results.data[i].images.thumbnail.width;
} else if ( setSize === "medium" ) {
size = results.data[i].images.low_resolution.url;
imageHeight = results.data[i].images.low_resolution.height;
imageWidth = results.data[i].images.low_resolution.width;
} else {
size = results.data[i].images.standard_resolution.url;
imageHeight = results.data[i].images.standard_resolution.height;
imageWidth = results.data[i].images.standard_resolution.width;
}

imageCaption = ( results.data[i].caption !== null ) ?
$( "<span>" ).text( results.data[i].caption.text ).html() :
this.messages.defaultImageAltText;

$image = $( "<img>", {
alt: imageCaption,
attr: {
height: imageHeight,
width: imageWidth
},
src: size
} );

Expand All @@ -149,7 +169,11 @@ if ( typeof Object.create !== "function" ) {
title: imageCaption
} ).append( $image );

imageGroup.push( $( this.options.wrapEachWith ).append( $element ) );
if ( isWrapperEmpty ) {
imageGroup.push( $element );
} else {
imageGroup.push( $( this.options.wrapEachWith ).append( $element ) );
}
}

this.$elem.append( imageGroup );
Expand Down
2 changes: 1 addition & 1 deletion spectragram.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6dd5501

Please sign in to comment.