Skip to content

Commit

Permalink
Fix for issue Shopify#525
Browse files Browse the repository at this point in the history
  • Loading branch information
js42721 committed May 7, 2016
1 parent 91bb393 commit 8985ad8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions assets/timber.js.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ timber.productPage = function (options) {

// Selectors
var $productImage = $('#ProductPhotoImg'),
$thumbImages = $('#ProductThumbs').find('a.product-single__thumbnail');
$addToCart = $('#AddToCart'),
$productPrice = $('#ProductPrice'),
$comparePrice = $('#ComparePrice'),
Expand All @@ -218,7 +219,15 @@ timber.productPage = function (options) {
// Update variant image, if one is set
if (variant.featured_image) {
var newImg = variant.featured_image,
el = $productImage[0];
el = $productImage[0],
pattern = /[?&]v=([^&#]*)/,
v = pattern.exec(newImg.src)[1];
$thumbImages.each(function() {
if (pattern.exec($(this).attr('href'))[1] === v) {
newImg.alt = $(this).find('img').attr('alt');
return false;
}
});
Shopify.Image.switchImage(newImg, el, timber.switchImage);
}

Expand Down Expand Up @@ -265,7 +274,8 @@ timber.productImageSwitch = function () {
timber.cache.$thumbImages.on('click', function(evt) {
evt.preventDefault();
var newImage = $(this).attr('href');
timber.switchImage(newImage, null, timber.cache.$productImage);
var newImageAlt = $(this).find('img').attr('alt');
timber.switchImage(newImage, { alt: newImageAlt }, timber.cache.$productImage);
});
}
};
Expand All @@ -274,6 +284,7 @@ timber.switchImage = function (src, imgObject, el) {
// Make sure element is a jquery object
var $el = $(el);
$el.attr('src', src);
$el.attr('alt', imgObject.alt);
};

timber.responsiveVideos = function () {
Expand Down

0 comments on commit 8985ad8

Please sign in to comment.