<commit_before>'use strict';

var $ = require('jquery'),
    _ = require('underscore'),
    overlay = require('./overlay'),
    spinner = require('./spinner'),
    $cart,
    isExpanded = false;

var setItemCount = function() {
    var itemsCount = $('.cart__item-name').length;
    if (itemsCount > 0 && !isExpanded) {
        $cart.addClass('js-cart-has-items').attr('data-item-count', itemsCount);
    } else {
        $cart.removeClass('js-cart-has-items');
    }
};

var showCart = function() {
    $cart.addClass('cart--expanded');
    $cart.removeClass('js-cart-has-items');
    overlay.show();
    isExpanded = true;
    setItemCount();
};

var hideCart = function() {
    $cart.removeClass('cart--expanded');
    setItemCount();
    overlay.hide();
    isExpanded = false;
    setItemCount();
};

var renderCart = function(data) {
    $('#cart-overlay').html(data);
};

var loadCart = function() {
    $.get('/cart/overlay')
        .done(function (data) {
            renderCart(data)
        })
        .always(function () {
            setItemCount();
        })
    ;
};

var addSku = function (e) {
    e.preventDefault();

    var sku = $(e.target).data('sku');
    var qty = $(e.target).parents('section').find('.spinner.product__quantity [name=quantity]').val();

    $.post('/cart/add/' + sku, { quantity: qty })
        .done(function (data) {
            renderCart(data);
            showCart();
        });
};

var removeSku = function (e) {
    e.preventDefault();

    var sku = $(e.target).parents('.cart-item').data('sku');

    $.post('/cart/remove/' + sku)
        .done(function (data) {
            renderCart(data);
        });
};

var increaseQty = function (e) {
    changeQty(e, 1);
};

var decreaseQty = function (e) {
    changeQty(e, -1);
};

var changeQty = function (e, changeQty) {
    e.preventDefault();

    changeQty = typeof changeQty !== 'undefined' ? changeQty : 1;

    var sku = $(e.target).parents('.cart-item').data('sku');
    var qty = parseInt($(e.target).parents('.cart-item').find('.cart-quantity').val()) + changeQty;

    $.post('/cart/change/' + sku + '/' + qty)
        .done(function (data) {<commit_msg>Using decrease/increase instead of change<commit_after>'use strict';

var $ = require('jquery'),
    _ = require('underscore'),
    overlay = require('./overlay'),
    spinner = require('./spinner'),
    $cart,
    isExpanded = false;

var setItemCount = function() {
    var itemsCount = $('.cart__item-name').length;
    if (itemsCount > 0 && !isExpanded) {
        $cart.addClass('js-cart-has-items').attr('data-item-count', itemsCount);
    } else {
        $cart.removeClass('js-cart-has-items');
    }
};

var showCart = function() {
    $cart.addClass('cart--expanded');
    $cart.removeClass('js-cart-has-items');
    overlay.show();
    isExpanded = true;
    setItemCount();
};

var hideCart = function() {
    $cart.removeClass('cart--expanded');
    setItemCount();
    overlay.hide();
    isExpanded = false;
    setItemCount();
};

var renderCart = function(data) {
    $('#cart-overlay').html(data);
};

var loadCart = function() {
    $.get('/cart/overlay')
        .done(function (data) {
            renderCart(data)
        })
        .always(function () {
            setItemCount();
        })
    ;
};

var addSku = function (e) {
    e.preventDefault();

    var sku = $(e.target).data('sku');
    var qty = $(e.target).parents('section').find('.spinner.product__quantity [name=quantity]').val();

    $.post('/cart/add/' + sku, { quantity: qty })
        .done(function (data) {
            renderCart(data);
            showCart();
        });
};

var removeSku = function (e) {
    e.preventDefault();

    var sku = $(e.target).parents('.cart-item').data('sku');

    $.post('/cart/remove/' + sku)
        .done(function (data) {
            renderCart(data);
        });
};

var increaseQty = function (e) {
    var sku = $(e.target).parents('.cart-item').data('sku');

    $.post('/cart/increase/' + sku)
        .done(function (data) {
            renderCart(data);
        });
};

var decreaseQty = function (e) {
    var sku = $(e.target).parents('.cart-item').data('sku');

    $.post('/cart/decrease/' + sku)
        .done(function (data) {
            renderCart(data);
        });
};

var changeQty = function (e, changeQty) {
    e.preventDefault();

    changeQty = typeof changeQty !== 'undefined' ? changeQty : 1;

    var sku = $(e.target).parents('.cart-item').data('sku');
    var qty = parseInt($(e.target).parents('.cart-item').find('.cart-quantity').val()) + changeQty;

    $.post('/cart/change/' + sku + '/' + qty)
        .done(function (data) {
{'fraction_non_alphanumeric': 0.19961365099806824, 'fraction_numerical': 0.00128783000643915, 'mean_word_length': 2.5984555984555984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3740649', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1520, 'n_words': 268}