Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/cvetdv.ru/bitrix/js/ |
Upload File : |
"use strict"; // var isOpenPopup = false; var isStylesFound = false; const skyweb24Popups = {}; skyweb24Popups.options = {}; skyweb24Popups.ConditionBuilder = {}; skyweb24Popups.ConditionStatus = {}; skyweb24Popups.ConditionEvents = {}; skyweb24Popups.ConditionAnalyzer = {}; function includeTimerScc() { let newStyle = document.createElement('link'); newStyle.href = "/bitrix/components/skyweb24/popup.pro.timer/templates/.default/style.css"; newStyle.rel = 'preload'; newStyle.setAttribute("as", "style"); document.getElementsByTagName('head')[0].appendChild(newStyle); newStyle = document.createElement('link'); newStyle.href = "/bitrix/components/skyweb24/popup.pro.timer/templates/.default/style.css"; newStyle.rel = 'stylesheet'; newStyle.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(newStyle); } function checkElement(selector) { if (document.querySelector(selector) !== null) { //return rafAsync().then(() => checkElement(selector)); return rafAsync().then(function () { checkElement(selector); }); } else { return Promise.resolve(true); } } function rafAsync() { /*return new Promise(resolve => { requestAnimationFrame(resolve); });*/ return new Promise(function (resolve, reject) { requestAnimationFrame(resolve); }); } function skyweb24getPosition(posObj) { var retData = false; var positions = {}; if (posObj.POSITION_LEFT && posObj.POSITION_LEFT == 'Y') { retData = true; positions.POSITION_LEFT = true; } if (posObj.POSITION_RIGHT && posObj.POSITION_RIGHT == 'Y') { retData = true; positions.POSITION_RIGHT = true; } if (posObj.POSITION_TOP && posObj.POSITION_TOP == 'Y') { retData = true; positions.POSITION_TOP = true; } if (posObj.POSITION_BOTTOM && posObj.POSITION_BOTTOM == 'Y') { retData = true; positions.POSITION_BOTTOM = true; } if (posObj.POSITION_FIXED) { positions.POSITION_FIXED = (posObj.POSITION_FIXED == 'Y') ? true : false; } if (retData) { return positions; } return false; } function skyweb24setPosition(o, pos) { let popup; popup = skyweb24Popups.Popup.getOption("currentPopup"); popup.adjustPosition(); let tmpProps = skyweb24Popups.popupdata[popup.params.popupID]; let isFixed = (tmpProps.POSITION_FIXED && tmpProps.POSITION_FIXED == 'Y') ? true : false; let topTimerHeigth = 0; let bottomTimerHeigth = 0; if (popup.contentContainer.querySelector('.skyweb24_popup_pro_timer.top')) { topTimerHeigth = popup.contentContainer.querySelector('.skyweb24_popup_pro_timer').clientHeight; } if (popup.contentContainer.querySelector('.skyweb24_popup_pro_timer.bottom')) { bottomTimerHeigth = popup.contentContainer.querySelector('.skyweb24_popup_pro_timer').clientHeight; } if (!isFixed && pos == false) { // } else if (isFixed && pos == false) { let position = "fixed"; let topTimerHeigth = (o.querySelector('.skyweb24_popup_pro_timer.top')) ? o.querySelector('.skyweb24_popup_pro_timer').clientHeight : 0; let tmpTop = Math.round((document.documentElement.clientHeight - o.offsetHeight - topTimerHeigth) / 2) let tmpLeft = Math.round((document.documentElement.clientWidth - o.offsetWidth) / 2); tmpTop = (tmpTop < 0) ? 0 : tmpTop; tmpLeft = (tmpLeft < 0) ? 0 : tmpLeft; if(o.offsetHeight > document.documentElement.clientHeight) { position = 'absolute'; } o.style.position = position; o.style.top = tmpTop + 'px'; o.style.left = tmpLeft + 'px'; if (pos.POSITION_BOTTOM) { o.style.bottom = '0'; o.style.top = ''; } if (pos.POSITION_TOP) { o.style.bottom = ''; o.style.top = '0'; } if (pos.POSITION_RIGHT) { o.style.right = '0'; o.style.left = ''; } if (pos.POSITION_LEFT) { o.style.right = ''; o.style.left = '0'; } } else { if (pos.POSITION_BOTTOM) { if (pos.POSITION_FIXED) { o.style.bottom = (0 + bottomTimerHeigth * 1) + 'px'; o.style.top = ''; } else { var tmpStyle = getComputedStyle(o); o.style.bottom = bottomTimerHeigth + 'px'; o.style.top = ''; //fix body relative var tmpBodyStyle = getComputedStyle(document.body); if (tmpBodyStyle.position == 'relative') { o.style.top = (document.documentElement.scrollTop + document.documentElement.clientHeight - parseInt(tmpStyle.height) - bottomTimerHeigth) + 'px'; o.style.bottom = ''; } } } else if (pos.POSITION_TOP) { if (pos.POSITION_FIXED) { o.style.bottom = ''; o.style.top = (0 + topTimerHeigth * 1) + 'px'; } else { o.style.bottom = ''; o.style.top = document.documentElement.scrollTop + topTimerHeigth + 'px'; } } if (pos.POSITION_LEFT) { o.style.right = ''; o.style.left = '0'; } else if (pos.POSITION_RIGHT) { o.style.left = ''; o.style.right = '0'; } if (pos.POSITION_FIXED) { o.style.position = 'fixed'; } } //animation and opasity var youtube = popup.contentContainer.querySelectorAll('#skyweb24_video_youtube'); var rollete = popup.contentContainer.querySelectorAll('#skyweb24_roulette'); var discount = popup.contentContainer.querySelectorAll('#skyweb24_coupon_coupon'); if (tmpProps.SHOW_ANIMATION && tmpProps.SHOW_ANIMATION != 'none') { //if youtube wait load if (youtube.length != 0) { } else if (discount.length > 0 || rollete.length > 0) { var styles = window.document.styleSheets; if (isStylesFound) { // startCustomAnimation(popup, tmpProps.SHOW_ANIMATION); isStylesFound = false; } else { for (var i in styles) { if (isNaN(i)) { continue; } if (styles[i].href && styles[i].href.indexOf(tmpProps.STYLE) !== -1) { isStylesFound = true; break; } } setTimeout(function () { skyweb24positionBanner(popup); }, 20); return; } } else { } } else { if (youtube.length != 0) { var iframe = popup.contentContainer.querySelector('iframe'); iframe.onload = function () { popup.adjustPosition(); BX("popup-message").style.opacity = 1; var elems = BX("popup-message").childNodes; for (var i = 0; i < elems.length; i++) { elems[i].style.opacity = 1; } } } else { BX("popup-message").style.opacity = 1; var elems = BX("popup-message").childNodes; for (var i = 0; i < elems.length; i++) { elems[i].style.opacity = 1; } } } } function skyweb24positionBanner(popup) { if(!popup) return false; var _this = popup; var tmpRect = _this.popupContainer.getBoundingClientRect(); if (!tmpRect) return false; if (tmpRect.width == 0 || tmpRect.height == 0) { setTimeout(function () { skyweb24positionBanner(popup); }, 100); } else if (popup.workWidth == undefined && popup.workHeight == undefined || popup.workWidth != tmpRect.width || popup.workHeight != tmpRect.height) { popup.workWidth = tmpRect.width; popup.workHeight = tmpRect.height; skyweb24positionBanner(popup); } else { setTimeout(function (popup) { if (_this.params.className == 'sw24PopupPro') { var currentPos = skyweb24getPosition(skyweb24Popups.popupdata[popup.params.popupID]); var img = popup.contentContainer.querySelectorAll('img'); var youtube = popup.contentContainer.querySelectorAll('#skyweb24_video_youtube'); var rollete = popup.contentContainer.querySelectorAll('#skyweb24_roulette'); if (img.length == 0 && youtube.length == 0) { if (currentPos === false) { if (rollete.length > 0) { setTimeout(function () { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); }, 0); } else { // skyweb24setPosition(_this.contentContainer.parentNode, currentPos); setTimeout(function () { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); }, 0); } } else { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); } } else { if (currentPos === false) { if (img.length != 0) { var container = _this.contentContainer var innerImgs = img.length; for (var i = 0; i < img.length; i++) { if (img[i].offsetHeight || img[i].height) { innerImgs--; } else { setTimeout(function () { skyweb24positionBanner(popup); }, 200); return; } } if (innerImgs < 1) { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); } } else { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); } } else { skyweb24setPosition(_this.contentContainer.parentNode, currentPos); } } } }, 30, popup); } } var buttonWindowPopup = { active: "N", class: "sk24-button-window-popup", element: "", popupid: "", create: function (data) { if (!this.element) { var template = document.createElement("div"); template.classList.add(this.class); template.innerHTML += "<a href='#'><div class='btn animated'><i style='color: " + data.icon.color + "' class='fa " + data.icon.class + "' aria-hidden='true'></i></div></a>"; document.body.appendChild(template); this.element = document.querySelectorAll(".sk24-button-window-popup")[0]; this.setAnimation(data.animation); this.setPostion(data.position); this.setBackground(data.background); this.setEvent(); } }, setAnimation: function (data) { data.name = !data.name ? "none" : data.name; data.delay = !data.delay ? "slow" : data.delay; data.repeat = !data.repeat ? "infinite" : ""; buttonWindowPopup.element.getElementsByClassName("btn")[0].classList.add(data.name, data.delay, data.repeat); }, setBackground: function (data) { buttonWindowPopup.element.getElementsByClassName("btn")[0].style.background = data.color; }, setPostion: function (data) { let left = data.left == "Y" ? "0" : "auto"; let right = data.right == "Y" ? "0" : "auto"; let top = data.top == "Y" ? "0" : "auto"; let bottom = data.bottom == "Y" ? "0" : "auto"; this.element.style.left = left; this.element.style.right = right; this.element.style.top = top; this.element.style.bottom = bottom; }, setEvent: function () { this.element.children[0].addEventListener("click", function (e) { e.preventDefault(); skyweb24Popups.Popup.show(buttonWindowPopup.popupid); buttonWindowPopup.hide(); return false; }) }, hide: function () { this.element.classList.remove("show"); }, show: function () { this.element.classList.add("show"); }, destroy: function () { this.element.remove(); this.element = ""; this.popupid = ""; this.active = "N"; }, }; skyweb24Popups.Popup = { _popups: [], _options: { closeEvents: [ { name: 'closeByTextButton', type: 'sw24TextCloseButton' }, { name: 'closeByPopupIcon', type: 'popup-window-close-icon' }, { name: 'closeByPopupOveray', type: 'popup-window-overlay' }, { name: 'closeTargetAction', type: 'sw24TargetAction' }, { name: 'closeByEsc', type: 'closeByEsc' } ], }, init: function() { let _self = this; this._getGlobalOptions().then(function(response){ let options = JSON.parse(response) for(let name in options) { _self.setOption(name, options[name]) } _self._getPopups().then(function (response) { _self._popups = JSON.parse(response) ; let popupIds = []; if(!_self._popups){ return false; } for(let popup of _self._popups) { popupIds.push(popup['id']); } _self._getPathTemplates(popupIds).then(function (data) { skyweb24Popups.popupdata = JSON.parse(data); skyweb24Popups.ConditionBuilder.init(_self._popups); skyweb24Popups.ConditionAnalyzer.init(); }); }) }); }, show: function (popupId = false) { if(popupId) { return this.create(popupId); } let popupList = skyweb24Popups.QueueShow.getList(); for (let popupId of popupList) { if(this.getCurPopupID()) break; this.setOption("currentPopupID", popupId); skyweb24Popups.Statistic.send("show", popupId); this.create(popupId); } }, create: function (popupID) { let _self = this; this._getTemplate(popupID).then(function(templateHTML) { skyweb24Popups.popupdata[popupID].DATA = templateHTML; _self.setStyles(popupID).then(function (popupID) { var backColor = (skyweb24Popups.popupdata[popupID].BACKGROUND_COLOR && skyweb24Popups.popupdata[popupID].BACKGROUND_COLOR != '') ? skyweb24Popups.popupdata[popupID].BACKGROUND_COLOR : '#000'; var backOpacity = (skyweb24Popups.popupdata[popupID].BACKGROUND_OPACITY && skyweb24Popups.popupdata[popupID].BACKGROUND_OPACITY != '') ? skyweb24Popups.popupdata[popupID].BACKGROUND_OPACITY : 50; backOpacity = backOpacity * 1; var closeIcon = true; if (skyweb24Popups.popupdata[popupID].SHOW_CLOSEBUTTON && skyweb24Popups.popupdata[popupID].SHOW_CLOSEBUTTON != '') { closeIcon = (skyweb24Popups.popupdata[popupID].SHOW_CLOSEBUTTON == 'Y') ? true : false; } var autoHide = true; if (skyweb24Popups.popupdata[popupID].CLOSE_AUTOHIDE && skyweb24Popups.popupdata[popupID].CLOSE_AUTOHIDE != '') { autoHide = (skyweb24Popups.popupdata[popupID].CLOSE_AUTOHIDE == 'Y') ? true : false; } var popup = new BX.PopupWindow("popup-message", null, { content: "---", autoHide: autoHide, bindOnResize: false, zIndex: "1", offsetTop: 1, offsetLeft: 0, className: 'sw24PopupPro', lightShadow: true, closeIcon: closeIcon, closeByEsc: true, popupID: popupID, overlay: { backgroundColor: backColor, opacity: backOpacity }, events: { onAfterPopupShow: function () { //fix for css setting with important this.overlay.element.style.setProperty('background-color', backColor, 'important'); this.overlay.element.style.setProperty('opacity', parseFloat(backOpacity / 100).toPrecision(3), 'important'); //e. o. fix for css setting with important skyweb24positionBanner(popup); let closeButton = this.contentContainer.querySelector(".sw24TextCloseButton"), self = this; if (closeButton) { closeButton.addEventListener('click', function () { _self.close(); }) } }, onPopupDestroy: function (e) {}, onPopupShow: function () { var tmpProps = skyweb24Popups.popupdata[popupID]; if (tmpProps.SHOW_ANIMATION && tmpProps.SHOW_ANIMATION != 'none') { var elems = BX("popup-message").childNodes; for (var i = 0; i < elems.length; i++) { } } } } }); popup.close = BX.proxy(function (e) { /*if (event !== undefined) { isOpenPopup = false; }*/ /*if (!this.isShown()) { return; }*/ /*if (event && !(BX.getEventButton(event) & BX.MSLEFT)) { return true; }*/ if (buttonWindowPopup.active == "Y") { buttonWindowPopup.show(); } let eventName = (event) ? event.target : 'closeByEsc'; let timeStart = parseInt(this.getOption("timeStartPopup")); let timeNow = parseInt(Math.floor(Date.now() / 1000)); skyweb24Popups.Statistic.send("close", popup.params.popupID, { popupTime: timeNow - timeStart, eventName: this._defineCloseEvent(eventName), }); this.setOption("currentPopup", null); this.setOption("currentPopupID", null); this.setOption("timeStartPopup", 0); if (skyweb24Popups.popupdata[popupID].HIDE_ANIMATION && skyweb24Popups.popupdata[popupID].HIDE_ANIMATION != 'none') { skyweb24_windowAnimation.hide(skyweb24Popups.popupdata[popupID].HIDE_ANIMATION); setTimeout(function () { popup.hideOverlay(); if(popup.popupContainer) popup.popupContainer.style.display = "none"; setTimeout(BX.proxy(popup.destroy, popup), 0); }, 800); } else { popup.hideOverlay(); popup.popupContainer.style.display = "none"; setTimeout(BX.proxy(popup.destroy, popup), 0); } skyweb24Popups.QueueShow.remove(popup.params.popupID); setTimeout(BX.proxy(function () { this.show(); }, this), 1500); BX.onCustomEvent("onPopupClose", [popup]) }, _self); //inner scripts var tmpData = skyweb24Popups.popupdata[popupID].DATA; var result = tmpData.match(/<script[^>]*>([\s\S]*?)<\/script>/g); var tmpInnerJs = [], tmpOuterJs = []; if (result && result.length > 0) { for (var n = 0; n < result.length; n++) { var nextRes = result[n].match(/<script[^>]*>([\s\S]*?)<\/script>/); if (nextRes) { tmpInnerJs.push(nextRes[1]); tmpData.replace(nextRes[0], ''); if (nextRes[1] == '') { tmpOuterJs.push(nextRes[0]); } } } } popup.setContent(tmpData); // END CREATE POPUP WINDOW _self.setOption("timeStartPopup", Math.floor(Date.now() / 1000)); _self.setOption("currentPopup", popup); if (tmpOuterJs.length > 0) { for (var n = 0; n < tmpOuterJs.length; n++) { var tmpEl = document.createElement('div'); tmpEl.innerHTML = tmpOuterJs[n]; var tmpS = tmpEl.querySelector("script"); if (tmpS.src) { var tmpOuterS = document.createElement('script'); tmpOuterS.src = tmpS.src; popup.popupContainer.appendChild(tmpOuterS); } } setTimeout(function () { if (tmpInnerJs.length > 0) { for (var n = 0; n < tmpInnerJs.length; n++) { if (tmpInnerJs[n] != '') { var nextScript = document.createElement('script'); nextScript.innerHTML = tmpInnerJs[n]; popup.popupContainer.appendChild(nextScript); } } } }, 500); } else if (tmpInnerJs.length > 0) { for (var n = 0; n < tmpInnerJs.length; n++) { if (tmpInnerJs[n] != '') { var nextScript = document.createElement('script'); nextScript.innerHTML = tmpInnerJs[n]; popup.popupContainer.appendChild(nextScript); } } } popup.show(); BX.bindDelegate(popup.contentContainer,"click", {className: "sw24TargetAction"}, function (e) { skyweb24Popups.Statistic.send("action", popup.params.popupID); }); if (popup.contentContainer.querySelector('.skyweb24_popup_pro_timer .timer') != null) { function startTimer() { if (!popup.contentContainer) { return false; } var timer = popup.contentContainer.querySelectorAll('.skyweb24_popup_pro_timer .timer .clock>span:not(.sep)'); var d, h, m, s; try { d = timer.item(0).innerHTML; h = timer.item(1).innerHTML; m = timer.item(2).innerHTML; s = timer.item(3).innerHTML; } catch (error) { return; } if (s == 0) { if (m == 0) { if (h == 0) { if (d == 0) { _self.close(); } d--; h = 24; if (d < 10) d = '0' + d; } h--; m = 60; if (h < 10) h = '0' + h; } m--; if (m < 10) m = '0' + m; s = 59; } else s--; if (s < 10) s = "0" + s; popup.contentContainer.querySelector('.skyweb24_popup_pro_timer .timer .clock').innerHTML = "<span>" + d + "</span><span class='sep'>:</span><span>" + h + "</span><span class='sep'>:</span><span>" + m + "</span><span class='sep'>:</span><span>" + s + "</span>"; setTimeout(startTimer, 1000); } startTimer(); } if (popup.contentContainer.querySelector('section.container') != null) { var count = paintRoulett(); BX.bind(BX(popup.contentContainer.querySelector('button.roll_roulette')), 'click', function () { roll_roulette_func(count); }); } BX.setCookie('skwb24_popups_show_' + popupID, 'Y', {expires: 5, path: '/'}); }); }); }, setStyles: function(popupID) { return new Promise(function (resolve, reject) { includeTimerScc(); // CREATE POPUP WINDOW BX.remove(BX('skyweb24_popup_style')); BX.remove(BX('skyweb24_popup_color')); var head = document.getElementsByTagName('head')[0]; let href = skyweb24Popups.popupdata[popupID].STYLE; let isCustom = skyweb24Popups.popupdata[popupID].TEMPLATE.indexOf("custom") > 0; if(skyweb24Popups.minified == "Y" && !isCustom) { href = skyweb24Popups.popupdata[popupID].TEMPLATE + "/style.min.css" } let cssPreload = BX.create('link', { 'attrs': { 'rel': 'preload', "as": "style", 'href': href } }); var s_tepmlate = BX.create('link', { 'attrs': { 'id': 'skyweb24_popup_style', 'type': 'text/css', 'rel': 'stylesheet', 'href': href } }); head.appendChild(cssPreload); head.appendChild(s_tepmlate); if (skyweb24Popups.popupdata[popupID].THEME) { let cssPreloadColor = BX.create('link', { 'attrs': { 'rel': 'preload', "as": "style", 'href': skyweb24Popups.popupdata[popupId].THEME } }); var s_color = BX.create('link', { 'attrs': { 'id': 'skyweb24_popup_color', 'type': 'text/css', 'rel': 'stylesheet', "as": "style", 'href': skyweb24Popups.popupdata[popupId].THEME } }); head.appendChild(cssPreloadColor); head.appendChild(s_color); } s_tepmlate.addEventListener("load", BX.proxy(function (e) { resolve(popupID); }, this)); }) }, close: function () { this.getOption("currentPopup").close(); }, getCurPopupID: function() { return this.getOption("currentPopupID"); }, setOption: function(optionName, optionValue, popupID = false) { if(popupID) { this._options[optionName] = new Object(); this._options[optionName][popupID] = optionValue; } else { this._options[optionName] = optionValue; } }, getOption: function(name, popupId = false) { return (popupId) ? this._options[name][popupId] : this._options[name]; }, getBasket: function() { return this.request({ url: '/bitrix/components/skyweb24/popup.pro/ajax.php', fields: { type: 'getBasket', }, type: 'json', method: "POST" }) }, request: function (data) { return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest(); xhr.open( data.method, data.url + "?" + BX.ajax.prepareData(data.fields), true ); xhr.send(); xhr.onreadystatechange = function () { if (xhr.status == 200 && xhr.readyState == 4) { resolve(xhr.responseText); } } }); }, _getGlobalOptions: function() { return this.request({ url: '/bitrix/components/skyweb24/popup.pro/ajax.php', fields: { type: 'skyweb24Popups' }, type: 'json', method: "POST" }) }, _getPopups: function() { return this.request({ url: '/bitrix/components/skyweb24/popup.pro/ajax.php', fields: { type: 'getPopups', pageUrl: encodeURIComponent(location.href), site: this.getOption("site"), dateUser: Math.round(+new Date() / 1000), }, type: 'json', method: "POST" }) }, _getPathTemplates: function(popupIds) { return this.request({ url: '/bitrix/components/skyweb24/popup.pro/ajax.php', fields: { 'type': 'getTemplatePath', 'popupIds': popupIds }, type: 'json', method: "POST" }) }, _getTemplate: function(popupId) { return this.request({ url: '/bitrix/components/skyweb24/popup.pro/ajax.php', fields: { 'type': 'getHTML', 'popupId': popupId }, type: 'html', method: "POST" }, false) }, _defineCloseEvent: function (target) { let listCloseEvents = this.getOption("closeEvents"); for (let closeEvent of listCloseEvents) { if(typeof target !== "string") { if (target.classList.contains(closeEvent.type)) { return closeEvent.name; } } else { if(closeEvent.type == target) { return closeEvent.name; } } } return "closeWindow"; }, }; skyweb24Popups.ConditionBuilder = { options: { indexList: 0 }, init: function (popupsList) { this.options.indexList = 0; for (let popup of popupsList) { let condition = this._checking(popup['rule'], popup['id']); skyweb24Popups.ConditionStatus.setStatus(popup['id'], condition); } }, _checking: function (condition, popupID = false) { let list = { id: this.options.indexList++ }; if(condition.controlId === "CondGroup") { list.aggregator = this._defineAggregator(condition.values.aggregator, condition.values.value); list.value = []; for(let i = 0; i < condition.children.length; i++) { list.value.push(this._checking(condition.children[i], popupID)); } } else if(condition === true) list.value = "Y"; else if( condition === false ) list.value = "N"; else { list.value = skyweb24Popups.ConditionEvents.setEvent( condition.controlId, condition.values, popupID, list ); } return list; }, _defineAggregator: function(aggregator, logic) { let sign; sign = logic === "False" ? "!" : ""; return sign + aggregator; }, }; skyweb24Popups.ConditionEvents = { options: {}, setEvent: function (name, values, popupID, list) { let _self = this; if(name === "DAY") { if(!values.value){ return "N"; } let dayNow = String(new Date().getDay()); if(values.logic === "Equal") { return values.value.indexOf(dayNow) >= 0 ? "Y" : "N"; } else { return values.value.indexOf(dayNow) < 0 ? "Y" : "N"; } } else if(name === "AFTER_TIME_SECOND") { let timeNeedful = parseInt(values.default_value); let timeAfter = parseInt(values.value); if(values.logic === "more") { if(timeAfter <= 0) return "Y"; setTimeout(function () { list.value = "Y"; skyweb24Popups.ConditionAnalyzer.init(popupID); }, timeAfter * 1000); } else { if(timeNeedful > timeAfter) return "Y"; else if(timeNeedful <= timeAfter) return "N"; } return "U"; } else if(name === "AFTER_TIME_SECOND_PAGE") { if(values.logic === "more") { setTimeout(function () { list.value = "Y"; skyweb24Popups.ConditionAnalyzer.init(popupID); }, parseInt(values.value) * 1000); return "N"; } else { setTimeout(function () { list.value = "N"; skyweb24Popups.ConditionAnalyzer.init(popupID); }, parseInt(values.value) * 1000); return "Y"; } } else if(name === "TIME_INTERVAL") { let dateStart = new Date; let dateEnd = new Date; let dateNow = new Date; let vTimeStart = values.time_start.split(":"); let vTimeEnd = values.time_end.split(":"); dateStart.setHours(vTimeStart[0], vTimeStart[1], vTimeStart[2]); dateEnd.setHours(vTimeEnd[0], vTimeEnd[1], vTimeEnd[2]); let timeNow = dateNow.getTime(); let timeStart = dateStart.getTime(); let timeEnd = dateEnd.getTime(); if (timeStart < timeNow && timeEnd > timeNow) { return "Y"; } return "N"; } else if(name === "ALREADY_GOING") { let timerStartAnalyzer; document.addEventListener("mousemove", function (e){ list.value = (e.clientY <= 100) ? "Y" : "N"; if(timerStartAnalyzer) clearTimeout(timerStartAnalyzer); timerStartAnalyzer = setTimeout(function () { skyweb24Popups.ConditionAnalyzer.init(popupID); }, 150); }); return "U"; } else if(name === "PERCENT_PAGE") { let timerStartAnalyzer; document.addEventListener("scroll", function (e) { let heightOfWindow = window.innerHeight, contentScrolled = window.pageYOffset, bodyHeight = document.body.scrollHeight; let total = bodyHeight - heightOfWindow; let got = contentScrolled; let percent = parseInt((got / total) * 100); if (percent >= values.value) { list.value = "Y"; } else { list.value = "N"; } if(timerStartAnalyzer) clearTimeout(timerStartAnalyzer); timerStartAnalyzer = setTimeout(function () { skyweb24Popups.ConditionAnalyzer.init(popupID); }, 150); }); return "U"; } else if(name === "ANCHOR_VISIBLE") { document.addEventListener("scroll", function (e){ let anchor = document.querySelector('[name="' + values.value + '"]'); if(anchor) { let portHeight = window.innerHeight; let XYAnchor = anchor.getBoundingClientRect(); let result = (XYAnchor.bottom > 0 && XYAnchor.top <= portHeight) ? "Y" : "N"; if(result !== list.value) { list.value = result; skyweb24Popups.ConditionAnalyzer.init(popupID); } } }); return "U"; } else if(name === "ON_CLICK_CLASS_LINK") { if(values.value) { let selector = document.querySelector("." + values.value); if(selector) { selector.addEventListener("click", function (e){ list.value = "Y"; skyweb24Popups.ConditionAnalyzer.init(popupID); }); } } return "U"; } else if(name === "DEVICE_TYPE") { let userAgent = window.navigator.userAgent.toLowerCase(); if(values.logic === "Equal") { if(values.value) { for(let value of values.value) { if((userAgent.indexOf(value) >= 0)) { return "Y"; } } } return "N"; } else { for(let value of values.value) { if((userAgent.indexOf(value) >= 0)) { return "N"; } } return "Y"; } } else if(name === "PREVIOUS_WINDOW") { if(BX.getCookie("skwb24_popups_show_" + values.value)) { return (values.logic === "Equal") ? "Y" : "N"; } BX.addCustomEvent("onPopupClose", function(e){ if(!e) return false; if(values.logic === "Equal") { if(e.params.popupID === values.value) { list.value = "Y"; skyweb24Popups.ConditionAnalyzer.init(popupID); } } else { if( e.params.popupID !== values.value && e.params.popupID !== popupID ) { list.value = "Y"; skyweb24Popups.ConditionAnalyzer.init(popupID); } } }); return "U"; } else if(name === "OS") { let userAgent = window.navigator.userAgent.toLowerCase(); if(values.logic === "Equal") { return (userAgent.indexOf(values.value) >= 0) ? "Y" : "N"; } else { return (userAgent.indexOf(values.value) < 0) ? "Y" : "N"; } } else if(name === "BROWSER") { let userAgent = window.navigator.userAgent.toLowerCase(); if(values.logic === "Equal") { return (userAgent.indexOf(values.value) >= 0) ? "Y" : "N"; } else { return (userAgent.indexOf(values.value) < 0) ? "Y" : "N"; } } else if(name === "REPEAT_SHOW") { if(BX.getCookie('skwb24_popups_repeat_show_' + popupID) === 'Y') { return "N"; } else { let repeat = values.repeat; let type = values.type.toLowerCase(); let arTypes = { hour: 3600, day: 86400, week: 604800, month: 2419200, year: 31536000 }; BX.addCustomEvent("onPopupShow", function(e){ if(e.params.popupID === popupID) { BX.setCookie( "skwb24_popups_repeat_show_" + popupID, "Y", {expires: arTypes[type] * repeat, path: '/'} ); list.value = "N"; } }); return "Y"; } } else if(name === "REPEAT_GAME") { let arTime = { HOUR: 3600, DAY: 86400, WEEK: 604800, MONTH: 2629743, YEAR: 31556926, }; skyweb24Popups.Popup.setOption( "repeat_game", values.repeat * arTime[values.type], popupID ); return "Y"; } else if(name === "CART_SUMM") { let basket = skyweb24Popups.Popup.getOption("basket"); let cartSum = parseInt(basket.summ || 0); let value = parseInt(values.value); BX.addCustomEvent('onAjaxSuccess', function (a, b) { if (b && b.url && b.url.indexOf('basket') >= 0 && b.url.indexOf('component_props.php') < 0) { skyweb24Popups.Popup.getBasket().then(function (response) { let basket = JSON.parse(response); let result; if(values.logic === "more") { result = ( basket.summ >= value ) ? "Y" : "N"; } else { result = ( basket.summ < value ) ? "Y" : "N"; } if(list.value !== result) { list.value = result; skyweb24Popups.ConditionAnalyzer.init(popupID); } }); } }); if(values.logic === "more") { return ( cartSum >= value ) ? "Y" : "N" } else { return ( cartSum < value ) ? "Y" : "N" } } else if(name === "CART_COUNT") { let basket = skyweb24Popups.Popup.getOption("basket"); let cartCount = parseInt(basket.count || 0); let value = parseInt(values.value); BX.addCustomEvent('onAjaxSuccess', function (a, b) { if (b && b.url && b.url.indexOf('basket') >= 0 && b.url.indexOf('component_props.php') < 0) { skyweb24Popups.Popup.getBasket().then(function (response) { let basket = JSON.parse(response); let result; if(values.logic === "more") { result = ( basket.count >= value ) ? "Y" : "N"; } else { result = ( basket.count < value ) ? "Y" : "N"; } if(list.value !== result) { list.value = result; skyweb24Popups.ConditionAnalyzer.init(popupID); } }); } }); if(values.logic === "more") { return ( cartCount >= value ) ? "Y" : "N" } else { return ( cartCount < value ) ? "Y" : "N" } } else if(name === "CART_PRODUCT") { let basket = skyweb24Popups.Popup.getOption("basket"); let cartProducts = basket.products || []; let productID = values.value; BX.addCustomEvent('onAjaxSuccess', function (a, b) { if (b && b.url && b.url.indexOf('basket') >= 0 && b.url.indexOf('component_props.php') < 0) { skyweb24Popups.Popup.getBasket().then(function (response) { let basket = JSON.parse(response); let result; if(values.logic === "Equal") { result = (basket.products.indexOf(productID) >= 0) ? "Y" : "N"; } else { result = (basket.products.indexOf(productID) < 0 ) ? "Y" : "N"; } if(list.value !== result) { list.value = result; skyweb24Popups.ConditionAnalyzer.init(popupID); } }); } }); if(values.logic === "Equal") { return (cartProducts.indexOf(productID) >= 0) ? "Y" : "N"; } else { return (cartProducts.indexOf(productID) < 0) ? "Y" : "N"; } } else if(name === "CART_SECTION") { let basket = skyweb24Popups.Popup.getOption("basket"); let cartSections = basket.sections || []; let sectionID = values.value; BX.addCustomEvent('onAjaxSuccess', function (a, b) { if (b && b.url && b.url.indexOf('basket') >= 0 && b.url.indexOf('component_props.php') < 0) { skyweb24Popups.Popup.getBasket().then(function (response) { let basket = JSON.parse(response); let result; if(values.logic === "Equal") { result = (basket.sections.indexOf(sectionID) >= 0) ? "Y" : "N"; } else { result = (basket.sections.indexOf(sectionID) < 0 ) ? "Y" : "N"; } if(list.value !== result) { list.value = result; skyweb24Popups.ConditionAnalyzer.init(popupID); } }); } }); if(values.logic === "Equal") { return (cartSections.indexOf(sectionID) >= 0) ? "Y" : "N"; } else { return (cartSections.indexOf(sectionID) < 0) ? "Y" : "N"; } } else if(name === "HAS_COOKIE") { let cookieValue = BX.getCookie(values.name); if(!cookieValue) return "N"; if(values.logic === "Equal") { return (values.value === cookieValue) ? "Y" : "N"; } else { return (values.value !== cookieValue) ? "Y" : "N"; } } }, }; skyweb24Popups.ConditionStatus = { // statuses - Y, N, U // aggregation - AND, !AND, OR, !OR _statuses: [], setStatus: function (popupId, condition) { this._statuses.push({ popupId: popupId, shown: false, condition: [condition] }) }, getStatus: function (popupId) { if(popupId) { for(let status of this._statuses) { if(status.popupId == popupId) { return [status]; } } } return this._statuses; }, }; skyweb24Popups.ConditionAnalyzer = { _status: [], init: function(popupID) { let statusPopups = skyweb24Popups.ConditionStatus.getStatus(popupID); for(let status of statusPopups) { let result = this._analyze(status.condition); if(result[0] === "Y") { // console.log("ANALYZER STATUS", { id: popupID, result }); skyweb24Popups.QueueShow.add(status['popupId']); skyweb24Popups.Popup.show(); } } }, _analyze: function (group) { let values = []; if (group.length > 0) { for (let item of group) { if (typeof item.value === "object") { values.push(this._defineGroupValue( this._analyze(item.value), item.aggregator, item.id )); } else { values.push(item.value); } } } else { // if empty group values.push("Y"); } return values; }, _defineGroupValue: function (values, aggregator, id = 0) { values = values.map(function(value, i){ return value === "U" ? "N" : value; }); let lenValue = values.reduce(function (arr, n){ arr[n] = (arr[n] || 0) + 1; return arr; }, {}); if (aggregator === "AND") { return values.length === lenValue['Y'] ? "Y" : "N"; } if (aggregator === "!AND") { return values.length === lenValue['N'] ? "Y" : "N"; } if (aggregator === "OR") { return lenValue['Y'] >= 1 ? "Y" : "N"; } if (aggregator === "!OR") { return lenValue['N'] >= 1 ? "Y" : "N"; } } }; skyweb24Popups.QueueShow = { _list: [], add: function (popupID) { if(!this.hasItemList(popupID)) { this._list.push(popupID); } }, remove: function (popupID) { if(this.hasItemList(popupID)) { this._list.splice(this._list.indexOf(popupID), 1); } }, getList: function () { return this._list; }, hasItemList: function (popupID) { return this._list.indexOf(popupID) >= 0; }, }; skyweb24Popups.Statistic = { send: function(type, popupID = false, params = false) { if(type === "action") { return this._request({ 'type': 'statisticAction', 'popupId': popupID || skyweb24Popups.Popup.getCurPopupID(), 'site_url': location.host, 'url': location.href }); } else if(type === "show") { return this._request({ type: "statisticShow", popupId: popupID || skyweb24Popups.Popup.getCurPopupID(), site_url: location.host, url: location.href }); } else if( type === "close") { return this._request({ type: 'statisticTime', popupId: popupID || skyweb24Popups.Popup.getCurPopupID(), popupTime: params.popupTime, closeType: params.eventName, site_url: location.host, url: location.href }); } }, _request: function (data) { return !!skyweb24Popups.Popup.request({ url: "/bitrix/components/skyweb24/popup.pro/ajax.php", fields: data, method: "POST", dataType: "JSON" }); }, }; BX.ready(function () { skyweb24Popups.Popup.init(); });