PageSourceSearch

https://www.onetwotrip.com/landings/js/cookie-policy.js

js onetwotrip.com collected 2026-10-01 11:41:42 UTC 10,523 bytes, 269 lines download raw bytes

1/**
2 * Created by vlad on 16/03/16.
3 */
4
5var cookiePolicyIsInitialized = false;
6(function (root, factory) {
7	if (typeof module === 'object' && module.exports) {
8		module.exports = factory();
9	} else {
10		root.showCookiePolicyAlert = factory();
11	}
12})(window, factory);
13
14function factory() {
15	return function showCookiePolicyAlert() {
16		var urlParams = typeof getUrlVars !== 'undefined' && getUrlVars();
17		if (urlParams && urlParams.view === 'app') {
18			return;
19		}
20
21		function createCss() {
22			var style = document.createElement('style');
23			style.textContent = '.ottCookiePolicyAlert{display:-ms-flexbox;display:flex;-ms-flex-line-pack:center;align-content:center;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;box-sizing:border-box;width:100%;padding:8px 16px;background:#212121;color:#fff;border-radius:8px 8px 0 0;line-height:16px;font-size:12px;font-weight:400;font-family:Roboto,Arial,sans-serif;position:fixed;left:0;bottom:0;z-index:99;transition:transform 1s ease,opacity 1s ease;transform:translateY(100%);opacity:0}.ottCookiePolicyAlert--active{transition:transform .5s ease,opacity .5s ease;transform:translateY(0);opacity:1}.ottCookiePolicyAlert--nonRu .ottCookiePolicyAlert__text{display:block;text-align:center}.ottCookiePolicyAlert__acceptBtn,.ottCookiePolicyAlert__declineBtn{padding:0 16px}.ottCookiePolicyAlert__acceptBtn,.ottCookiePolicyAlert__declineBtn,.ottCookiePolicyAlert__okBtn{height:28px;font-size:12px;font-weight:500;border-radius:4px;transition:color .2s,background-color .2s;color:#fff}.ottCookiePolicyAlert__declineBtn{margin-right:8px;background-color:transparent;border:1px solid #888}.ottCookiePolicyAlert__declineBtn:hover{background-color:rgba(255,255,255,.1);border-color:#888}.ottCookiePolicyAlert__acceptBtn{margin-left:8px;background-color:rgba(255,255,255,.2)}.ottCookiePolicyAlert__acceptBtn:hover{background-color:rgba(255,255,255,.4);border-color:transparent}.ottCookiePolicyAlert__okBtn{flex-shrink:0;height:16px;padding:0 8px;margin-left:32px;background-color:transparent;transition:color .2s;color:#fff}.ottCookiePolicyAlert__okBtn:hover{color:rgba(255,255,255,.5)}.ottCookiePolicyAlert__buttonsContainer{flex-shrink:0;margin-left:32px}.ottCookiePolicyAlert__moreLink{color:#888;text-decoration:none}.ottCookiePolicyAlert__moreLink:hover{color:#fff;transition:color .2s}@media screen and (max-width:767px){.ottCookiePolicyAlert{-webkit-box-pack:justify;-moz-box-pack:justify;-ms-flex-pack:justify;-webkit-justify-content:space-between;justify-content:space-between}.ottCookiePolicyAlert--nonRu{display:block}.ottCookiePolicyAlert__buttonsContainer{padding-top:16px;margin-left:0}.ottCookiePolicyAlert__acceptBtn,.ottCookiePolicyAlert__declineBtn{width:calc(50% - 8px)}}';
24			document.head.appendChild(style);
25		}
26
27		var cookies = {
28			getCookie: function (name) {
29				var matches = document.cookie.match(new RegExp(
30					'(?:^|; )' + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)'
31				));
32				return matches ? decodeURIComponent(matches[1]) : undefined;
33			},
34			setCookie: function (options) {
35				if (!options || options.name == null || options.value == null) {
36					return;
37				}
38				var str = options.name + '=' + encodeURIComponent(options.value);
39				if (options.days) {
40					var date = new Date();
41					date.setTime(date.getTime() + (options.days * 24 * 60 * 60 * 1000));
42					str += '; expires=' + date.toGMTString();
43				}
44
45				str = str + ';path=' + (options.path || '/');
46
47				if (!options.domain && window.location.hostname.indexOf(".onetwotrip.com") > -1) {
48					options.domain = ".onetwotrip.com";
49				}
50				if (options.domain) {
51					str += ';domain=' + options.domain;
52				}
53				if (options.secure) {
54					str += ';secure';
55				}
56				document.cookie = str;
57				if (options.xdm && window.location.hostname.indexOf(".onetwotrip.com") == -1) {
58					this.setPMCookie(options);
59				}
60			},
61			deleteCookie: function (options) {
62				if (!options || !options.name) {
63					return;
64				}
65				if (!options.domain && window.location.hostname.indexOf(".onetwotrip.com") > -1) {
66					options.domain = ".onetwotrip.com";
67				}
68
69				var str = [
70					options.name, "=",
71					";expires=Thu, 01-Jan-1970 00:00:01 GMT",
72					';path=', options.path || '/'
73				].join('');
74
75				if (options.domain) {
76					str += ';domain=' + options.domain;
77				}
78				document.cookie = str;
79			},
80			setPMCookie: function (options) {
81				iframe = document.getElementById('pm');
82				if (!iframe) return;
83				iframe.contentWindow.postMessage({
84					type: 'cookie',
85					options: options
86				}, iframe.src);
87			}
88		};
89
90		var isRuTextLocale = tw.language === 'ru' || tw.language === 'ru-kz';
91
92		function template(data, url) {
93			var buttonsTemplate;
94			if (isRuTextLocale) {
95				buttonsTemplate = '<button class="ottCookiePolicyAlert__okBtn ottCookiePolicyAlert__resolveCookieBtn" id="accept-cookie" type="button">' + data.btnText + '</button>';
96			} else {
97				buttonsTemplate = '<div class="ottCookiePolicyAlert__buttonsContainer">' +
98					'<button class="ottCookiePolicyAlert__declineBtn ottCookiePolicyAlert__resolveCookieBtn" id="adecline-cookie" type="button">' + data.btnDisagreeText + '</button>' +
99					'<button class="ottCookiePolicyAlert__acceptBtn ottCookiePolicyAlert__resolveCookieBtn" id="accept-cookie" type="button">' + data.btnAgreeText + '</button>' +
100					'</div>';
101			}
102
103			return '<div class="ottCookiePolicyAlert' + (isRuTextLocale ? '' : ' ottCookiePolicyAlert--nonRu') +
104				'" id="cookie-policy-alert">
104' +
105				'<span class="ottCookiePolicyAlert__text">' + data.text.replace('{cookieLink}', data.policyUrl) +
106				'</span>' +
107				buttonsTemplate +
108				'</div>';
109		}
110
111		function showCookieAlert() {
112			var locales = {
113				'en-gb': true,
114				'en-us': true,
115				'en-ie': true,
116				'ru': true,
117				'ru-kz': true,
118				'ru-ua': true,
119				'es': true,
120				'de': true,
121				'uk-ua': true,
122				'pl': true,
123			};
124			var cookieAppearDelay = 2000;
125			var cookieDisappearDelay = 1000;
126			var scrollThreshold = 20;
127
128			if (!locales[tw.language]) {
129				return false;
130			}
131
132			createCss();
133			document.body.insertAdjacentHTML('afterbegin', template(l10n.cookiePolicy));
134
135			var acceptBtns = document.querySelectorAll('.ottCookiePolicyAlert__resolveCookieBtn');
136			var cookieAlertBlock = document.getElementById('cookie-policy-alert');
137
138			// Display cookie policy in 2 sec after page load
139			setTimeout(function () {
140				cookieAlertBlock.classList.add('ottCookiePolicyAlert--active');
141			}, cookieAppearDelay);
142
143			Array.prototype.forEach.call(acceptBtns, function (acceptButtonNode) {
144				acceptButtonNode.addEventListener('click', handleCookiePolicyButtonClick, false);
145			});
146
147			if (isRuTextLocale) {
148				window.addEventListener('scroll', handleWindowScroll);
149				document.body.addEventListener('click', handleDocumentClick);
150			}
151
152			function handleCookiePolicyButtonClick() {
153				acceptCookiePolicy();
154			}
155
156			function acceptCookiePolicy(forceHide) {
157				cookies.setCookie({
158					name: 'cookiePolicyHasAccepted',
159					value: true,
160					days: 365
161				});
162
163				cookies.deleteCookie({name: 'cookiePolicyBannerLastPage'});
164				cookieAlertBlock.classList.remove('ottCookiePolicyAlert--active');
165
166				// Remove cookie element after disappear delay or immidiately
167				setTimeout(function () {
168					removeCookiePolicyNode();
169				}, forceHide ? 0 :cookieDisappearDelay);
170			}
171
172			function checkNode(node, nodeCheckDelegate, checkCount) {
173				checkCount = checkCount === undefined ? 2 : checkCount;
174				if (!checkCount || !node) {
175					return false;
176				} else if (nodeCheckDelegate(node)) {
177					return true;
178				}
179
180				return checkNode(node.parentNode, nodeCheckDelegate, --checkCount);
181			}
182
183			function removeCookiePolicyNode() {
184				if (cookieAlertBlock && cookieAlertBlock.parentNode) {
185					window.removeEventListener('scroll', handleWindowScroll);
186					document.body.removeEventListener('click', handleDocumentClick);
187					cookieAlertBlock.parentNode.removeChild(cookieAlertBlock);
188				}
189			}
190
191			var prevYOffset = window.pageYOffset;
192			var deltaYOffset = 0;
193			function handleWindowScroll() {
194				var delta = window.pageYOffset - prevYOffset;
195				deltaYOffset += delta;
196				if (Math.abs(deltaYOffset) > scrollThreshold) {
197					acceptCookiePolicy(true);
198				}
199			}
200
201			var policyLocatorValue = 'policy-link';
202			function handleDocumentClick(event) {
203				var interactiveElementsTagNames = ['button', 'input', 'textarea', 'a'];
204				var targetIsInteractiveElement = checkNode(event.target, function(node) {
205					var nodeTagName = node.tagName.toLowerCase();
206					return interactiveElementsTagNames.indexOf(nodeTagName) >= 0;
207				});
208
209
210				if (targetIsInteractiveElement &&
211					event.target.getAttribute('data-locator') !== policyLocatorValue) {
212
213					acceptCookiePolicy();
214				}
215			}
216
217			cookiePolicyIsInitialized = true;
218		}
219
220
221
222		var cookieHasAccepted = cookies.getCookie('cookiePolicyHasAccepted');
223		var isNativeApp = ~location.search.indexOf('view=app');
224
225		// если нет куки о согласии использовании кук
226		if (!cookieHasAccepted && !isNativeApp) {
227			var LOCALE_PATH = tw.language + '/';
228			var currentLocation = window.location.pathname.replace(LOCALE_PATH, '');
229
230			// проверяем куку lastPageCookie, которая выставляется при переходе на любую страницу сайта
231			var lastPageCookie = cookies.getCookie('cookiePolicyBannerLastPage');
232
233			/**
234			 * Если кука отличается от текущего адреса баннер не показываем,
235			 * удаляем куку и ставим cookiePolicyHasAccepted в true
236			 */
237			if (lastPageCookie && lastPageCookie !== currentLocation) {
238				cookies.deleteCookie({name: 'cookiePolicyBannerLastPage'});
239				cookies.setCookie({
240					name: 'cookiePolicyHasAccepted',
241					value: true,
242					days: 1
243				});
244			} else {
245				//   показываем баннер и создаем куку с текущим адресом
246				showCookieAlert();
247				cookies.setCookie({
248					name: 'cookiePolicyBannerLastPage',
249					value: currentLocation,
250					days: 30
251				});
252			}
253		}
254	}
255}
256
257function initializeCookiePolicy() {
258	if (!cookiePolicyIsInitialized) {
259		try {
260			window.showCookiePolicyAlert();
261		} catch (error) {
262			console.warn('Cookie Policy error:', error);
263		}
264	}
265}
266
267// Sometimes DOMContentLoaded fires faster thus there are 2 handlers
268window.addEventListener('load', initializeCookiePolicy);
269document.addEventListener('DOMContentLoaded', initializeCookiePolicy);

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.