<commit_before>/*
 Import all product specific js
 */
import $ from 'jquery';
import PageManager from './page-manager';
import Review from './product/reviews';
import collapsibleFactory from './common/collapsible';
import ProductDetails from './common/product-details';
import videoGallery from './product/video-gallery';
import { classifyForm } from './common/form-utils';

export default class Product extends PageManager {
    constructor(context) {
        super(context);
        this.url = location.href;
        this.$reviewLink = $('[data-reveal-id="modal-review-form"]');
        this.$buttonInc = $('[data-action="inc"]');
        this.$buttonDec = $('[data-action="dec"]');
        this.$qtyInput = $('.form-input--incrementTotal');
    }

    before(next) {
        // Listen for foundation modal close events to sanitize URL after review.
        $(document).on('close.fndtn.reveal', () => {
            if (this.url.indexOf('#writeReview') !== -1 && typeof window.history.replaceState === 'function') {
                window.history.replaceState(null, document.title, window.location.pathname);
            }
        });

        next();
    }

    loaded(next) {
        let validator;

        // Init collapsible
        collapsibleFactory();

        this.productDetails = new ProductDetails($('.productView'), this.context, window.BCData.product_attributes);

        videoGallery();

        const $reviewForm = classifyForm('.writeReview-form');
        const review = new Review($reviewForm);

        $('body').on('click', '[data-reveal-id="modal-review-form"]', () => {
            validator = review.registerValidation();
        });

        $reviewForm.on('submit', () => {
            if (validator) {
                validator.performCheck();
                return validator.areAll('valid');
            }

            return false;
        });

        var self = this;
        this.$buttonInc.on('click', function(e){
            e.preventDefault();
            var qtyStep = parseInt(self.$qtyInput.attr('data-quantity-min')) == 0 ? 1 : parseInt(self.$qtyInput.attr('data-quantity-min'));
            var oldQty = parseInt(self.$qtyInput.val());
            console.log(oldQty);
            self.$qtyInput.val(oldQty + qtyStep);
            return false;
        });

        this.$buttonDec.on('click', function(e){
            e.preventDefault();
            var qtyStep = parseInt(self.$qtyInput.attr('data-quantity-min')) == 0 ? 1 : parseInt(self.$qtyInput.attr('data-quantity-min'));
            var oldQty = parseInt(self.$qtyInput.val());
            console.log(oldQty);
            if (oldQty > qtyStep){
                self.$qtyInput.val(oldQty - qtyStep);
            }
            return false;
        });

        next();
    }

    after(next) {
        this.productReviewHandler();

        next();
    }

    productReviewHandler() {
        if (this.url.indexOf('#write_review') !== -1) {
            this.$reviewLink.click();
        }
    }
}<commit_msg>interval to quantity on product page<commit_after>/*
 Import all product specific js
 */
import $ from 'jquery';
import _ from 'lodash';
import PageManager from './page-manager';
import Review from './product/reviews';
import collapsibleFactory from './common/collapsible';
import ProductDetails from './common/product-details';
import videoGallery from './product/video-gallery';
import { classifyForm } from './common/form-utils';

export default class Product extends PageManager {
    constructor(context) {
        super(context);
        this.url = location.href;
        this.$reviewLink = $('[data-reveal-id="modal-review-form"]');
        this.$buttonInc = $('[data-action="inc"]');
        this.$buttonDec = $('[data-action="dec"]');
        this.$qtyInput = $('.form-input--incrementTotal');
    }

    before(next) {
        // Listen for foundation modal close events to sanitize URL after review.
        $(document).on('close.fndtn.reveal', () => {
            if (this.url.indexOf('#writeReview') !== -1 && typeof window.history.replaceState === 'function') {
                window.history.replaceState(null, document.title, window.location.pathname);
            }
        });

        next();
    }

    loaded(next) {
        let validator;

        // Init collapsible
        collapsibleFactory();

        this.productDetails = new ProductDetails($('.productView'), this.context, window.BCData.product_attributes);

        videoGallery();

        const $reviewForm = classifyForm('.writeReview-form');
        const review = new Review($reviewForm);

        $('body').on('click', '[data-reveal-id="modal-review-form"]', () => {
            validator = review.registerValidation();
        });

        $reviewForm.on('submit', () => {
            if (validator) {
                validator.performCheck();
                return validator.areAll('valid');
            }

            return false;
        });

        const increaseQty = _.bind(_.debounce(this.increaseQty, 100), this);
        this.$buttonInc.on('click', (event) => {
            increaseQty($(event.currentTarget));
            event.preventDefault();
            return false;
        });

        this.$buttonDec.on('click', (event) => {
            increaseQty($(event.currentTarget));
            event.preventDefault();
            return false;
        });

        next();
    }

    increaseQty($target) {
        const qtyStep = parseInt(this.$qtyInput.attr('data-quantity-min'), 10) === 0 ? 1 : parseInt(this.$qtyInput.attr('data-quantity-min'), 10);
        const oldQty = parseInt(this.$qtyInput.val(), 10);
        if ($target.data('action') === 'inc') {
            this.$qtyInput.val(oldQty + qtyStep);
        } else {
            if (oldQty > qtyStep) {
                this.$qtyInput.val(oldQty - qtyStep);
            }
        }
    }

    after(next) {
        this.productReviewHandler();

        next();
    }

    productReviewHandler() {
        if (this.url.indexOf('#write_review') !== -1) {
            this.$reviewLink.click();
        }
    }
}
{'fraction_non_alphanumeric': 0.1574272084224379, 'fraction_numerical': 0.0031255140648132917, 'mean_word_length': 2.2050606220347917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5279891', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1673, 'n_words': 317}