Skip to content

Instantly share code, notes, and snippets.

@seedcms
Last active January 4, 2018 17:16
Show Gist options
  • Save seedcms/1ee6ec0e6a72508507ed6c1233980587 to your computer and use it in GitHub Desktop.
Save seedcms/1ee6ec0e6a72508507ed6c1233980587 to your computer and use it in GitHub Desktop.
product-swatches.js
jQuery(document).ready(function(){
function go_swatch(product_id){
var appDomain = 'https://productswatches-herokuapp-com.global.ssl.fastly.net';
var url = appDomain + '/product_swatches/get-json/'+product_id;
if(product_tag){
var data = {
return_format: 'html',
product_id:product_id,
tooltip: 'yes',
tooltip_split: '-',
tooltip_bg: '555',
tooltip_color: 'fff',
tooltip_font_size: '12px',
tooltip_font: 'sans-serif',
tooltip_padding: '5px',
tooltip_border_radius: '6px',
tooltip_css: '',
border_radius: '0%',
border_color: 'ffffff',
border_active: 'cccccc',
border_width: '1',
width: '50',
height: '50',
swatch_title: '',
hide_sold_out: '',
tag: product_tag
};
}else{
var data = {
return_format: 'html',
product_id:product_id,
tooltip: 'yes',
tooltip_split: '-',
tooltip_bg: '555',
tooltip_color: 'fff',
tooltip_font_size: '12px',
tooltip_font: 'sans-serif',
tooltip_padding: '5px',
tooltip_border_radius: '6px',
tooltip_css: '',
border_radius: '0%',
border_color: 'ffffff',
border_active: 'cccccc',
border_width: '1',
width: '50',
height: '50',
swatch_title: '',
hide_sold_out: ''
};
}
$.ajax({
type: 'post',
url: url,
data: data,
cache: false,
dataType: "html",
success: function(data) {
//console.log(product_idx);
//console.log(".product-swatches-"+product_id);
$(".product-swatches-"+product_id).html(data);
}
});
}
$(".product-swatches").each(function() {
product_id = $(this).data('id');
product_idx = $(this).data('id');
product_tag = $(this).data('tag');
//console.log(product_id);
go_swatch(product_id)
}); // end .each
}); // end on document ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment