PageSourceSearch

https://farmamir.kg/bitrix/components/aspro/theme.selector.premier/templates/.default/script.js

js farmamir.kg collected 2026-10-02 12:38:08 UTC 7,768 bytes, 356 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		invert: function() {
155			// current color
156			let color = this.isDefaultColor ? this.defaultColor : this.color;
157
158			// invert color
159			this.color = color === 'light' ? 'dark' : 'light';
160		},
161
162		bindEvents: function() {
163			if (this.node) {
164				if (typeof this.handlers.onNodeClick === 'function') {
165					BX.bind(
166						this.node,
167						'click',
168						BX.proxy(
169							this.handlers.onNodeClick,
170							this
171						)
172					);
173				}
174
175				if (typeof this.handlers.onKeyDown === 'function') {
176					BX.bind(
177						document.body,
178						'keydown',
179						BX.proxy(
180							this.handlers.onKeyDown,
181							this
182						)
183					);
184				}
185
186				if (typeof this.handlers.onChangePrefersColorScheme === 'function') {
187					window.matchMedia('(prefers-color-scheme: dark)').addEventListener(
188						'change', 
189						BX.proxy(
190							this.handlers.onChangePrefersColorScheme,
191							this
192						)
193					);
194				}
195
196				if (typeof this.handlers.onChangeThemeColor === 'function') {
197					BX.addCustomEvent(
198						'onChangeThemeColor',
199						BX.proxy(
200							this.handlers.onChangeThemeColor,
201							this
202						)
203					);
204				}
205			}
206		},
207
208		unbindEvents: function() {
209			if (this.node) {
210				if (typeof this.handlers.onNodeClick === 'function') {
211					BX.unbind(
212						this.node,
213						'click',
214						BX.proxy(
215							this.handlers.onNodeClick,
216							this
217						)
218					);
219				}
220
221				if (typeof this.handlers.onKeyDown === 'function') {
222					BX.unbind(
223						document.body,
224						'keydown',
225						BX.proxy(
226							this.handlers.onKeyDown,
227							this
228						)
229					);
230				}
231
232				if (typeof this.handlers.onChangePrefersColorScheme === 'function') {
233					window.matchMedia('(prefers-color-scheme: dark)').removeEventListener(
234						'change', 
235						BX.proxy(
236							this.handlers.onChangePrefersColorScheme,
237							this
238						)
239					);
240				}
241
242				if (typeof this.handlers.onChangeThemeColor === 'function') {
243					BX.removeCustomEvent(
244						'onChangeThemeColor', 
245						BX.proxy(
246							this.handlers.onChangeThemeColor,
247							this
248						)
249					);
250				}
251			}
252		},
253
254		sendAction: function(componentAction, data, onsuccess, onfailure, oncomplete) {
255			let componentName = 'aspro:theme.selector.premier';
256
257			data.set('is_ajax_post', 'Y');
258			data.set('sessid', BX.message('bitrix_sessid'));
259			data.set('lang', BX.message('LANGUAGE_ID'));
260			data.set('SITE_ID', this.result('SITE_ID'));
261			data.set('SIGNED_PARAMS', this.result('SIGNED_PARAMS'));
262
263			let promise = BX.ajax.runComponentAction(
264				componentName,
265				componentAction,
266				{
267					mode: 'ajax',
268					data: data,
269				}
270			);
271
272			promise.then(
273				BX.proxy(
274					function(response){
275						if (typeof onsuccess === 'function') {
276							onsuccess(response);
277						}
278		
279						if (typeof oncomplete === 'function') {
280							oncomplete();
281						}
282					},
283					this
284				),
285				BX.proxy(
286					function(response){
287						console.error(response);
288
289						let message = '';
290						for (let i = 0; i < response.errors.length; ++i) {
291							if (
292								typeof response.errors[i] === 'object' &&
293								response.errors[i].message.length
294							) {
295								if (
296									!message.length ||
297									response.errors[i].message.length < message.length
298								) {
299									message = response.errors[i].message;
300								}
301							}
302						}
303		
304						if (typeof onfailure === 'function') {
305							onfailure(message);
306						}
307		
308						if (typeof oncomplete === 'function') {
309							oncomplete();
310						}
311					},
312					this
313				),
314			);
315		},
316
317		handlers: {
318			onNodeClick: function(event) {
319				this.invert();
320			},
321
322			onKeyDown: function(event) {
323				event = event || window.event;
324
325				if (
326					event.ctrlKey &&
327					event.shiftKey && 
328					event.keyCode == 76
329				) {
330					this.invert();
331					event.stopImmediatePropagation();
332				}
333			},
334
335			onChangePrefersColorScheme: function(event) {	 
336				if (this.isDefaultColor) {
337					if (!event) {
338						event = window.event;
339					}
340		
341					this.color = 'default';
342				}
343			},
344
345			onChangeThemeColor: function(eventdata) {
346				if (
347					typeof eventdata === 'object' &&
348					eventdata &&
349					'value' in eventdata
350				) {
351					this.color = eventdata.value;
352				}
353			},
354		},
355	}
356}

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.