var cl_overlay_widget_url = 'https://citylink.pro/'; var cl_content = `
`; var cl_overlay_widget = { url: cl_overlay_widget_url, urlWidget: cl_overlay_widget_url + 'api/widgets/content/overlay/', urlStyle: cl_overlay_widget_url + 'widgets/overlay/css/style.css', init: function(target) { if (target === null || typeof target === 'undefined') { return false; } this.urlWidget += target; var _this = this; var body = document.body; var isViewed = _this.getCookie('viewed'); var permanent = cl_content.search('permanent') !== -1; if (isViewed === null || permanent) { _this.addStyle(); _this.initListeners(); var overlay = document.createElement('div') overlay.className = 'cl-overlay-bg'; overlay.id = 'cl-overlay-widget'; overlay.innerHTML = cl_content; body.insertBefore(overlay, body.firstChild); } }, addStyle: function() { var style = document.createElement('link'); style.rel = 'stylesheet'; style.type = 'text/css'; style.href = this.urlStyle; document.head.appendChild(style); }, initListeners: function () { var _this = this; document.addEventListener('click', function (e) { if(e.target && e.target.id === 'cl-overlay-close'){ var overlay = document.getElementById('cl-overlay-widget'); if (overlay !== null && typeof overlay !== 'undefined') { overlay.style.display = 'none'; _this.setCookie('viewed', 1); } } }) }, setCookie: function (name, value, options = {}) { options = { path: '/', ...options }; if (options.expires instanceof Date) { options.expires = options.expires.toUTCString(); } var updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value); for (var optionKey in options) { updatedCookie += "; " + optionKey; var optionValue = options[optionKey]; if (optionValue !== true) { updatedCookie += "=" + optionValue; } } document.cookie = updatedCookie; }, getCookie: function (name) { var matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : null; } }