PageSourceSearch

https://empirekrep.ru/local/components/aspro/theme.selector.lite/templates/.default/script.js?177998283610866

js empirekrep.ru collected 2026-10-07 18:16:48 UTC 10,866 bytes, 317 lines download raw bytes

1if (typeof window.JThemeSelector === 'undefined') {
2    window.JThemeSelector = function(id, params, result) {
3        var _private = {
4            inited: false,
5            id: id,
6        };
7
8        Object.defineProperties(this, {
9            inited: {
10                get: function() {
11                    return _private.inited;
12                },
13                set: function(value) {
14                    if (value) {
15                        _private.inited = true;
16                    }
17                }
18            },
19            id: {
20                get: function() {
21                    return _private.id;
22                },
23            },
24        });
25
26        this.params = function(key) {
27            if (typeof params === 'object') {
28                if (typeof key !== 'undefined') {
29                    if (Object.keys(params).indexOf(key) > -1) {
30                        return params[key];
31                    }
32                }
33            }
34
35            return undefined;
36        }
37
38        this.result = function(key) {
39            if (typeof result === 'object') {
40                if (typeof key !== 'undefined') {
41                    if (Object.keys(result).indexOf(key) > -1) {
42                        return result[key];
43                    }
44                }
45            }
46
47            return undefined;
48        }
49
50        this.init();
51    }
52
53    window.JThemeSelector.prototype = {
54        node: null,
55
56        get color() {
57            if (this.isDefaultColor) {
58                return 'default';
59            } else {
60                return BX.hasClass(document.body, 'theme-dark') ? 'dark': 'light';
61            }
62        },
63        set color(value) {
64            if (
65                this.node &&
66                (
67                    value === 'light' ||
68                    value === 'dark' ||
69                    value === 'default'
70                )
71            ) {
72                let color = value;
73
74                if (value === 'default') {
75                    color = this.defaultColor;
76                }
77                
78                let item = this.node.querySelector('.theme-selector__item--' + color);
79                if (
80                    item &&
81                    !BX.hasClass(item, 'current')
82                ) {
83                    BX.addClass(item, 'current');
84
85                    this.node.setAttribute('title', BX.message('TS_T_' + color));
86
87                    let items = Array.prototype.slice.call(this.node.querySelectorAll('.theme-selector__item.current:not(.theme-selector__item--' + color + ')'));
88                    if (items.length) {
89                        for (let i = 0; i < items.length; ++i) {
90                            BX.removeClass(items[i], 'current');
91                        }
92                    }
93                }
94
95                let changed = !BX.hasClass(document.body, 'theme-' + value);
96
97                if (changed) {
98                    BX.removeClass(document.body, 'theme-default theme-dark theme-light');
99                    BX.addClass(document.body, 'theme-' + value);
100
101                    let items = Array.prototype.slice.call(document.querySelectorAll('.style-switcher [data-option-id="THEME_VIEW_COLOR"]'));
102                    if (items.length) {
103                        for (let i = 0; i < items.length; ++i) {
104                            let val = items[i].getAttribute('data-option-value');
105                            if (
106                                val &&
107                                val.toLowerCase() === value
108                            ) {
109                                BX.addClass(items[i], 'current');
110                            } else {
111                                BX.removeClass(items[i], 'current');
112                            }
113                        }
114                    }
115
116                    let fd = new FormData();
117                    fd.set('color', value);
118                    this.sendAction('setColor', fd);
119
120                    BX.onCustomEvent(
121                        'onChangeThemeColor', 
122                        [{
123                            value: value,
124                        }]
125                    );
126                }
127            }
128        },
129
130        get isDefaultColor() {
131            return BX.hasClass(document.body, 'theme-default');
132        },
133
134        get defaultColor() {
135            return window.matchMedia("(prefers-color-scheme: dark)").matches ? 'dark' : 'light';
136        },
137
138        init: function() {
139            if (!this.inited) {
140                this.inited = true;
141
142                this.node = BX('theme-selector--' + this.id);
143                if (this.node) {
144                    this.node.theme_selector = this;
145
146                    this.bindEvents();
147
148                    // set current item as current body class
149                    this.color = this.color;
150                }
151            }
152        },
153
154        bindEvents: function() {
155            if (this.node) {
156                if (typeof this.handlers.onNodeClick === 'function') {
157                    BX.bind(
158                        this.node,
159                        'click',
160                        BX.proxy(
161                            this.handlers.onNodeClick,
162                            this
163                        )
164                    );
165                }
166
167                if (typeof this.handlers.onChangePrefersColorScheme === 'function') {
168                    window.matchMedia('(prefers-color-scheme: dark)').addEventListener(
169                        'change', 
170                        BX.proxy(
171                            this.handlers.onChangePrefersColorScheme,
172                            this
173                        )
174                    );
175                }
176
177                if (typeof this.handlers.onChangeThemeColor === 'function') {
178                    BX.addCustomEvent(
179                        'onChangeThemeColor',
180                        BX.proxy(
181                            this.handlers.onChangeThemeColor,
182                            this
183                        )
184                    );
185                }
186            }
187        },
188
189        unbindEvents: function() {
190            if (this.node) {
191                if (typeof this.handlers.onNodeClick === 'function') {
192                    BX.unbind(
193                        this.node,
194                        'click',
195                        BX.proxy(
196                            this.handlers.onNodeClick,
197                            this
198                        )
199                    );
200                }
201
202                if (typeof this.handlers.onChangePrefersColorScheme === 'function') {
203                    window.matchMedia('(prefers-color-scheme: dark)').removeEventListener(
204                        'change', 
205                        BX.proxy(
206                            this.handlers.onChangePrefersColorScheme,
207                            this
208                        )
209                    );
210                }
211
212                if (typeof this.handlers.onChangeThemeColor === 'function') {
213                    BX.removeCustomEvent(
214                        'onChangeThemeColor', 
215                        BX.proxy(
216                            this.handlers.onChangeThemeColor,
217                            this
218                        )
219                    );
220                }
221            }
222        },
223
224        sendAction: function(componentAction, data, onsuccess, onfailure, oncomplete) {
225            let componentName = 'aspro:theme.selector.lite';
226
227            data.set('is_ajax_post', 'Y');
228            data.set('sessid', BX.message('bitrix_sessid'));
229            data.set('lang', BX.message('LANGUAGE_ID'));
230            data.set('SITE_ID', this.result('SITE_ID'));
231            data.set('SIGNED_PARAMS', this.result('SIGNED_PARAMS'));
232
233            let promise = BX.ajax.runComponentAction(
234                componentName,
235                componentAction,
236                {
237                    mode: 'ajax',
238                    data: data,
239                }
240            );
241
242            promise.then(
243                BX.proxy(
244                    function(response){
245                        if (typeof onsuccess === 'function') {
246                            onsuccess(response);
247                        }
248    
249                        if (typeof oncomplete === 'function') {
250                            oncomplete();
251                        }
252                    },
253                    this
254                ),
255                BX.proxy(
256                    function(response){
257                        console.error(response);
258
259                        let message = '';
260                        for (let i = 0; i < response.errors.length; ++i) {
261                            if (
262                                typeof response.errors[i] === 'object' &&
263                                response.errors[i].message.length
264                            ) {
265                                if (
266                                    !message.length ||
267                                    response.errors[i].message.length < message.length
268                                ) {
269                                    message = response.errors[i].message;
270                                }
271                            }
272                        }
273        
274                        if (typeof onfailure === 'function') {
275                            onfailure(message);
276                        }
277    
278                        if (typeof oncomplete === 'function') {
279                            oncomplete();
280                        }
281                    },
282                    this
283                ),
284            );
285        },
286
287        handlers: {
288            onNodeClick: function(event) {
289                // current color
290                let color = this.isDefaultColor ? this.defaultColor : this.color;
291
292                // invert color
293                this.color = color === 'light' ? 'dark' : 'light';
294            },
295
296            onChangePrefersColorScheme: function(event) {     
297                if (this.isDefaultColor) {
298                    if (!event) {
299                        event = window.event;
300                    }
301    
302                    this.color = 'default';
303                }
304            },
305
306            onChangeThemeColor: function(eventdata) {
307                if (
308                    typeof eventdata === 'object' &&
309                    eventdata &&
310                    'value' in eventdata
311                ) {
312                    this.color = eventdata.value;
313                }
314            },
315        },
316    }
317}

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.