Skip to content

Instantly share code, notes, and snippets.

@damned
Created April 4, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damned/db1a4b939a13a87004bb37cb955b326d to your computer and use it in GitHub Desktop.
Save damned/db1a4b939a13a87004bb37cb955b326d to your computer and use it in GitHub Desktop.
estore funded page v2
function cleanUpNavigation() {
$("a[href='/']").each(function() { $(this).attr('href', 'javascript:void(0)'); });
$(".container[itemprop='breadcrumb']").remove();
}
function cleanUpFooter() {
$('.footer-container:first').remove();
}
function cleanUpPage() {
cleanUpNavigation();
cleanUpFooter();
}
var allowedProductChildrenClasses = /thumbnail|product-title/;
function removeUnwantedFields() {
$('#products-holder article').each(function() {
$(this).children().each(function() {
var $child = $(this);
if (!allowedProductChildrenClasses.test($child.attr('class'))) {
$child.remove();
}
});
})
}
function Product($product) {
var $specificationRows = $product.find('#specification table tr');
var $mainImage = $product.find("[itemprop='image']");
function spec(name) {
return $specificationRows.find("th:contains('" + name + "')").next().text();
}
return {
depth: spec('Depth'),
height: spec('Height'),
width: spec('Width'),
mainImageUrl: $mainImage.attr('src')
};
}
function addProductInfo($product, productInfo) {
$product.find('img').attr('src', productInfo.mainImageUrl);
$product.append('<p>Dimensions: ' + productInfo.width + 'x' + productInfo.height + 'x' + productInfo.depth + '</p>');
}
function pullProductInfo() {
$('#products-holder article').each(function() {
var $product = $(this);
var $productImageLink = $product.find('a:has(img)');
var productDetailUrl = $productImageLink.attr('href');
var $productDetailContent = $('<div/>');
$productDetailContent.load(productDetailUrl + " .productTemplate", function() {
addProductInfo($product, Product($productDetail));
});
})
}
function cleanUpProducts() {
removeUnwantedFields();
pullProductInfo();
}
function loadProducts() {
var $productsHolder = $('#products-holder');
$productsHolder.load($productsHolder.data('load-spec'), cleanUpProducts);
}
$(function() { // run once loaded
cleanUpPage();
loadProducts();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment