Please select a color option or click a color picture to choose an option.
');
//console.log('varIMAGES:'+variationIMAGES_FLAG);//either 1 or null
function flexThumbClick() {
var index = $(this).index();
/*
* the following doesn't work too well - chooses wrong variants - off by 1 in some cases
index++;
var selected = $('select#attribute option:nth-child('+index+'),select#color-and-number option:nth-child('+index+')');
*/
var product_image_variant = $('.flex-viewport figure > div').get(index);
var variant_via_image = '';
if (product_image_variant) {
variant_via_image = $(product_image_variant).attr('data-color-number');
}
if (variant_via_image !== '') {
var selected = $('select#attribute option[value="'+variant_via_image+'"],select#color-and-number option[value="'+variant_via_image+'"],select#color option[value="'+variant_via_image+'"]');
}
if (typeof selected === 'undefined' || !selected) {
return;
}
// console.log('flex thumb click debug', product_image_variant, variant_via_image);
if (selected.length) {
$('select#attribute option,select#color-and-number option,select#color option').attr('selected', false);
selected.attr('selected', true);
$('form.variations_form').trigger('check_variations');
// var option_val = selected.val();
// $('select#option').val( option_val );
// $('form.variations_form').trigger('woocommerce_variation_select_change').trigger( 'check_variations', [ '', false ] );
// $('a.reset_variations').css('display','block').css('visibility','visible');
// $('.woocommerce-variation.single_variation').css('display','block');
}
if (!$defaultVariationMsg.is('hidden')) {
$defaultVariationMsg.hide(300);
}
}
function initFlexHelpers() {
$('select#attribute, select#color-and-number, select#color').on("change", function(e){
var idCONVERSION = this.value.replace('%', 'Percent');
idCONVERSION = idCONVERSION.replace('(', '_');
idCONVERSION = idCONVERSION.replace(/[^\w\s]/gi, '');
idCONVERSION = idCONVERSION.replace(/\s/g, '');
// alert(idCONVERSION);
// console.log(idCONVERSION);
// $('#'+idCONVERSION).addClass('feature');
// try to grab thumbnail by ID
var thumbnailCOUNT = $('#'+idCONVERSION).index();
if(thumbnailCOUNT!=-1){ thumbnailCOUNT++;
themeFlexSelectChange(thumbnailCOUNT);
}
else {
// try to grab thumbnail by data-color-number
var thumbnailCOUNT = $('div[data-color-number="' + this.value + '"]').index();
if(thumbnailCOUNT!=-1){ thumbnailCOUNT++;
themeFlexSelectChange(thumbnailCOUNT);
}
}
if (!$defaultVariationMsg.is('hidden')) {
$defaultVariationMsg.hide(300);
}
});
// this might fire too early before flexslider does
$('ol.flex-control-thumbs').find('li').each(function(i){
$(this).addClass('thumb');
$(this).addClass(i.toString());
});
$('.flex-control-nav > li').on('click touchstart',flexThumbClick);
setTimeout(defaultVariationMakeSelectionMessage, 1200);
}
// default variation make selection message
function defaultVariationMakeSelectionMessage() {
// console.log('i hate cache');
var $frm = $('.variations_form.cart');
if ($frm.length) {
$frm.after($defaultVariationMsg);
}
// setTimeout(function() { $defaultVariationMsg.show(300) }, 500);
}
// $(window).load(initFlexHelpers);
// need interval to check for .flex-control-nav > li since woocommerce might fire after this script loads
if(window.variationIMAGES_FLAG){
var flexLoadedInterval = setInterval(checkFlexslider, 300);
function checkFlexslider() {
if ($('.flex-control-nav > li').length) {
// console.log('found flex slider');
clearInterval(flexLoadedInterval);
initFlexHelpers();
$('#theme-product-image-container').addClass('flex-loaded');
}
else {
// console.log('recheck for flexslider in 300');
}
}
} // if variationIMAGES_FLAG
});