Skip to content

Instantly share code, notes, and snippets.

@akopcz2
Created August 19, 2019 14:18
Show Gist options
  • Save akopcz2/c78f6e418edcbd21adc88eb562a1c04b to your computer and use it in GitHub Desktop.
Save akopcz2/c78f6e418edcbd21adc88eb562a1c04b to your computer and use it in GitHub Desktop.
Clone Child Shop
window.addEventListener('resize', function(){
let desktopThumbnailWrapper = document.querySelector('.thumbnails-wrapper');
let desktopThumbnailParent = desktopThumbnailWrapper.parentNode;
let shopifyProductReviews = document.querySelector('#shopify-product-reviews');
let shopifyReviewsProductParent = shopifyProductReviews.parentNode;
let shopifyProductReviewsClone = shopifyProductReviews.cloneNode(true);
let rightSide = document.querySelector('.grid__item.medium-up--one-half');
//Desktop
if(window.innerWidth > 767){
if(!rightSide.querySelector('#shopify-product-reviews')){
console.log('NO REVIEWS')
desktopThumbnailWrapper.insertAdjacentElement('afterend', shopifyProductReviewsClone);
// Remove IE poly
shopifyProductReviews.parentNode.removeChild(shopifyProductReviews);
//mobile
}
console.log(shopifyReviewsProductParent.querySelector('#shopify-product-reviews'));
} else {
if(desktopThumbnailParent.querySelector('#shopify-product-reviews')){
let productDesc = document.querySelector('.product-single__description');
productDesc.insertAdjacentElement('afterend', shopifyProductReviewsClone);
//remove node from desktop thumbnail view
desktopThumbnailParent.querySelector('#shopify-product-reviews').remove();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment