summaryrefslogtreecommitdiff
path: root/html/content/js/Plugins/quantity.js
blob: f124c63bfd82715359c073871ba68b1882f4e009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$$plugins.define('quantity', ['dom'], function (element, options, dom) {
    //const plugin = this,
    //    increaseButton = element.querySelector('.quantity__btn--inc'),
    //    decreaseButton = element.querySelector('.quantity__btn--dec'),
    //    input = element.querySelector('input'),
    //    maxQuantity = options.MaxQuantity,
    //    minQuantity = options.MinQuantity || 1;

    //let currentValue = parseInt(input.value);

    //checkButtons();
    //plugin.on('click', increaseButton, updateValue);
    //plugin.on('click', decreaseButton, updateValue);

    //function updateValue(e) {
    //    const button = dom.closest(e.target, '[data-ref="quantity-control"]'),
    //        previousValue = currentValue;
    //    if (!button || button.classList.contains('disabled')) {
    //        return false;
    //    }
    //    if (button === increaseButton) {
    //        currentValue += 1;
    //    } else {
    //        currentValue -= 1;
    //    }

    //    console.log(button)
    //    input.value = currentValue;
    //    checkButtons();
    //    if (options.ItemId) {
    //        plugin.emit('cart:quantity.changed', {
    //            quantity: currentValue,
    //            item: options.ItemId,
    //            element: e.target,
    //            fail: function onFail() {
    //                currentValue = previousValue;
    //            }
    //        });
    //    }
    //}

    //function checkButtons() {
    //    if (currentValue > minQuantity) {
    //        decreaseButton.classList.remove('disabled');
    //    } else {
    //        decreaseButton.classList.add('disabled');
    //    }

    //    if (currentValue < maxQuantity) {
    //        increaseButton.classList.remove('disabled');
    //    } else {
    //        increaseButton.classList.add('disabled');
    //    }
    //}
});