PageSourceSearch

https://alphahookah.ru/local/templates/alpha_s1/js/basket.js

js alphahookah.ru collected 2026-10-08 09:05:54 UTC 4,957 bytes, 142 lines download raw bytes

1(function (window){
2	'use strict';
3
4    if (window.Alpha.Basket)
5        return;
6    
7    window.Alpha.Basket = function (params)
8    {
9        this.params = {};
10        this.timer = false;
11        
12        if (params.containerId !== undefined && params.params !== undefined)
13        {
14            this.params = params;
15            
16            this.init();
17        }
18    };
19    
20    window.Alpha.Basket.prototype = {
21        
22        init: function () {
23            var _ = this;
24            
25            $("body").on('click', '#' + this.params.containerId + ' [data-entity="delete"]', function () {
26                var itemId = parseInt($(this).closest('[data-item-id]').data('item-id'));
27                if (itemId > 0)
28                {
29                    _.deleteItem(itemId);
30                }
31            });
32            
33            $("body").on('click', '#' + this.params.containerId + ' [data-entity="quantity-minus"], #' + this.params.containerId + ' [data-entity="quantity-plus"]', function () {
34                var qtyInput = $(this).closest('[data-item-id]').find('[data-entity="quantity-input"]'),
35                        itemRatio = parseFloat($(this).closest('[data-item-id]').data('item-qty-ratio'));
36
37                if (qtyInput.length > 0)
38                {
39                    var qty = parseFloat(qtyInput.val());
40
41                    if ($(this).data('entity') == "quantity-minus")
42                    {
43                        qty -= itemRatio;
44                        if (qty <= 0)
45                            qty = 0;
46                    } else
47                    {
48                        qty += itemRatio;
49                    }
50
51                    qtyInput.val(qty).trigger('change');
52                }
53            });
54
55            $("body").on('change', '#' + this.params.containerId + ' [data-entity="quantity-input"]', function () {
56
57                var itemId = parseInt($(this).closest('[data-item-id]').data('item-id')),
58                        itemRatio = parseFloat($(this).closest('[data-item-id]').data('item-qty-ratio')),
59                        qtyValue = parseFloat($(this).val()),
60                        changedValue = false;
61
62                if (qtyValue === '')
63                {
64                    qtyValue = itemRatio;
65                    changedValue = true;
66                }
67
68                if (qtyValue % itemRatio !== 0)
69                {
70                    qtyValue = Math.ceil((itemRatio - (qtyValue % itemRatio) + qtyValue) * 100) / 100;
71                    changedValue = true;
72                }
73
74                if (itemId > 0)
75                {
76                    _.updateItem(itemId, qtyValue);
77                }
78
79                if (changedValue)
80                    $(this).val(qtyValue);
81            });
82
83            BX.addCustomEvent(window, 'OnBasketChange', BX.delegate(function (event) {
84                if (event === undefined || event.data === undefined || event.data.containerId === undefined || (typeof(event.data) === 'object' && !!event.data.containerId && event.data.containerId !== this.params.containerId))
85                    this.refreshCart({});
86                
87            }, this));
88        },
89
90        updateItem: function (id, qty)
91	{
92            this.refreshCart ({action: 'update', itemId: id, quantity: qty});
93	},
94
95	deleteItem: function (id)
96	{
97            this.refreshCart ({action: 'delete', itemId: id});
98	},
99        
100        refreshCart: function (data)
101        {
102
103            var _ = this;
104            data.sessid = BX.bitrix_sessid();
105            data.siteId = this.params.siteId;
106            data.templateName = this.params.templateName;
107            data.arParams = this.params.params;
108                        
109            if (this.timer !== undefined)
110                clearTimeout(this.timer);
111            
112            this.timer = setTimeout(function () {
113
114                BX.ajax({
115                    url: _.params.ajaxPath,
116                    method: 'POST',
117                    dataType: 'html',
118                    data: data,
119                    timeout: 30,
120                    emulateOnload: true,
121                    onsuccess: function (result) {
122                        if (!result)
123                            return;
124
125                        var ob = BX.processHTML(result);
126
127                        BX(_.params.containerId).innerHTML = ob.HTML;
128                        BX.ajax.processScripts(ob.SCRIPT, true);
129
130                        if (!!data.action && (data.action === 'update' || data.action === 'delete'))
131                        {
132                            BX.onCustomEvent(window, 'OnBasketChange', {containerId: _.params.containerId});
133                        }
134                    }
135                });
136                
137            }, 500);
138        },
139        
140    };
141    
142})(window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.