Last active
July 17, 2020 18:13
-
-
Save odessy/ade1bcbef1432053d04e572418d1c81d to your computer and use it in GitHub Desktop.
Story change product option: story theme modification of https://gist.github.com/drabbytux/a49215c6d0ba16c4d096a56212bbc4ce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
thumbnails = $('.product__thumbs img[src*="/products/"]'); | |
if (thumbnails.length) { | |
thumbnails.on('click', function() { | |
var arrImage = $(this).attr('src').split('?')[0].split('.'); | |
var strExtention = arrImage.pop(); | |
var strRemaining = arrImage.pop() | |
.replace(/_(pico|icon|thumb|small|compact|medium|large|grande|crop|center)/gi, '') | |
.replace(/_[a-zA-Z0-9@]+$/,''); | |
var strNewImage = arrImage.join('.')+"."+strRemaining+"."+strExtention; | |
if (typeof variantImages[strNewImage] !== 'undefined') { | |
productOptions.forEach(function (value, i) { | |
optionValue = variantImages[strNewImage]['option-'+i]; | |
if (optionValue !== null && optionValue !== 'undefined' && $('#SingleOptionSelector-'+i+' option').filter(function() { | |
var text = $(this).text(); | |
if(theme !== null && theme.strings !== 'undefined' ){ | |
text = text.replace(" - "+theme.strings.unavailable, "").replace(" - "+theme.strings.soldOut, "") | |
} | |
return text.trim() === optionValue }).length) { | |
$('#SingleOptionSelector-'+i).val(optionValue).trigger('change'); | |
} | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment