Skip to content

Instantly share code, notes, and snippets.

@msanigar
Last active August 29, 2015 14:25
Show Gist options
  • Save msanigar/2fb840583559c38328c7 to your computer and use it in GitHub Desktop.
Save msanigar/2fb840583559c38328c7 to your computer and use it in GitHub Desktop.
Allow users to buy from the category via lightbox instead of going through to product detail page
/*
* quickbuy js - enable users to fire lightbox from category and add to basket without entering product detail page
*/
jQuery(document).ready(function() {
function checkWidth() {
var windowSize = $(window).width();
if (windowSize >= 960) {
var $locDiv = jQuery('#prod_list_prods').length ? jQuery('#prod_list_prod') : jQuery('#main_cat_prods');
console.log($locDiv);
$locDiv.delegate('img', 'mouseenter', function(){
var $skuID = this.src.match(/[a-z][a-z][a-z]\d\d\d\d\d/)[0];
if ( !jQuery('#QuickBuyProdBox').length ) {
jQuery(this).closest('.image').prepend('<div id="QuickBuyProdBox">');
};
jQuery("#QuickBuyProdBox").click(function(){
jQuery.event.trigger('lightbox', $skuID);
});
jQuery('.image, #QuickBuyProdBox').mouseleave(function(){
jQuery('#QuickBuyProdBox').remove();
});
});
} else if (windowSize >= 720 && windowSize <= 959) {
$locDiv.delegate('img', 'touchstart', function(evt){
var $skuID = this.src.match(/[a-z][a-z][a-z]\d\d\d\d\d/)[0];
if ( !jQuery(this).closest('#comp-imageprince').find( '#QuickBuyProdBox' ).length ){
console.log(evt); evt.preventDefault()
jQuery('#QuickBuyProdBox').remove();
jQuery(this).closest('.image').prepend('<div id="QuickBuyProdBox">');
}
jQuery("#QuickBuyProdBox").click(function(){
jQuery.event.trigger('lightbox', $skuID);
});
});
}
}
});
//quick buy from cat banner
jQuery('#QuickBuyTXT a').click( function(){
jQuery.event.trigger('lightbox', '<venda_icxtqbsku>');
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment