PageSourceSearch

https://sandar.ru/bitrix/js/currency/core_currency.js?15946046463027

js sandar.ru collected 2026-10-08 09:06:15 UTC 3,027 bytes, 146 lines download raw bytes

1;(function(window) {
2
3BX.namespace('BX.Currency');
4
5if (BX.Currency.defaultFormat)
6{
7	return;
8}
9
10BX.mergeEx(BX.Currency, {
11	currencyList: [],
12	defaultFormat: {
13		'FORMAT_STRING': '#',
14		'DEC_POINT': '.',
15		'THOUSANDS_SEP': ' ',
16		'DECIMALS': 2,
17		'HIDE_ZERO': 'N'
18	},
19
20	setCurrencyFormat: function(currency, format, replace)
21	{
22		var index = this.getCurrencyIndex(currency),
23			currencyFormat = BX.clone(this.defaultFormat, true),
24			i;
25
26		replace = !!replace;
27		if (index > -1 && !replace)
28		{
29			return;
30		}
31		if (index === -1)
32		{
33			index = this.currencyList.length;
34		}
35
36		for (i in currencyFormat)
37		{
38			if (currencyFormat.hasOwnProperty(i) && typeof format[i] !== 'undefined')
39			{
40				currencyFormat[i] = format[i];
41			}
42		}
43		this.currencyList[index] = {
44			'currency': currency,
45			'format': BX.clone(currencyFormat, true)
46		};
47	},
48
49	setCurrencies: function(currencies, replace)
50	{
51		var i;
52		if (!!currencies && BX.type.isArray(currencies))
53		{
54			for (i = 0; i < currencies.length; i++)
55			{
56				if (!!currencies[i].CURRENCY && !!currencies[i].FORMAT)
57				{
58					this.setCurrencyFormat(currencies[i].CURRENCY, currencies[i].FORMAT, replace);
59				}
60			}
61		}
62	},
63
64	getCurrencyFormat: function(currency)
65	{
66		var index = this.getCurrencyIndex(currency);
67		return (index > -1 ? this.currencyList[index].format : false);
68	},
69
70	getCurrencyIndex: function(currency)
71	{
72		var i, index = -1;
73		if (this.currencyList.length === 0)
74		{
75			return index;
76		}
77		for (i = 0; i < this.currencyList.length; i++)
78		{
79			if (this.currencyList[i].currency === currency)
80			{
81				index = i;
82				break;
83			}
84		}
85		return index;
86	},
87
88	clearCurrency: function(currency)
89	{
90		var index = this.getCurrencyIndex(currency);
91		if (index > -1)
92			this.currencyList = BX.util.deleteFromArray(this.currencyList, index);
93	},
94
95	clean: function()
96	{
97		this.currencyList = [];
98	},
99
100	currencyFormat: function (price, currency, useTemplate)
101	{
102		var result = '',
103			format;
104		useTemplate = !!useTemplate;
105		format = this.getCurrencyFormat(currency);
106		if (!!format && typeof format === 'object')
107		{
108			format.CURRENT_DECIMALS = format.DECIMALS;
109			if (format.HIDE_ZERO === 'Y' && price == parseInt(price, 10))
110				format.CURRENT_DECIMALS = 0;
111
112			result = BX.util.number_format(price, format.CURRENT_DECIMALS, format.DEC_POINT, format.THOUSANDS_SEP);
113			if (useTemplate)
114				result = format.FORMAT_STRING.replace(/(^|[^&])#/, '$1' + result);
115		}
116		return result;
117	},
118
119	loadCurrencyFormat: function (currency)
120	{
121		return new Promise(function (resolve, reject)
122		{
123			var index = this.getCurrencyIndex(currency);
124			if(index > -1)
125			{
126				resolve(this.currencyList[index].format);
127			}
128			else
129			{
130				BX.ajax.runAction("currency.format.get", {data: {currencyId: currency}}).then(
131					function(response)
132					{
133						var format = response.data;
134						this.setCurrencyFormat(currency, format);
135						resolve(format);
136					}.bind(this)
137				).catch(function(response)
138				{
139					reject(response.errors);
140				})
141			}
142		}.bind(this))
143	}
144});
145
146})(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.