PageSourceSearch

https://valaam.ru/local/components/valaam/rites/templates/header/script.js?17849629215294

js valaam.ru collected 2026-10-02 06:00:51 UTC 5,294 bytes, 143 lines download raw bytes

1(function() {
2    'use strict';
3
4    if (!!window.JCRitesCartCounter)
5        return;
6
7    window.JCRitesCartCounter = function(params) {
8        this.mainContainerId = null;
9        this.status = [];
10        this.labelEmpty = 'Корзина записок';
11        this.labelCount = 'Корзина записок, записок: #COUNT#';
12        if(typeof params === "object")
13        {
14            if(params.status){
15                this.status = params.status;
16            }
17            if(params.mainContainerId){
18                this.mainContainerId = params.mainContainerId;
19            }
20            if(params.labelEmpty){
21                this.labelEmpty = params.labelEmpty;
22            }
23            if(params.labelCount){
24                this.labelCount = params.labelCount;
25            }
26        }
27        BX.ready(BX.delegate(this.init,this));
28    };
29    window.JCRitesCartCounter.prototype = {
30        init: function (){
31            if(this.mainContainerId) {
32                this.container = document.getElementById(this.mainContainerId);
33            }
34        },
35        getCartLink: function (){
36            return this.container ? this.container.querySelector('.header__btn--cart') : null;
37        },
38        syncAriaLabel: function (count){
39            const link = this.getCartLink();
40            if (!link) {
41                return;
42            }
43            if (count) {
44                const displayCount = parseInt(count, 10) > 99 ? '99+' : String(count);
45                link.setAttribute(
46                    'aria-label',
47                    this.labelCount.replace('#COUNT#', displayCount)
48                );
49            } else {
50                link.setAttribute('aria-label', this.labelEmpty);
51            }
52        },
53        load: function (){
54            if(!this.container) return;
55            let query = new URLSearchParams({
56                clientId:this.getClientId(),
57                email:this.getConfirmedEmail(),
58            });
59            for (let index in this.status) {
60                if(this.status.hasOwnProperty(index))
61                {
62                    query.append('status['+index+']', this.status[index]);
63                }
64            }
65            query = query.toString();
66            fetch('/api/rites?'+query, {
67                method: 'GET',
68                headers: {
69                    'Content-Type': 'application/json;charset=utf-8'
70                }
71            }).then(
72                BX.proxy(this.loadResult,this)
73            );
74        },
75        loadResult: async function (response){
76            if(!this.container) return;
77            try {
78                let result = await response.json();
79                if(result.hasOwnProperty("nav") && result.nav.hasOwnProperty("totalCount"))
80                {
81                    this.showCount(result.nav.totalCount);
82                    return;
83                }
84                else if(result.hasOwnProperty("items") && result.items.length)
85                {
86                    this.showCount(result.items.length);
87                    return;
88                }
89            }
90            catch (e) {}
91            this.showCount();
92        },
93        showCount:function (count){
94            if(!this.container) return;
95            let counter = this.container.querySelector(".header__counter-value");
96            if(count) {
97                if(counter){
98                    counter.innerHTML = parseInt(count)>99?"99+":count;
99                }
100                else {
101                    const link = this.getCartLink() || this.container;
102                    link.appendChild( BX.create({
103                        tag: 'div',
104                        props: {className: 'header__counter'},
105                        attrs: {'aria-hidden': 'true'},
106                        children: [
107                            BX.create({
108                                tag:'div',
109                                props: {
110                                    className: "header__counter-value"
111                                },
112                                text:parseInt(count)>99?"99+":count
113                            })
114                        ]
115                    }));
116                }
117                this.syncAriaLabel(count);
118            }
119            else if(counter){
120                counter.parentNode.remove();
121                this.syncAriaLabel(0);
122            } else {
123                this.syncAriaLabel(0);
124            }
125        },
126        getConfirmedEmail() {
127            const fromUrl = new URLSearchParams(window.location.search).get("EMAIL");
128            if (fromUrl) {
129                localStorage.setItem("rites-confirmedEmail", fromUrl);
130                return fromUrl;
131            }
132            return localStorage.getItem("rites-confirmedEmail") || "";
133        },
134        getClientId() {
135            let id = localStorage.getItem("rites-client-id");
136            if (!id) {
137                id = window.crypto.getRandomValues(new Uint32Array(4)).reduce((acc, el) => acc += el.toString(16), '');
138                localStorage.setItem("rites-client-id", id);
139            }
140            return id;
141        },
142    }
143})();

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.