Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Last active December 20, 2015 11:49
Show Gist options
  • Select an option

  • Save msmithstubbs/6126244 to your computer and use it in GitHub Desktop.

Select an option

Save msmithstubbs/6126244 to your computer and use it in GitHub Desktop.
jQuery(function() {
// This first bit is just handling the user selecting a variant.
$('.product-information').on('click', '.variant_title', function(e) {
e.preventDefault();
$(this).addClass('selected').siblings().removeClass("selected");
$(this).closest('.product-information').find('#bis_button').toggle($(this).is('.unavailable'));
});
// Then, when the button is clicked...
$('#bis_button').on('click', function(e) {
e.preventDefault();
var email = prompt('Please enter your email address');
// ...find out which variant is currently selected, and fetch that product and variant ids off the element.
var selectedVariant = $(this).closest('.product-information').find('a.variant_title.selected');
var productId = selectedVariant.data("product-id"),
variantId = selectedVariant.data("variant-id");
console.log(email, productId, variantId);
// Finally, call BISPopover.create() and handle the response.
BISPopover.create(email, variantId, productId).then(function(data) {
if (data.status == "OK") {
alert(data.message);
} else {
var msg = [];
for(var i in data.errors) { // could be more than one error message
msg.push(data.errors[i]);
}
alert(msg);
}
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment