PageSourceSearch

https://mamako.ru/bitrix/js/vbcherepanov.bonus/bonus_integration.js?156923601421407

js mamako.ru collected 2026-10-04 00:06:22 UTC 21,407 bytes, 435 lines download raw bytes

1(function(window){
2    'use strict';
3
4    if (window.ITRBonusIntegrate)
5        return;
6
7    window.ITRBonusIntegrate = function(arParams){
8        if (typeof arParams === 'object') {
9            this.Params=arParams;
10            this.elementcount = 0;
11            this.elementID = 0;
12        }
13        this.DetailElement();
14        this.BasketAllBonus();
15        if(BX.Sale)
16            this.SOAAjax();
17        BX.addCustomEvent('OnBasketChange',  BX.proxy(this.BasketAllBonus, this));
18        BX.addCustomEvent('onCatalogElementChangeOffer',BX.proxy(this.DetailElement, this));
19        BX.addCustomEvent('ChangeQuantity',  BX.proxy(this.ChangeQuantity, this));
20        BX.addCustomEvent('onAjaxSuccess', BX.proxy(this.SOAAjax, this));
21    };
22    window.ITRBonusIntegrate.prototype = {
23        BasketAllBonus:function(){
24            if(!BX.Sale || !BX.Sale.BasketComponent)
25                return;
26
27            if(!BX.Sale.BasketComponent.result.GRID.ROWS && BX.Sale.BasketComponent.result.BASKET_ITEM_RENDER_DATA)
28                BX.Sale.BasketComponent.result.GRID.ROWS = BX.Sale.BasketComponent.result.BASKET_ITEM_RENDER_DATA;
29            if(!BX.Sale.BasketComponent.result.GRID.ROWS)
30                return;
31            var params= {
32                AJAX: 'Y',
33                SITE_ID: this.Params.SITE_ID,
34                TYPE:'CART',
35                ENDTOEND: 'Y',
36                GRID: BX.Sale.BasketComponent.result.GRID.ROWS,
37                COUNTS:1,
38            };
39            var _this=this;
40            if(this.Params.CART.ON==true) {
41                if(!document.getElementById('bonus_all')) {
42                    var itog_block = BX.findChild(BX(_this.Params.CART.MAIN_BLOCK), {
43                        'tag': 'div',
44                        'class': _this.Params.CART.OUT_BLOCK
45                    }, true);
46                    var bonus_all = BX.create('DIV', {props: {id: 'bonus_all'}});
47                    itog_block.appendChild(bonus_all);
48                }
49
50                BX.ajax({
51                    url: this.Params.CART.PATH,
52                    data: params,
53                    method: 'POST',
54                    dataType: 'json',
55                    timeout: 30,
56                    async: true,
57                    processData: true,
58                    scriptsRunFirst: true,
59                    emulateOnload: true,
60                    start: true,
61                    cache: false,
62                    onsuccess: function (data) {
63                        if (parseFloat(data.ALLBONUS) > 0) {
64                            var p=document.getElementById('bonus_all');
65                            if (p) {
66                                BX.adjust(BX('bonus_all'), {html: _this.Params.CART.LANG_BONUS + ' ' + data.ALLBONUS});
67                            }
68                            else{
69                                var itog_block = BX.findChild(BX(_this.Params.CART.MAIN_BLOCK), {
70                                    'tag': 'div',
71                                    'class': _this.Params.CART.OUT_BLOCK
72                                }, true);
73                                var bonus_all = BX.create('DIV', {props: {id: 'bonus_all'}, html: _this.Params.CART.LANG_BONUS + ' ' + data.ALLBONUS});
74                                itog_block.appendChild(bonus_all);
75                            }
76
77                        }
78                        else {
79                            BX.remove(BX('bonus_all'));
80                        }
81                        if (_this.Params.CART.BONUS_OFFER == true) {
82                            for (var id in data.ITEMS) {
83                                var item = data.ITEMS[id];
84                                var product_block = BX('basket-item-' + item.ID);
85                                var price_blocks = BX.findChild(product_block, {
86                                    'tag': 'div',
87                                    'class': 'basket-item-block-price'
88                                }, true, true);
89                                var price_for_item = price_blocks[1];
90                                var bonus_item = BX.create('DIV', {
91                                    props: {
92                                        id: 'bonus_item_' + item.ID,
93                                        className: 'bonus bonus_item_cart'
94                                    }, html: _this.Params.CART.OFFER_LANG_BONUS + ' ' + item.BONUS
95                                });
96                                BX.remove(BX('bonus_item_' + item.ID));
97
98                                if (parseFloat(item.BONUS) > 0)
99                                    price_for_item.appendChild(bonus_item);
100                            }
101                        }
102                        if (_this.Params.CARTBONUSPAY.ON == true) {
103                            var bonuspay_block = BX.findChild(BX(_this.Params.CARTBONUSPAY.MAIN_BLOCK), {
104                                'tag': 'div',
105                                'class': _this.Params.CARTBONUSPAY.OUT_BLOCK
106                            }, true);
107                            var bonuspay = BX.create('DIV', {
108                                props: {id: 'bonuspay'},
109                                html: 'bonuspay for cart (test) !!!not use!!!'
110                            });
111                            bonuspay_block.appendChild(bonuspay);
112                        }
113                    },
114                    onfailure: function () {
115
116                    }
117                });
118            }
119        },
120        SOAAjax:function(){
121            if(!BX.Sale || BX.Sale.OrderAjaxComponent == undefined)
122                return;
123
124            this.payBonusElement(BX.Sale.OrderAjaxComponent.result);
125
126        },
127        payBonusElement:function(result){
128            if(result!=undefined) {
129                BX.remove(BX('bonus_order'));
130                BX.remove(BX('bonus_pay'));
131                if (this.Params.SOA.MAIN_BLOCK) {
132                    var total_block = BX.findChild(BX(this.Params.SOA.MAIN_BLOCK), {
133                        'tag': 'div',
134                        'class': this.Params.SOA.OUT_BLOCK
135                    }, true, true);
136                    if (total_block instanceof Array) {
137                        var cnt = parseInt(total_block.length);
138
139                        if (cnt > 2) {
140                            cnt = cnt - 2;
141                        }
142                        if (cnt < 0) cnt = 0;
143                    }
144
145                    if (parseFloat(result.TOTAL.BONUS_ORDER) > 0) {
146                        BX.remove(BX('bonus_order'));
147                        var block_order_bonus = BX.create('DIV', {
148                            attrs: {className: 'bx-soa-cart-total-line', id: 'bonus_order'},
149                            html: '<div id="order_bonus"><span class="bx-soa-cart-t">' + this.Params.SOA.LANG_BONUS + '</span><span class="bx-soa-cart-d">' + result.TOTAL.BONUS_ORDER + '</span></div>'
150                        });
151                        if (total_block[cnt] && block_order_bonus)
152                            BX.insertAfter(block_order_bonus, total_block[cnt]);
153                    }
154                    if (parseFloat(result.TOTAL.BONUS_PAY) > 0) {
155                        BX.remove(BX('bonus_pay'));
156                        var block_bonus_pay = BX.create('DIV', {
157                            attrs: {className: 'bx-soa-cart-total-line', id: 'bonus_pay'},
158                            html: '<div id="order_bonuspay"><span class="bx-soa-cart-t">' + this.Params.SOA.LANG_BONUSPAY + '</span><span class="bx-soa-cart-d">' + result.TOTAL.BONUS_PAY + '</span></div>'
159                        });
160                        if (total_block[cnt] && block_bonus_pay)
161                            BX.insertAfter(block_bonus_pay, total_block[cnt]);
162                    }
163
164                }
165                if (result.BONUSPAY && result.BONUSPAY.DISPLAY == true) {
166                    var payment_block = BX.create('DIV', {
167                        attrs: {
168                            id: 'itrbonus-payment-bonus',
169                            className: 'bx-soa-section'
170                        }
171                    });
172                    var title = BX.create('DIV', {
173                        attrs: {className: 'bx-soa-section-title-container'},
174                        html: '<h2 class="bx-soa-section-title col-sm-9">
174' +
175                            '<span class="bx-soa-section-title-count"></span>' + result.BONUSPAY.NAME + '</h2>'
176                    });
177                    var con = BX.create('DIV', {attrs: {className: 'bx-soa-section-content container-fluid'}});
178
179                    var container = BX.create('DIV', {attrs: {className: 'bx-soa-pp row'}});
180                    var container_in = BX.create('DIV', {attrs: {className: 'col-sm-9 bx-soa-pp-item-container'}});
181                    var container_inpic = BX.create('DIV', {attrs: {className: 'col-sm-2 bx-soa-pp-item-container'}});
182                    payment_block.appendChild(title);
183
184
185                    var comment_block = BX.create('DIV', {
186                        props: {className: 'bonus_comment'},
187                        children: [
188                            BX.create('strong', {text: this.Params.SOA.ITR_BONUS_TEXT_IN_YOU_ACCOUNT.replace("#SUMMA#", result.BONUSPAY.CURRENT_BONUS_BUDGET_FORMATED.replace("&nbsp;", " "))})
189                        ]
190                    });
191                    var max_pay = BX.create('span', {html: '<br />' + this.Params.SOA.ITR_BONUS_TXT_YOU_MUST_PAY.replace("#PERCENT#", result.BONUSPAY.ORDER_PAY_PERCENT).replace("#MAXPAY#", result.BONUSPAY.MAXPAY_FORMATTED)});
192
193                    var pay_field_block = BX.create('DIV', {
194                        props: {id: 'bonus_payfield_block'},
195                        children: [BX.create('strong', {text: result.BONUSPAY.USER_INPUT == true ? this.Params.SOA.ITR_BONUS_TXT_HOW_MUCH_BONUS : ''})]
196                    });
197
198                    var non_bonuspay = BX.create('DIV', {
199                        props: {className: 'bonus_comment'},
200                        children: [
201                            BX.create('strong', {text: this.Params.SOA.ITR_BONUS_NONE_PAYBONUS})
202                        ]
203                    });
204
205                    var input_field = BX.create('input', {
206                        attrs: {
207                            type: 'text',
208                            id: 'BONUS_CNT',
209                            value: result.BONUSPAY.MAXPAY,
210                            name: 'BONUS_CNT',
211                            disabled: result.PAY_BONUS_ACCOUNT ? 'disable' : '',
212                        },
213                        style: {
214                            'width':'150px'
215                        }
216                    });
217                    if(this.Params.CHECK_SMS.ON == 'Y') {
218                        var sms_field_block = BX.create('DIV', {
219                            props: {id: 'sms_payfield_block'},
220                            children: [BX.create('strong', {text: this.Params.CHECK_SMS.SMSTEXT})]
221                        });
222                        var sms_code = BX.create('input', {
223                            attrs: {
224                                type: 'text',
225                                id: 'SMSCODE',
226                                value: result.SMSCODE ? result.SMSCODE : '',
227                                name: 'SMSCODE',
228                                disabled: result.CHECKSMS ? 'disable' : '',
229                            },
230                            style: {
231                                'width': '150px'
232                            }
233                        });
234                        var checksms = BX.create('LABEL', {
235                                props: {className: 'bxr-subscribe-tab-link bxr-font-color bxr-border-color'},
236                                children: [
237                                    BX.create('INPUT', {
238                                        attrs: {
239                                            type: 'checkbox',
240                                            id: 'CHECK_SMS',
241                                            name: 'CHECK_SMS',
242                                            value: 'Y',
243                                            checked: result.CHECKSMS
244                                        },
245                                        style: {
246                                            'display': 'none',
247                                        },
248                                        events: {
249                                            click: BX.proxy(this.checksms, this)
250                                        }
251                                    }),
252                                    BX.create('SPAN', {
253                                        text: (result.CHECKSMS ? this.Params.SOA.ITR_BONUS_TXT_BONUSPAY_CANCEL : this.Params.SOA.ITR_BONUS_TXT_BONUSPAY_OK)
254                                    })
255                                ],
256                                style: {
257                                    'border': '1px solid #e3e6e8',
258                                    'padding': '2px',
259                                    'margin-left': '10px',
260                                    'cursor': 'pointer',
261                                },
262                            }
263                        );
264
265                    }
266
267                    var input_field_hidden = BX.create('input', {
268                        attrs: {
269                            type: 'hidden',
270                            id: 'BONUS_CNT',
271                            value: result.BONUSPAY.MAXPAY,
272                            name: 'BONUS_CNT',
273                        },
274                    });
275
276                    var hiddenpay = BX.create('INPUT', {
277                        attrs: {
278                            type: 'hidden',
279                            name: 'PAY_BONUS_ACCOUNT',
280                            value: 'N',
281                        },
282
283                    });
284
285                    var label = BX.create('LABEL', {
286                            props: {className: 'bxr-subscribe-tab-link bxr-font-color bxr-border-color'},
287                            children: [
288                                BX.create('INPUT', {
289                                    attrs: {
290                                        type: 'checkbox',
291                                        id: 'PAY_BONUS_ACCOUNT',
292                                        name: 'PAY_BONUS_ACCOUNT',
293                                        value: 'Y',
294                                        checked: result.PAY_BONUS_ACCOUNT
295                                    },
296                                    style: {
297                                        'display': 'none',
298                                    },
299                                    events: {
300                                        click: BX.proxy(this.selectBonusPaySystem, this)
301                                    }
302                                }),
303                                BX.create('SPAN', {
304                                    text: (result.PAY_BONUS_ACCOUNT ? this.Params.SOA.ITR_BONUS_TXT_BONUSPAY_CANCEL : this.Params.SOA.ITR_BONUS_TXT_BONUSPAY_OK)
305                                })
306                            ],
307                            style: {
308                                'border': '1px solid #e3e6e8',
309                                'padding': '2px',
310                                'margin-left': '10px',
311                                'cursor': 'pointer',
312                            },
313                        }
314                    );
315
316                    var help = BX.create('DIV', {
317                            props: {},
318                            children: [
319                                BX.create('A', {
320                                    props: {href: BX.util.htmlspecialchars(this.Params.SOA.ITR_BONUS_PATH_TO_HELP)},
321                                    html: BX.util.htmlspecialchars(this.Params.SOA.ITR_BONUS_TEXT_TO_HELP)
322                                }),
323                            ],
324                        }
325                    );
326
327                    var logoNode = BX.create('DIV', {props: {className: 'bx-soa-pp-company-image'}});
328                    var logotype = result.BONUSPAY.LOGOTIP_SRC;
329                    if (logotype) {
330                        logoNode.setAttribute('style',
331                            'background-image: url(' + logotype + ');' +
332                            'background-image: -webkit-image-set(url(' + logotype + ') 1x, url(' + logotype + ') 2x)'
333                        );
334                    }
335                    var pic_con = BX.create('DIV', {attrs: {className: 'bx-soa-pp-company-graf-container'}});
336                    pic_con.appendChild(logoNode);
337                    container_inpic.appendChild(pic_con);
338                    container_in.appendChild(comment_block);
339                    if(result.BONUSPAY.MAXPAY > 0){
340                        container_in.appendChild(max_pay);
341                        container_in.appendChild(pay_field_block);
342                        container_in.appendChild(hiddenpay);
343                        container_in.appendChild(input_field_hidden);
344                        if (result.BONUSPAY.USER_INPUT == true) {
345                            container_in.appendChild(input_field);
346                        }
347                        container_in.appendChild(label);
348                        if(this.Params.CHECK_SMS.ON == 'Y' && result.PAY_BONUS_ACCOUNT){
349                            container_in.appendChild(sms_field_block);
350                            container_in.appendChild(sms_code);
351                            container_in.appendChild(checksms);
352                        }
353                    }else{
354                        container_in.appendChild(non_bonuspay);
355                    }
356
357                    container_in.appendChild(help);
358
359                    var p_block = BX.findChild(BX(this.Params.SOA.BONUSPAY_MAIN_BLOCK), {
360                        'tag': 'div',
361                        'class': this.Params.SOA.BONUSPAY_OUT_BLOCK
362                    }, true);
363                    BX.remove(BX('itrbonus-payment-bonus'));
364                    container.appendChild(container_inpic);
365                    container.appendChild(container_in);
366                    con.appendChild(container);
367                    payment_block.appendChild(con);
368                    BX.insertAfter(payment_block, BX(this.Params.SOA.BONUSPAY_MAIN_BLOCK));
369                } else {
370                    BX.remove(BX('itrbonus-payment-bonus'));
371                }
372            }
373        },
374        checksms:function(){
375            BX.Sale.OrderAjaxComponent.sendRequest();
376        },
377        selectBonusPaySystem:function(){
378            BX.Sale.OrderAjaxComponent.sendRequest();
379        },
380        DetailElement:function (eventData){
381            if(eventData) {
382                this.elementID = eventData.newId;
383                if (this.elementcount != 0)
384                    this.ElementBonus();
385            }
386        },
387        ChangeQuantity:function(eventData){
388            this.elementID=eventData.newId;
389            this.elementcount=eventData.Qua;
390            this.ElementBonus();
391        },
392        ElementBonus:function(){
393            if(this.Params.DETAIL.ON==true){
394                var params= {
395                    AJAX: 'Y',
396                    SITE_ID:this.Params.SITE_ID,
397                    PRODUCT_ID:this.elementID,
398                    COUNTS :this.elementcount,
399                    TEMPLATE:this.Params.DETAIL.COMP_TEMPLATE,
400                };
401                var _this=this;
402                BX.ajax({
403                    url: this.Params.DETAIL.PATH,
404                    data: params,
405                    method: 'POST',
406                    dataType: 'html',
407                    timeout: 30,
408                    async: true,
409                    processData: true,
410                    scriptsRunFirst: true,
411                    emulateOnload: true,
412                    start: true,
413                    cache: false,
414                    onsuccess: function(data){
415                        var itog_block = BX.findChild(BX(_this.Params.DETAIL.MAIN_BLOCK), {'tag': 'div', 'class': _this.Params.DETAIL.OUT_BLOCK}, true);
416                        if(_this.Params.DETAIL.COMP_TEMPLATE==''){
417                            var bonus_all = BX.create('DIV', {props: {id: 'bonus_all'}, html: _this.Params.DETAIL.LANG_BONUS+' '+data });
418                        }else{
419                            var bonus_all = BX.create('DIV', {props: {id: 'bonus_all'}, html: data });
420                        }
421                        BX.remove(BX('bonus_all'));
422                        //if(parseFloat(data) > 0) {
423                        itog_block.appendChild(bonus_all);
424                        //}
425                    },
426                    onfailure: function(){
427
428                    }
429                });
430            }
431
432        }
433
434    };
435})(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.