PageSourceSearch

https://av-soft.ru/bitrix/templates/ranx-landing/assets/js/main.js

js av-soft.ru collected 2026-10-07 10:28:18 UTC 5,728 bytes, 227 lines download raw bytes

1$(document).ready(function(){
2	initMasks();
3	initSimplebar();
4	initTooltip();
5	
6	// go to anchor animation
7	$(document).on('click', 'a', function(e){
8		if (window.location.pathname !== $(this).prop('pathname')) {
9			return;
10		}
11
12		let href = $(this).attr('href');
13		if (typeof href != 'undefined' && href.indexOf('#block_') !== -1) {
14			e.preventDefault();
15
16			href = href.substr(href.indexOf('#block_'));
17			$('html, body').animate({ 
18                scrollTop: $(href).offset().top - 100
19            }, 500);
20		}
21	});
22});
23
24// wrapper for BX.ajax.runComponentAction
25function rxRunComponentAction(component, action, config = { data: {} })
26{
27	if (!config.data) {
28		config.data = {}
29	}
30
31	component = 'ranx:' + component + '.landing';
32	config.mode = config.mode || 'class'
33
34	// add extra fields
35	if (BX.message.SITE_ID)
36	{
37		config.data.SITE_ID = BX.message.SITE_ID;
38	}
39	config.data.sessid = BX.bitrix_sessid();
40
41	return BX.ajax.runComponentAction(component, action, config);
42}
43
44function initSimplebar()
45{
46	$('.js-simplebar').each(function(){new SimpleBar(this)});
47}
48
49function initTooltip()
50{
51	$('[data-toggle="tooltip"]').tooltip();
52}
53
54// convert serialized array to obj
55function convertFormArrToObj(dataArr)
56{
57	let data = {};
58
59	for (i = 0; i < dataArr.length; i++) {
60		if (dataArr[i]['name'].indexOf('[]') !== -1) {
61			let name = dataArr[i]['name'].slice(0, -2);
62			if (!data[name]) {
63				data[name] = [];
64			}
65			data[name].push(dataArr[i]['value']);
66		} else if (dataArr[i]['name'].indexOf('[') !== -1) { // fucking awesome kostyl!
67			let firstBracketPos = dataArr[i]['name'].indexOf('[');
68			let name = dataArr[i]['name'].slice(0, firstBracketPos) + ']' + dataArr[i]['name'].slice(firstBracketPos, -1);
69			data[name] = dataArr[i]['value'];
70		} else if (data[dataArr[i]['name']]) {
71			if (!Array.isArray(data[dataArr[i]['name']])) {
72				data[dataArr[i]['name']] = [data[dataArr[i]['name']]];
73			}
74			data[dataArr[i]['name']].push(dataArr[i]['value']);
75		} else {
76			data[dataArr[i]['name']] = dataArr[i]['value'];
77		}
78	}
79
80	return data;
81}
82
83function startBtnLoad($btn)
84{
85	let width = $btn.outerWidth();
86	let height = $btn.outerHeight();
87
88	$btn.data('original-html', $btn.html());
89	$btn.data('original-style', $btn.attr('style'));
90	$btn.html('<div class="spinner-grow"></div>');
91	$btn.css('width', width);
92	$btn.css('height', height);
93	$btn.addClass('loading');
94
95	$btn.prop('disabled', true);
96
97	$btn.css('padding', 0);
98	$btn.css('display', 'inline-flex');
99	$btn.css('justify-content', 'center');
100	$btn.css('align-items', 'center');
101}
102
103function endBtnLoad($btn)
104{
105	let originalText = $btn.data('original-html');
106	let originalStyle = $btn.data('original-style') || '';
107
108	$btn.html(originalText);
109	$btn.removeClass('loading');
110
111	$btn.prop('disabled', false);
112
113	$btn.attr('style', originalStyle);
114}
115
116function getSettingId()
117{
118	return $('body').data('setting-id') || '';
119}
120
121async function loadFiles(files, params = {})
122{
123	let promises = [];
124
125	$.each(files, function () {
126		const file = this;
127		const allowedExts = params.exts;
128		const allowedMimeType = params.mime;
129		const allowedSize = params.size;
130		if (!file ||
131			allowedExts && !allowedExts.includes('.' + getFileExt(file.name)) ||
132			allowedMimeType && allowedMimeType !== file.type.split('/').shift() ||
133			allowedSize && file.size > allowedSize){
134			return;
135		}
136
137		promises.push(new Promise(resolve => {
138			const reader = new FileReader();
139			reader.onload = () => resolve({
140				name: file.name,
141				mime: file.type,
142				size: file.size,
143				data: reader.result
144			});
145			reader.onerror = (error) => reject(error);
146			reader.readAsDataURL(file);
147		}));
148	});
149
150	// if the browser doesn't support allSettled
151	if(!Promise.allSettled) {
152		Promise.allSettled = function(promises) {
153			return Promise.all(promises.map(p => Promise.resolve(p).then(
154				value => ({status: 'fulfilled', value: value}),
155				error => ({status: 'rejected', reason: error})
156			)));
157		};
158	}
159
160	let results = await Promise.allSettled(promises);
161	let loadedFiles = [];
162	$.each(results, function () {
163		if (this.status === 'fulfilled') {
164			loadedFiles.push(this.value);
165		}
166	});
167
168	return loadedFiles;
169}
170
171function getFileExt(name = '')
172{
173	// https://stackoverflow.com/questions/190852/how-can-i-get-file-extensions-with-javascript/12900504#12900504
174	return name.toLowerCase().slice((name.lastIndexOf('.') - 1 >>> 0) + 2);
175}
176function getFileExtPrefix(name = '')
177{
178	const ext = getFileExt(name);
179	if (ext) {
180		return `extension:${ext.replace(/[^a-zA-Z0-9]+/g, '')};`;
181	}
182
183	return '';
184}
185
186async function loadFile($input, params = {})
187{
188	let files = await loadFiles($input.prop('files'), params);
189	if (files.length < 1) {
190		return;
191	}
192
193	return files.shift();
194}
195
196/* cookies */
197function getCookie(name) {
198	let matches = document.cookie.match(new RegExp(
199	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
200	));
201	return matches ? decodeURIComponent(matches[1]) : undefined;
202}
203function setCookie(name, value, options = {}) {
204
205	options = Object.assign({ path: '/' }, options);
206  
207	if (options.expires instanceof Date) {
208	  	options.expires = options.expires.toUTCString();
209	}
210  
211	let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
212  
213	for (let optionKey in options) {
214		updatedCookie += "; " + optionKey;
215		let optionValue = options[optionKey];
216		if (optionValue !== true) {
217			updatedCookie += "=" + optionValue;
218		}
219	}
220  
221	document.cookie = updatedCookie;
222}
223function deleteCookie(name) {
224	setCookie(name, "", {
225		'max-age': -1
226	})
227}

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.