Skip to content

Instantly share code, notes, and snippets.

@Webbist-dev
Created September 8, 2014 15:54
Show Gist options
  • Save Webbist-dev/36ed4b7f35401367f331 to your computer and use it in GitHub Desktop.
Save Webbist-dev/36ed4b7f35401367f331 to your computer and use it in GitHub Desktop.
// Add functionality for Ingredients "Card Flip"
//
$('.product-img-box-pdp').wrapInner('<div class="product-img-box-pdp-inner-wrap" style="display: none;" />');
$(".ingredients-text").wrapInner('<div class="ingredients-text-inner-wrap"" />');
$('.product-img-box-pdp').prepend('<div class="product-img-box-pdp-inner" style="width: 100%;" />');
$('.product-img-box-pdp-inner').css('min-height', productImgHeight);
$('.product-img-box-pdp figure').clone().appendTo('.product-img-box-pdp-inner').show();
$('.ingredients-button-close').click(function() {
$(".ingredients-link").removeClass('ingredient-active');
$(".product-img-box-pdp-inner").flippy({
content: $('.product-img-box-pdp-inner-wrap > figure'),
duration: 600,
direction: 'RIGHT'
});
return false;
});
// Desktop flippy
var bp_desktop = '1024px';
$(".ingredients-link").click(function() {
$(".ingredients-link").removeClass('ingredient-active');
var ingredientCode = $(this).data("ingredient");
$(this).addClass('ingredient-active');
$(".ingredients-text").each(function() {
if($(this).data("ingredient") == ingredientCode) {
// Only apply flippy.js at desktop
if (Modernizr.mq('only all and (min-width: ' + bp_desktop + ')')) {
$(".product-img-box-pdp-inner").flippy({
content: $(this),
duration: 600,
direction: 'LEFT',
onFinish:function(){
$('.ingredients-button-close').click(function() {
$(".ingredients-link").removeClass('ingredient-active');
$(".product-img-box-pdp-inner").flippy({
content: $('.product-img-box-pdp-inner-wrap > figure'),
duration: 600,
direction: 'RIGHT'
});
return false;
});
}
});
} else {
// Hide elements on click
$('.product-img-box-pdp-inner-wrap')insertAfter('header');
$('.product-img-box-pdp-inner-wrap').show('.ingredient-active');
$('.main-container').hide();
$('header .spacer-bottom-small').hide();
$('.footer-container').hide();
}
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment