Skip to content

Instantly share code, notes, and snippets.

@tomwolber
Created August 3, 2015 01:59
Show Gist options
  • Save tomwolber/d629902a66e678cf49a7 to your computer and use it in GitHub Desktop.
Save tomwolber/d629902a66e678cf49a7 to your computer and use it in GitHub Desktop.
var fs = require('fs');
module.exports = {
body : [ 'body.cart' ],
cache: {
eabled: false
},
transform : function(req, response, body, $) {
var partials = req.app.hbsPartials;
var global_data = req.app.bb && req.app.bb.data && req.app.bb.data.partials.length ? req.app.data.partials : {};
var head = $('head');
var header = req.app.hbs.handlebars.compile('' + fs.readFileSync('views/partials/header.hbs'))(global_data);
var footer = req.app.hbs.handlebars.compile('' + fs.readFileSync('views/partials/footer.hbs'))(global_data);
var slide_menu = req.app.hbs.handlebars.compile('' + fs.readFileSync('views/partials/slide_menu.hbs'))(global_data);
var body_container = $('<section id="bbPageContent"></section>');
var bottom_checkout;
head.append(css('mobile')).append(js('site'));
head.append(js('cart'));
// WRAP THE BODY SO NAV WORKS
body_container.html($('body').html());
$('body').html(body_container);
// ELEMENTS FROM GLOBAL PARSER
$('body').prepend(slide_menu);
$('#header').replaceWith(header);
$('footer').replaceWith(footer);
// REMOVES
$('#back-to-top, .small-cart-item-qty .sku-title, #quantity-input quantity-input, .cart-order-totals .keep-shopping').remove();
// KEEP SHOPPING, PAYPAL, CHECKOUT (UPPER)
$('.items-title').before('<a href="/" class="keepshopping">&#9664; KEEP SHOPPING</a>');
$('.items-title').after('<div class="uppercheck"><span class="paypal"></span><a href="#" class="checkout">CHECKOUT <em>&#9002</em></a></div>');
$('.uppercheck span').prepend($('#paypal-button').first());
// KEEP SHOPPING, PAYPAL, CHECKOUT (LOWER)
bottom_checkout = $('.uppercheck').clone();
$('#checkout').after(bottom_checkout);
// MOVE DOM TO MAKE PRODUCTS MATCH MOCKUP LAYOUTS
$('#cart-items .cart-item .row').not('.small-cart-item-info').each(function() {
var primary = $('<div class="primary"></div>');
var pricing = $('<div class="pricing"></div>');
var title = $(this).find('.product-title');
var image = $(this).find('.product-image');
var details = $(this).find('.product-details');
var qty = $(this).find('.small-cart-item-qty');
var price = $(this).find('.small-cart-item-price').remove();
$(this).addClass('product');
details.append(qty);
primary.prepend(title, image, details);
pricing.html(price.html() || '');
$(this).prepend(primary, pricing);
});
// USE QUANTITY STEPPER
$('#quantity-form').each(function() {
var $qtyInput = $(this).find('.quantity-input');
$qtyInput.after(partials('qty-stepper', $qtyInput.toString()));
});
// PROMO CODES
$('#promo-code').parent().addClass('promo-wrap');
$('#promo-code-submit').parent().addClass('promo-submit-wrap');
$('.promo-remove').parent().addClass('promo-item');
return {
body: $.html()
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment