PageSourceSearch

https://www.bitrix24.uk/local/components/sb/gdpr.manager.bitrix24/templates/.default/base.js

js bitrix24.uk collected 2026-09-30 10:00:11 UTC 6,660 bytes, 339 lines download raw bytes

1;(function() {
2	'use strict';
3
4	const Util = {
5		_window: window,
6		namespace: function(namespace) {
7			let parts = namespace.split('.');
8			let parent = this._window.BX;
9
10			if (typeof parent === 'undefined')
11			{
12				parent = {};
13			}
14
15			if (parts[0] === 'BX')
16			{
17				parts = parts.slice(1);
18			}
19
20			for (let i = 0; i < parts.length; i += 1)
21			{
22				if (typeof parent[parts[i]] === 'undefined')
23				{
24					parent[parts[i]] = {};
25				}
26
27				parent = parent[parts[i]];
28			}
29
30			return parent;
31		},
32		isEmptyObject: function(value) {
33			return !!value && typeof value === 'object' && Object.keys(value).length === 0
34		},
35		isEmptyString: function(value) {
36			return typeof value === 'string' && value.length === 0;
37		},
38		isElementNode: function(value) {
39			return !!value && value.nodeType === Node.ELEMENT_NODE;
40		},
41	};
42
43	function Manager()
44	{
45		this.manager = Util.namespace('SB.Util.Gdpr.Cookie.Manager');
46
47		this.attributes = {
48			script: 'data-bx-cookie-policy-template',
49			initialized: 'data-bx-cookie-policy-initialized',
50			section: 'data-bx-cookie-policy-section',
51			sectionType: 'data-bx-cookie-policy-section-type',
52		};
53
54		this.events = {
55			cookieManagerInitialized: 'BX.SB.Util.Gdpr.Cookie.Manager:onInitialized',
56			cookieManagerCloseCookieSettings: 'BX.SB.Util.Gdpr.Cookie.Manager.Popup:closeCookieSettings',
57		};
58
59		if (this.manager.isInitialized)
60		{
61			this.run();
62		}
63		else
64		{
65			document.addEventListener(this.events.cookieManagerInitialized, this.run.bind(this));
66		}
67	}
68
69	Manager.prototype = {
70		run: function() {
71			if (typeof this.manager._window === 'undefined')
72			{
73				return;
74			}
75
76			Array.prototype.slice
77			.call(document.querySelectorAll('[' + this.attributes.section + ']:not([' + this.attributes.initialized + '])'))
78			.forEach(
79				(section) => {
80					if (section.hasAttribute(this.attributes.initialized))
81					{
82						return;
83					}
84
85					section.setAttribute(this.attributes.initialized, 'true');
86
87					if (!section.hasAttribute(this.attributes.sectionType))
88					{
89						return;
90					}
91
92					const type = section.getAttribute(this.attributes.sectionType);
93
94					switch (type)
95					{
96						case 'popup':
97							new Popup({
98								node: section,
99								name: 'cookie_policy_site_redirect',
100								base: this,
101							});
102							break;
103
104						case 'slidebar':
105							new Popup({
106								node: section,
107								name: 'cookie_policy_slidebar',
108								base: this,
109							});
110							break;
111
112						case 'popupsettings':
113							new Popup({
114								node: section,
115								name: 'cookie_policy_popupsettings',
116								base: this,
117								disableCookieStorage: true,
118								autoLoad: false,
119								eventClasses: {
120									loadClass: 'js-show-gdpr-settings'
121								},
122							});
123							break;
124					}
125
126					section.removeAttribute('style');
127				}
128			);
129		}
130	};
131
132	function Popup(settings)
133	{
134		this.localStorage = Util.namespace('BX.localStorage');
135
136		this.base = settings.base || {};
137
138		if (Util.isEmptyObject(this.base))
139		{
140			return;
141		}
142
143		this.manager = this.base.manager || {};
144
145		if (Util.isEmptyObject(this.manager))
146		{
147			return;
148		}
149
150		this.attributes = {
151			shown: 'shown',
152			close: 'data-bx-cookie-policy-section-close',
153		};
154
155		this.settings = Object.assign(
156			{},
157			{
158				node: null,
159				name: null,
160				base: null,
161				disableCookieStorage: false,
162				autoLoad: true,
163				eventClasses: {
164					loadClass: '',
165				},
166			},
167			settings
168		);
169
170		if (!this.settings.disableCookieStorage)
171		{
172			if (Util.isEmptyString(this.settings.name || ''))
173			{
174				return;
175			}
176
177			this.settings.name = this.settings.name.toString();
178		}
179
180		if (!Util.isElementNode(this.settings.node))
181		{
182			return;
183		}
184
185		const waitingStorage = () => {
186			const storage = Util.namespace('BX.localStorage');
187			const timeout = 30000;
188
189			return (new Promise((resolve, reject) => {
190				const check = () => {
191					if (!(storage && typeof storage.get === 'function'))
192					{
193						return;
194					}
195
196					clearInterval(interval);
197
198					resolve(storage);
199				};
200
201				const interval = setInterval(check, 100);
202
203				check();
204
205				if (!timeout)
206				{
207					return;
208				}
209
210				setTimeout(
211					() => {
212						clearInterval(interval);
213						reject(false);
214					},
215					timeout
216				);
217			}));
218		};
219
220		(async function($this) {
221			if (await waitingStorage())
222			{
223				const storage = Util.namespace('BX.localStorage');
224
225				if ($this.settings.disableCookieStorage === false && !Util.isEmptyString(storage.get($this.settings.name) || ''))
226				{
227					return;
228				}
229
230				$this.bind();
231
232				if ($this.settings.autoLoad === true)
233				{
234					$this.show();
235				}
236			}
237		})(this);
238	}
239
240	Popup.prototype = {
241		show: function() {
242			BX.adjust(
243				this.settings.node,
244				{attrs: Object.fromEntries([[this.attributes.shown.toString(), 'true']])},
245			);
246		},
247		hide: function() {
248			if (this.settings.disableCookieStorage === false)
249			{
250				const storage = Util.namespace('BX.localStorage');
251
252				storage.set(
253					this.settings.name.toString(),
254					'Y',
255					this.manager.isExpiresAllowed() ? 30 * 24 * 60 * 60 : 0
256				);
257			}
258
259			BX.adjust(
260				this.settings.node,
261				{attrs: Object.fromEntries([[this.attributes.shown.toString(), 'false']])},
262			);
263		},
264		bind: function() {
265			Array
266			.prototype
267			.slice
268			.call(this.settings.node.querySelectorAll('[' + this.attributes.close + ']'))
269			.forEach(
270				(close) => {
271					if (Util.isElementNode(close))
272					{
273						close.addEventListener('click', this.hide.bind(this));
274					}
275				}
276			);
277
278			if (
279				this.settings.name === 'cookie_policy_popupsettings'
280				&& typeof BX === 'function'
281				&& typeof BX.addCustomEvent === 'function'
282			)
283			{
284				BX.addCustomEvent(this.base.events.cookieManagerCloseCookieSettings, this.hide.bind(this));
285			}
286
287			if (!Util.isEmptyString(this.settings.eventClasses.loadClass || ''))
288			{
289				Array
290				.prototype
291				.slice
292				.call(document.querySelectorAll('.' + this.settings.eventClasses.loadClass))
293				.forEach(
294					(element) => {
295						if (Util.isElementNode(element))
296						{
297							element.addEventListener(
298								'click',
299								(event) => {
300									event = event || window.event;
301									event.preventDefault();
302									this.show();
303								}
304							);
305						}
306					}
307				);
308			}
309		},
310	};
311
312	let Initialization = function () {
313		if (BX && typeof BX === 'function')
314		{
315			if (!BX.Type.isUndefined(window.frameCacheVars))
316			{
317				BX.Event.EventEmitter.subscribe('onFrameDataReceived', () => {
318					this.launch();
319				});
320			}
321		}
322
323		window.addEventListener(
324			'DOMContentLoaded',
325			() => {
326				this.launch();
327			},
328			false
329		);
330	};
331
332	Initialization.prototype = {
333		launch: function() {
334			new Manager();
335		},
336	};
337
338	new Initialization();
339})();

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.