-
-
Save syahrasi/6432457 to your computer and use it in GitHub Desktop.
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
function makeColorButtons(){ | |
var color_select = $('#product-select-option-0'), | |
color_list = $('#colors').html(""); | |
color_select.find('option').each(function(i,el){ | |
var element = $(el); | |
var color = element.val(), | |
color_attr = color.replace(/\s/g,"-"), | |
link = $(document.createElement('a')) | |
.attr('href',"#") | |
.attr('title', color), | |
swatch = $(document.createElement('li')) | |
.addClass('swatch color_hover') | |
.attr('id', color_attr) | |
.attr('title',color) | |
.attr('data-color', color) | |
.append(link) | |
.appendTo(color_list); | |
} | |
}); | |
color_select.val("").hide().siblings().hide(); | |
$('.swatch').on('click', function(e){ | |
var swatch = $(this), | |
color = swatch.data('color'), | |
color_id = swatch.attr('id'); | |
// make current swatch active | |
swatch.addClass('active').siblings().removeClass('active'); | |
// update printed color | |
$('#current_color').html(color); | |
$('.image img').each(function(){ | |
if ($(this).attr('alt') === color_id ){ $(this).parents('a').click(); return; } | |
}); | |
// update the underlying hidden selector | |
color_select.val(color).change(); | |
e.preventDefault(); | |
}); | |
$('.swatch').first().click(); | |
$('.color_hover').tooltip({ placement: 'bottom'}); | |
} | |
$(document).ready(function() { | |
// $('.swatch').first().click(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment