1/* eslint-disable */ 2this.O2k = this.O2k || {}; 3(function (exports) { 4 'use strict'; 5 6 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } 7 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } 8 /** 9 * Тип опÑий Ð´Ð»Ñ Ð½Ð°ÑÑÑойки CookieManager. 10 */ 11 12 /** 13 * ÐлаÑÑ CookieModal â ÑпÑавление модалÑнÑм окном Ð´Ð»Ñ ÑоглаÑÐ¸Ñ Ñ Ð¸ÑполÑзованием cookies. 14 * Реализован как Singleton (единÑÑвеннÑй ÑкземплÑÑ). 15 */ 16 var CookieModal = /*#__PURE__*/function () { 17 // СелекÑоÑÑ Ð¿Ð¾ ÑмолÑÐ°Ð½Ð¸Ñ 18 19 // CSS-клаÑÑÑ ÑоÑÑоÑÐ½Ð¸Ñ 20 21 /** 22 * ÐонÑÑÑÑкÑÐ¾Ñ ÐºÐ»Ð°ÑÑа 23 * @param {HTMLElement} target â Ñелевой ÑÐ»ÐµÐ¼ÐµÐ½Ñ (конÑÐµÐ¹Ð½ÐµÑ Ð¼Ð¾Ð´Ð°Ð»Ñного окна) 24 * @param {CookieModalConfig} options â опÑии Ð´Ð»Ñ Ð¿ÐµÑеопÑÐµÐ´ÐµÐ»ÐµÐ½Ð¸Ñ ÑелекÑоÑов и клаÑÑов 25 */ 26 function CookieModal(target) { 27 var _this = this; 28 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 29 babelHelpers.classCallCheck(this, CookieModal); 30 babelHelpers.defineProperty(this, "isApply", false); 31 babelHelpers.defineProperty(this, "onCloseAction", false); 32 babelHelpers.defineProperty(this, "selectors", { 33 applyButton: '.js-cookie-apply', 34 applyAllButton: '.js-cookie-apply-all', 35 closeButton: '.js-cookie-close', 36 settingsButton: '.js-cookie-settings', 37 mainContainer: '.cookie__main', 38 settingsContainer: '.cookie__settings' 39 }); 40 babelHelpers.defineProperty(this, "stateClasses", { 41 activeCookie: 'cookie--active', 42 hiddenContainer: 'cookie__container--hidden' 43 }); 44 babelHelpers.defineProperty(this, "close", function () { 45 if (!_this.isApply && _this.onCloseAction !== false) { 46 var _this$settingsContain; 47 var settings = {}; 48 (_this$settingsContain = _this.settingsContainer) === null || _this$settingsContain === void 0 ? void 0 : _this$settingsContain.querySelectorAll('input[type="checkbox"]').forEach(function (el) { 49 if (_this.onCloseAction === 'apply' || _this.onCloseAction === 'refuse') { 50 if (_this.onCloseAction === 'refuse') { 51 settings[el.name] = !!el.disabled; 52 } else { 53 settings[el.name] = true; 54 } 55 _this.isApply = true; 56 _this.target.dispatchEvent(new CustomEvent('apply', { 57 detail: { 58 settings: settings 59 } 60 })); 61 } 62 }); 63 } 64 _this.target.classList.remove(_this.stateClasses.activeCookie); 65 }); 66 if (CookieModal._instance) { 67 console.warn('Class CookieModal â is singleton, instance already exists'); 68 return CookieModal._instance; 69 } 70 CookieModal._instance = this; 71 if (options.selectors) { 72 this.selectors = _objectSpread(_objectSpread({}, this.selectors), options.selectors); 73 } 74 if (options.stateClasses) { 75 this.stateClasses = _objectSpread(_objectSpread({}, this.stateClasses), options.stateClasses); 76 } 77 if (options.onCloseAction) { 78 this.onCloseAction = options.onCloseAction; 79 } 80 this.target = target; 81 this.applyButton = this.target.querySelector(this.selectors.applyButton); 82 this.applyAllButton = this.target.querySelector(this.selectors.applyAllButton); 83 this.closeButtons = this.target.querySelectorAll(this.selectors.closeButton); 84 this.settingsButton = this.target.querySelector(this.selectors.settingsButton); 85 this.mainContainer = this.target.querySelector(this.selectors.mainContainer); 86 this.settingsContainer = this.target.querySelector(this.selectors.settingsContainer); 87 this.bindEvents(); 88 } 89 90 /** 91 * ÐÑкÑÑÐ²Ð°ÐµÑ Ð¼Ð¾Ð´Ð°Ð»Ñное окно cookie 92 */ 93 babelHelpers.createClass(CookieModal, [{ 94 key: "open", 95 value: function open() { 96 this.target.classList.add(this.stateClasses.activeCookie); 97 this.showMain(); 98 } 99 /** 100 * ÐакÑÑÐ²Ð°ÐµÑ Ð¼Ð¾Ð´Ð°Ð»Ñное окно cookie 101 */ 102 }, { 103 key: "showMain", 104 /** 105 * ÐоказÑÐ²Ð°ÐµÑ Ð¾Ñновной ÑкÑан (Ñ ÐºÑаÑким ÑообÑением и кнопками) 106 */ 107 value: function showMain() { 108 if (this.mainContainer) this.mainContainer.classList.remove(this.stateClasses.hiddenContainer); 109 if (this.settingsContainer) this.settingsContainer.classList.add(this.stateClasses.hiddenContainer); 110 } 111 /** 112 * ÐÑименÑÐµÑ Ð²ÑбÑаннÑе наÑÑÑойки cookie 113 * @param {boolean} all â еÑли true, пÑименÑÑÑÑÑ Ð²Ñе наÑÑÑойки (вÑе ÑекбокÑÑ = true) 114 */ 115 }, { 116 key: "applySettings", 117 value: function applySettings() { 118 var _this$settingsContain2; 119 var all = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
120 var settings = {}; 121 (_this$settingsContain2 = this.settingsContainer) === null || _this$settingsContain2 === void 0 ? void 0 : _this$settingsContain2.querySelectorAll('input[type="checkbox"]').forEach(function (el) { 122 if (all) settings[el.name] = true;else settings[el.name] = el.checked; 123 }); 124 125 // ÐенеÑаÑÐ¸Ñ ÑобÑÑÐ¸Ñ Ñ Ð´Ð°Ð½Ð½Ñми о наÑÑÑÐ¾Ð¹ÐºÐ°Ñ 126 this.target.dispatchEvent(new CustomEvent('apply', { 127 detail: { 128 settings: settings 129 } 130 })); 131 this.isApply = true; 132 this.close(); 133 } 134 /** 135 * ÐоказÑÐ²Ð°ÐµÑ ÑкÑан Ñ Ð½Ð°ÑÑÑойками cookie 136 */ 137 }, { 138 key: "showSettings", 139 value: function showSettings() { 140 if (this.mainContainer) this.mainContainer.classList.add(this.stateClasses.hiddenContainer); 141 if (this.settingsContainer) this.settingsContainer.classList.remove(this.stateClasses.hiddenContainer); 142 } 143 /** 144 * ÐазнаÑÐ°ÐµÑ Ð¾Ð±ÑабоÑÑики ÑобÑÑий на кнопки 145 */ 146 }, { 147 key: "bindEvents", 148 value: function bindEvents() { 149 var _this2 = this, 150 _this$settingsButton, 151 _this$applyButton, 152 _this$applyAllButton; 153 this.closeButtons.length > 0 && this.closeButtons.forEach(function (button) { 154 return button.addEventListener('click', _this2.close); 155 }); 156 (_this$settingsButton = this.settingsButton) === null || _this$settingsButton === void 0 ? void 0 : _this$settingsButton.addEventListener('click', function () { 157 return _this2.showSettings(); 158 }); 159 (_this$applyButton = this.applyButton) === null || _this$applyButton === void 0 ? void 0 : _this$applyButton.addEventListener('click', function () { 160 return _this2.applySettings(); 161 }); 162 (_this$applyAllButton = this.applyAllButton) === null || _this$applyAllButton === void 0 ? void 0 : _this$applyAllButton.addEventListener('click', function () { 163 return _this2.applySettings(true); 164 }); 165 } 166 }]); 167 return CookieModal; 168 }(); 169 170 function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } 171 function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } 172 /** 173 * ÐлаÑÑ Ð´Ð»Ñ Ð¼Ð¾Ð½Ð¸ÑоÑинга изменений cookie в бÑаÑзеÑе. 174 * ÐоддеÑÐ¶Ð¸Ð²Ð°ÐµÑ ÑовÑеменнÑй API `cookieStore` (в безопаÑном конÑекÑÑе) и ÑезеÑвнÑй Ñежим опÑоÑа. 175 */ 176 var CookieMonitor = /*#__PURE__*/function () { 177 /** 178 * Ð¡Ð¾Ð·Ð´Ð°ÐµÑ ÑкземплÑÑ CookieMonitor. 179 * 180 * @param {Object} config - ÐонÑигÑÑаÑÐ¸Ñ Ð¼Ð¾Ð½Ð¸ÑоÑинга. 181 * @param {number}
181 [config.checkInterval=1000] - ÐнÑеÑвал пÑовеÑки cookie в миллиÑекÑÐ½Ð´Ð°Ñ (Ð´Ð»Ñ ÑезеÑвного Ñежима). 182 * @param {boolean} [config.useModernAPI=true] - ÐÑполÑзоваÑÑ Ð»Ð¸ ÑовÑеменнÑй API cookieStore, еÑли доÑÑÑпен. 183 * @param {Function} [config.onCookieChange] - ÐолбÑк, вÑзÑваемÑй пÑи изменении cookie. 184 * 185 * @example 186 * const monitor = new CookieMonitor({ 187 * checkInterval: 500, 188 * onCookieChange: (change) => console.log(change) 189 * }); 190 */ 191 function CookieMonitor() { 192 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 193 babelHelpers.classCallCheck(this, CookieMonitor); 194 this.config = _objectSpread$1({ 195 checkInterval: 1000, 196 useModernAPI: true, 197 onCookieChange: function onCookieChange() {} 198 }, config); 199 this.knownCookies = new Set(this.getAllCookieNames()); 200 this.checkInterval = null; 201 this.cookieStoreHandler = null; 202 this.isModernAPIAvailable = window.isSecureContext && typeof window.cookieStore !== 'undefined'; 203 } 204 205 /** 206 * ÐапÑÑÐºÐ°ÐµÑ Ð¼Ð¾Ð½Ð¸ÑоÑинг изменений cookie. 207 * ÐвÑомаÑиÑеÑки вÑбиÑÐ°ÐµÑ Ð¼ÐµÐ¶Ð´Ñ ÑовÑеменнÑм API и ÑезеÑвнÑм Ñежимом. 208 */ 209 babelHelpers.createClass(CookieMonitor, [{ 210 key: "startMonitoring", 211 value: function startMonitoring() { 212 if (this.isModernAPIAvailable && this.config.useModernAPI) { 213 this.startModernMonitoring(); 214 } else { 215 this.startLegacyMonitoring(); 216 } 217 } 218 /** 219 * ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ ÑекÑÑий пÑоÑеÑÑ Ð¼Ð¾Ð½Ð¸ÑоÑинга. 220 */ 221 }, { 222 key: "stopMonitoring", 223 value: function stopMonitoring() { 224 if (this.isModernAPIAvailable && this.cookieStoreHandler) { 225 this.stopModernMonitoring(); 226 } else { 227 this.stopLegacyMonitoring(); 228 } 229 } 230 /** 231 * ÐапÑÑÐºÐ°ÐµÑ Ð¼Ð¾Ð½Ð¸ÑоÑинг Ñ Ð¸ÑполÑзованием ÑовÑеменного API cookieStore. 232 * @private 233 */ 234 }, { 235 key: "startModernMonitoring", 236 value: function startModernMonitoring() { 237 var _this = this; 238 if (!this.isModernAPIAvailable) return; 239 this.cookieStoreHandler = function (event) { 240 event.changed.forEach(function (_ref) { 241 var name = _ref.name; 242 var currentValue = _this.getCookieValue(name); 243 _this.config.onCookieChange({ 244 name: name, 245 value: currentValue, 246 action: 'change', 247 timestamp: new Date() 248 }); 249 _this.knownCookies.add(name); 250 }); 251 event.deleted.forEach(function (_ref2) { 252 var name = _ref2.name; 253 _this.config.onCookieChange({ 254 name: name, 255 value: null, 256 action: 'delete', 257 timestamp: new Date() 258 }); 259 _this.knownCookies["delete"](name); 260 }); 261 }; 262 window.cookieStore.addEventListener('change', this.cookieStoreHandler); 263 } 264 /** 265 * ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð¼Ð¾Ð½Ð¸ÑоÑинг ÑеÑез ÑовÑеменнÑй API. 266 * @private 267 */ 268 }, { 269 key: "stopModernMonitoring", 270 value: function stopModernMonitoring() { 271 if (this.cookieStoreHandler) { 272 window.cookieStore.removeEventListener('change', this.cookieStoreHandler); 273 this.cookieStoreHandler = null; 274 } 275 } 276 /** 277 * ÐапÑÑÐºÐ°ÐµÑ ÑезеÑвнÑй Ñежим мониÑоÑинга ÑеÑез пеÑиодиÑеÑкÑÑ Ð¿ÑовеÑÐºÑ document.cookie. 278 * @private 279 */ 280 }, { 281 key: "startLegacyMonitoring", 282 value: function startLegacyMonitoring() { 283 var _this2 = this; 284 this.checkInterval = setInterval(function () { 285 _this2.checkCookieChanges(); 286 }, this.config.checkInterval); 287 } 288 /** 289 * ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ ÑезеÑвнÑй Ñежим мониÑоÑинга. 290 * @private 291 */ 292 }, { 293 key: "stopLegacyMonitoring", 294 value: function stopLegacyMonitoring() { 295 if (this.checkInterval) { 296 clearInterval(this.checkInterval); 297 this.checkInterval = null; 298 } 299 } 300 /** 301 * ÐÑовеÑÑÐµÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ cookie в ÑезеÑвном Ñежиме. 302 * ÐÑзÑÐ²Ð°ÐµÑ ÐºÐ¾Ð»Ð±Ñк Ð´Ð»Ñ Ð½Ð¾Ð²ÑÑ Ð¸ ÑдалÑннÑÑ cookie. 303 * @private 304 */ 305 }, { 306 key: "checkCookieChanges", 307 value: function checkCookieChanges() { 308 var _this3 = this; 309 var currentCookies = this.getAllCookieNames(); 310 var newCookies = currentCookies.filter(function (name) { 311 return !_this3.knownCookies.has(name); 312 }); 313 var deletedCookies = Array.from(this.knownCookies).filter(function (name) { 314 return !currentCookies.includes(name); 315 });
316 newCookies.forEach(function (cookieName) { 317 var value = _this3.getCookieValue(cookieName); 318 _this3.knownCookies.add(cookieName); 319 _this3.config.onCookieChange({ 320 name: cookieName, 321 value: value, 322 action: 'change', 323 timestamp: new Date() 324 }); 325 }); 326 deletedCookies.forEach(function (cookieName) { 327 _this3.knownCookies["delete"](cookieName); 328 _this3.config.onCookieChange({ 329 name: cookieName, 330 value: null, 331 action: 'delete', 332 timestamp: new Date() 333 }); 334 }); 335 } 336 /** 337 * ÐозвÑаÑÐ°ÐµÑ ÑпиÑок имÑн вÑÐµÑ Ð´Ð¾ÑÑÑпнÑÑ cookie. 338 * @returns {string[]} ÐаÑÑив имÑн cookie. 339 */ 340 }, { 341 key: "getAllCookieNames", 342 value: function getAllCookieNames() { 343 return document.cookie.split('; ').map(function (cookie) { 344 return cookie.split('=')[0]; 345 }).filter(Boolean); 346 } 347 /** 348 * ÐолÑÑÐ°ÐµÑ Ð·Ð½Ð°Ñение cookie по имени. 349 * ÐÑполÑзÑÐµÑ BX.getCookie, еÑли доÑÑÑпен, инаÑе паÑÑÐ¸Ñ document.cookie. 350 * 351 * @param {string} name - ÐÐ¼Ñ cookie. 352 * @returns {string|null} ÐнаÑение cookie или null, еÑли не найдено. 353 */ 354 }, { 355 key: "getCookieValue", 356 value: function getCookieValue(name) { 357 if (typeof window.BX !== 'undefined' && window.BX.getCookie) { 358 return window.BX.getCookie(name); 359 } 360 var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); 361 return match ? decodeURIComponent(match[2]) : null; 362 } 363 /** 364 * ÐозвÑаÑÐ°ÐµÑ Ð²Ñе cookie в виде обÑекÑа. 365 * @returns {Object} ÐбÑÐµÐºÑ Ñ Ð¿Ð°Ñами имÑ-знаÑение вÑÐµÑ cookie. 366 */ 367 }, { 368 key: "getAllCookies", 369 value: function getAllCookies() { 370 var cookies = {}; 371 document.cookie.split('; ').forEach(function (cookie) { 372 var _cookie$split = cookie.split('='), 373 _cookie$split2 = babelHelpers.slicedToArray(_cookie$split, 2), 374 name = _cookie$split2[0], 375 value = _cookie$split2[1]; 376 if (name) { 377 cookies[name] = decodeURIComponent(value); 378 } 379 }); 380 return cookies; 381 } 382 /** 383 * ÐÑовеÑÑеÑ, поддеÑживаеÑÑÑ Ð»Ð¸ мониÑоÑинг в ÑекÑÑем окÑÑжении. 384 * @returns {boolean} true, еÑли доÑÑÑпен Ñ Ð¾ÑÑ Ð±Ñ Ð¾Ð´Ð¸Ð½ меÑод (ÑовÑеменнÑй или ÑезеÑвнÑй). 385 */ 386 }, { 387 key: "isSupported", 388 value: function isSupported() { 389 return this.isModernAPIAvailable || true; 390 } 391 /** 392 * ÐозвÑаÑÐ°ÐµÑ ÑекÑÑий Ñежим мониÑоÑинга. 393 * @returns {'modern'|'legacy'} ТекÑÑий Ñежим. 394 */ 395 }, { 396 key: "getMode", 397 value: function getMode() { 398 return this.isModernAPIAvailable && this.config.useModernAPI ? 'modern' : 'legacy'; 399 } 400 /** 401 * ÐбновлÑÐµÑ ÐºÐ¾Ð½ÑигÑÑаÑÐ¸Ñ Ð¼Ð¾Ð½Ð¸ÑоÑинга. 402 * ÐÑи изменении инÑеÑвала или Ñежима пеÑезапÑÑÐºÐ°ÐµÑ Ð¼Ð¾Ð½Ð¸ÑоÑинг. 403 * 404 * @param {Object} newConfig - ÐовÑе паÑамеÑÑÑ ÐºÐ¾Ð½ÑигÑÑаÑии. 405 */ 406 }, { 407 key: "updateConfig", 408 value: function updateConfig(newConfig) { 409 this.config = _objectSpread$1(_objectSpread$1({}, this.config), newConfig); 410 if (newConfig.checkInterval || newConfig.useModernAPI !== undefined) { 411 var wasRunning = this.checkInterval || this.cookieStoreHandler; 412 if (wasRunning) { 413 this.stopMonitoring(); 414 this.startMonitoring(); 415 } 416 } 417 } 418 /** 419 * ÐолноÑÑÑÑ Ð¾ÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð¼Ð¾Ð½Ð¸ÑоÑинг и оÑиÑÐ°ÐµÑ Ð²Ð½ÑÑÑеннее ÑоÑÑоÑние. 420 */ 421 }, { 422 key: "destroy", 423 value: function destroy() { 424 this.stopMonitoring(); 425 this.knownCookies.clear(); 426 } 427 }]); 428 return CookieMonitor; 429 }(); 430 431 function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } 432 function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {};
432 i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } 433 /** 434 * ÐлаÑÑ Ð´Ð»Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¸ мониÑоÑинга cookies на ÑайÑе. 435 * 436 * @class CookieManager 437 * @description 438 * УпÑавлÑÐµÑ ÑоÑÑоÑнием cookie-Ñайлов, оÑÑÐ»ÐµÐ¶Ð¸Ð²Ð°ÐµÑ Ð¸Ñ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ, 439 * блокиÑÑÐµÑ Ð½ÐµÐ¶ÐµÐ»Ð°ÑелÑнÑе cookie в ÑооÑвеÑÑÑвии Ñ Ð½Ð°ÑÑÑойками полÑзоваÑелÑ. 440 * 441 * @param {CookieManagerConfig} config - ÐонÑигÑÑаÑÐ¸Ñ Ð¼ÐµÐ½ÐµÐ´Ð¶ÐµÑа cookie. 442 * @param {string} [config.userCookieName='user_cookies'] - ÐÐ¼Ñ cookie, Ñ ÑанÑÑего наÑÑÑойки полÑзоваÑелÑ. 443 * @param {string} [config.cookiePrefix='cookie_type-'] - ÐÑеÑÐ¸ÐºÑ Ð´Ð»Ñ ÐºÐ»ÑÑей Ñипов cookie в наÑÑÑÐ¾Ð¹ÐºÐ°Ñ . 444 * @param {number} [config.checkInterval=2000] - ÐнÑеÑвал пÑовеÑки изменений cookie (в миллиÑекÑÐ½Ð´Ð°Ñ ). 445 * @param {number} [config.cookieExpires=31536000] - СÑок дейÑÑÐ²Ð¸Ñ cookie в ÑекÑÐ½Ð´Ð°Ñ (по ÑмолÑÐ°Ð½Ð¸Ñ â 1 год). 446 * @param {Object} [config.cookieTypes={}] - ÐбÑÐµÐºÑ Ñ Ð¾Ð¿Ð¸Ñанием Ñипов cookie и ÑпиÑками ÑвÑзаннÑÑ Ð¸Ð¼Ñн. 447 * @param {Object} [config.removeSubdomainCookies=false] - УдалÑÑÑ Ð»Ð¸ кÑки Ñо вÑÐµÑ Ð¿Ð¾Ð´Ð´Ð¾Ð¼ÐµÐ½Ð¾Ð²? ÐапÑ. new.cookie.example.com -> .cookie.example.com -> .example.ru (по ÑмолÑÐ°Ð½Ð¸Ñ - false). 448 * @param {Function} [config.onAbsentCookie] - ÐолбÑк, вÑзÑваемÑй пÑи оÑÑÑÑÑÑвии cookie Ñ Ð½Ð°ÑÑÑойками. 449 * @param {Function} [config.onBeforeInit] - ÐолбÑк, вÑзÑваемÑй пеÑед иниÑиализаÑией. 450 * 451 * @example 452 * const manager = new CookieManager({ 453 * userCookieName: 'user_preferences', 454 * cookieTypes: { 455 * 1: [{ id: 10, name: 'tracking_cookie_1' }, { id: 11, name: 'tracking_cookie_2' }], 456 * 2: [{ id: 25, name: 'ads_cookie' }] 457 * }, 458 * onAbsentCookie: () => console.log('ÐаÑÑÑойки cookie не найденÑ'), 459 * onBeforeInit: (instance) => console.log('ÐниÑиализаÑÐ¸Ñ Ð½Ð°ÑаÑа', instance) 460 * }); 461 */ 462 var CookieManager = /*#__PURE__*/function () { 463 function CookieManager() { 464 var _this = this; 465 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 466 babelHelpers.classCallCheck(this, CookieManager); 467 this.config = _objectSpread$2({ 468 userCookieName: 'user_cookies', 469 cookiePrefix: 'cookie_type-', 470 checkInterval: 2000, 471 cookieExpires: 60 * 60 * 24 * 30 * 12, 472 cookieTypes: {}, 473 removeSubdomainCookies: false, 474 debug: false, 475 onAbsentCookie: function onAbsentCookie() { 476 return _this.config.debug && console.log('onAbsentCookie Event'); 477 }, 478 onBeforeInit: function onBeforeInit() { 479 return _this.config.debug && console.log('onBeforeInit Event'); 480 } 481 }, config); 482 this.monitor = null; 483 this.needDisable = []; 484 this.init(); 485 } 486 babelHelpers.createClass(CookieManager, [{ 487 key: "init", 488 value: function init() { 489 var _this2 = this; 490 if (document.readyState === 'loading') { 491 document.addEventListener('DOMContentLoaded', function () { 492 return _this2.setup(); 493 }); 494 } else { 495 this.setup(); 496 } 497 } 498 }, { 499 key: "setup", 500 value: function setup() { 501 this.onBeforeInit(); 502 this.processInitialState(); 503 } 504 }, { 505 key: "onBeforeInit", 506 value: function onBeforeInit() { 507 if (typeof this.onBeforeInit === 'function') { 508 this.config.onBeforeInit(this); 509 } 510 } 511 }, { 512 key: "processInitialState", 513 value: function processInitialState() { 514 var settingsCookie = this.getCookie(this.config.userCookieName); 515 if (settingsCookie === undefined && typeof this.config.onAbsentCookie === 'function') { 516 this.config.onAbsentCookie(); 517 } else { 518 this.processCookies(settingsCookie); 519 } 520 } 521 }, { 522 key: "processCookies", 523 value: function processCookies(settingsCookie) { 524 try { 525 var settings = JSON.parse(settingsCookie);
526 this.needDisable = this.getCookiesToDisable(settings); 527 if (this.needDisable.length > 0) { 528 this.disableCookies(this.needDisable); 529 this.startCookieMonitoring(this.needDisable); 530 } 531 } catch (error) { 532 console.error('Error parsing cookie settings:', error); 533 } 534 } 535 }, { 536 key: "getCookiesToDisable", 537 value: function getCookiesToDisable(settings) { 538 var needDisable = []; 539 for (var type in settings) { 540 if (settings[type] === false) { 541 var typeId = parseInt(type.replace(this.config.cookiePrefix, '')); 542 var cookieType = this.config.cookieTypes[typeId]; 543 if (cookieType && Array.isArray(cookieType)) { 544 var cookies = cookieType.map(function (item) { 545 return item.name; 546 }); 547 needDisable.push.apply(needDisable, babelHelpers.toConsumableArray(cookies)); 548 } 549 } 550 } 551 return needDisable; 552 } 553 }, { 554 key: "disableCookies", 555 value: function disableCookies(cookiesToDisable) { 556 var _this3 = this; 557 cookiesToDisable.forEach(function (cookieName) { 558 _this3.removeCookie(cookieName); 559 }); 560 } 561 }, { 562 key: "startCookieMonitoring", 563 value: function startCookieMonitoring(cookiesToDisable) { 564 var _this4 = this; 565 this.stopMonitoring(); 566 this.monitor = new CookieMonitor({ 567 checkInterval: this.config.checkInterval, 568 onCookieChange: function onCookieChange(cookieData) { 569 _this4.handleCookieChange(cookieData, cookiesToDisable); 570 } 571 }); 572 this.monitor.startMonitoring(); 573 } 574 }, { 575 key: "handleCookieChange", 576 value: function handleCookieChange(cookieData, cookiesToDisable) { 577 if (cookiesToDisable.includes(cookieData.name)) { 578 if (cookieData.action === 'change') { 579 if (this.config.debug) { 580 console.log("Blocked cookie detected: ".concat(cookieData.name, ", removing...")); 581 } 582 this.removeCookie(cookieData.name); 583 } 584 } 585 } 586 }, { 587 key: "getCookie", 588 value: function getCookie(name) { 589 if (typeof window.BX !== 'undefined' && window.BX.getCookie) { 590 return window.BX.getCookie(name); 591 } 592 var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); 593 return match ? decodeURIComponent(match[2]) : undefined; 594 } 595 }, { 596 key: "setCookie", 597 value: function setCookie(name, value) { 598 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 599 if (typeof window.BX !== 'undefined' && window.BX.setCookie) { 600 window.BX.setCookie(name, value, options); 601 } else { 602 var cookieString = "".concat(name, "=").concat(encodeURIComponent(value)); 603 if (options.expires) { 604 var date = new Date(); 605 date.setTime(date.getTime() + options.expires * 1000); 606 cookieString += "; expires=".concat(date.toUTCString()); 607 } 608 if (options.path) cookieString += "; path=".concat(options.path); 609 if (options.domain) cookieString += "; domain=".concat(options.domain); 610 if (options.secure) cookieString += '; secure'; 611 if (options.samesite) cookieString += "; samesite=".concat(options.samesite); 612 document.cookie = cookieString; 613 } 614 } 615 }, { 616 key: "removeCookie", 617 value: function removeCookie(name) { 618 document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT'; 619 if (this.config.removeSubdomainCookies) { 620 this.getDomainHierarchy().forEach(function (domain) { 621 document.cookie = name + '=; domain=' + domain + '; expires=Thu, 01 Jan 1970 00:00:00 GMT'; 622 }); 623 } 624 } 625 }, { 626 key: "getDomainHierarchy", 627 value: function getDomainHierarchy() { 628 var domain = window.location.hostname; 629 var variations = []; 630 var parts = domain.split('.'); 631 if (parts.length < 2) return [domain]; 632 for (var i = 0; i <= parts.length - 2; i++) { 633 variations.push('.' + parts.slice(i).join('.')); 634 } 635 return variations; 636 } 637 }, { 638 key: "saveUserSettings", 639 value: function saveUserSettings(settings) { 640 this.setCookie(this.config.userCookieName, JSON.stringify(settings), { 641 expires: this.config.cookieExpires, 642 path: '/' 643 }); 644 } 645 }, { 646 key: "stopMonitoring", 647 value: function stopMonitoring() { 648 if (this.monitor) { 649 this.monitor.stopMonitoring(); 650 this.monitor = null; 651 } 652 } 653 }, { 654 key: "updateConfig", 655 value: function updateConfig(newConfig) { 656 this.config = _objectSpread$2(_objectSpread$2({}, this.config), newConfig); 657 } 658 }, { 659 key: "updateCookieTypes", 660 value: function updateCookieTypes(cookieTypes) { 661 this.config.cookieTypes = cookieTypes; 662 } 663 }, { 664 key: "getMonitoringMode", 665 value: function getMonitoringMode() { 666 return this.monitor ? this.monitor.getMode() : 'inactive'; 667 } 668 }, {
669 key: "destroy", 670 value: function destroy() { 671 this.stopMonitoring(); 672 } 673 }]); 674 return CookieManager; 675 }(); 676 677 function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } 678 function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } 679 /** 680 * ÐлаÑÑ Ð¿ÑÐ¸Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð´Ð»Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÐºÑками и оÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¼Ð¾Ð´Ð°Ð»Ñного окна ÑоглаÑиÑ. 681 * 682 * @class 683 */ 684 var CookieApp = /*#__PURE__*/function () { 685 /** 686 * HTML-ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¸Ð»Ð¸ ÑелекÑоÑ, кÑда бÑÐ´ÐµÑ Ð¿ÑивÑзано пÑиложение. 687 * @type {HTMLElement|null} 688 */ 689 690 /** 691 * ÐпÑии пÑÐ¸Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ Ð¿Ð¾ ÑмолÑаниÑ. 692 * @type {AppConfig} 693 */ 694 695 /** 696 * СоздаÑÑ ÑкземплÑÑ Ð¿ÑиложениÑ. 697 * 698 * @param {string|HTMLElement} target - СелекÑÐ¾Ñ Ð¸Ð»Ð¸ HTML-ÑлеменÑ, в коÑоÑом бÑÐ´ÐµÑ ÑабоÑаÑÑ Ð¿Ñиложение. 699 * @param {AppConfig} [options={}] - ÐолÑзоваÑелÑÑкие опÑии Ð´Ð»Ñ Ð½Ð°ÑÑÑойки пÑиложениÑ. 700 */ 701 function CookieApp(target) { 702 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 703 babelHelpers.classCallCheck(this, CookieApp); 704 babelHelpers.defineProperty(this, "target", null); 705 babelHelpers.defineProperty(this, "options", { 706 /** 707 * ÐонÑигÑÑаÑÐ¸Ñ Ð¼Ð¾Ð´Ð°Ð»Ñного окна. 708 * @type {CookieModalConfig} 709 */ 710 cookieModalConfig: {}, 711 /** 712 * ÐонÑигÑÑаÑÐ¸Ñ Ð¼ÐµÐ½ÐµÐ´Ð¶ÐµÑа кÑк. 713 * @type {CookieManagerConfig} 714 */ 715 cookieManagerConfig: {} 716 }); 717 this.target = BX.Type.isString(target) ? document.querySelector(target) : target; 718 this.options = _objectSpread$3(_objectSpread$3({}, this.options), options); 719 this.init(); 720 } 721 722 /** 723 * ÐниÑиализиÑÑÐµÑ ÐºÐ¾Ð¼Ð¿Ð¾Ð½ÐµÐ½ÑÑ Ð¿ÑиложениÑ: 724 * - ÑоздаÑÑ Ð¼Ð¾Ð´Ð°Ð»Ñное окно Ð´Ð»Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ÐºÑками; 725 * - иниÑиализиÑÑÐµÑ Ð¼ÐµÐ½ÐµÐ´Ð¶ÐµÑ ÐºÑк Ñ Ð¾Ð±ÑабоÑкой ÑобÑÑий. 726 * 727 * @returns {void} 728 */ 729 babelHelpers.createClass(CookieApp, [{ 730 key: "init", 731 value: function init() { 732 var _this = this; 733 this.cookieModal = new CookieModal(this.target, this.options.cookieModalConfig); 734 this.cookieManager = new CookieManager(_objectSpread$3({ 735 onAbsentCookie: function onAbsentCookie() { 736 setTimeout(function () { 737 _this.cookieModal.open(); 738 }, 500); 739 }, 740 onBeforeInit: function onBeforeInit(cookieManager) { 741 _this.cookieModal.target.addEventListener('apply', function (e) { 742 cookieManager.saveUserSettings(e.detail.settings); 743 cookieManager.processInitialState(); 744 }); 745 } 746 }, this.options.cookieManagerConfig)); 747 } 748 }]); 749 return CookieApp; 750 }(); 751 752 exports.CookieApp = CookieApp; 753 exports.CookieManager = CookieManager; 754 exports.CookieMonitor = CookieMonitor; 755 exports.CookieModal = CookieModal; 756 757}((this.O2k.Cookies = this.O2k.Cookies || {}))); 758//# sourceMappingURL=cookies.bundle.js.map
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.