/** * Plugin Banners: ZyGCBanners * Plugin URI: https://gcboost.ru/shop/zygcbanners * Description: Модуль для вывода всплывающих баннеров с информационной или рекламной информацией * Version: 1.1 (modified) * Author: Evgeniy Nayden * Author URI: https://gcboost.ru/ */ !(function (n, e) { var t = {}, i = 'zy-gc-banners', a = { init: function (e) { t = n.extend( !0, { uri: 'teach/control', debug: !0, access: 'admin', scale: 0.6, iframeWidth: '992px', }, e ) a.debug('options', e) a.debug('settings', t) n('head').append(a.getStyles()) var o = window.gcGetCookie(i + '-not-show') if (o && '1' === o) return !1 a.setup() }, setup: function () { if ( (null !== window.frameElement && window.location.pathname.indexOf('/banners') >= 0 && a.editFrame(), !a.checkAccess()) ) return !1 n('body').append(a.template()) // ------ ДОБАВЛЕННЫЙ БЛОК (внедрение стилей в iframe) ------ var iframe = n('#' + i + '__banner-iframe') iframe.on('load', function () { try { var iframeDoc = this.contentDocument || this.contentWindow.document if (iframeDoc) { var style = iframeDoc.createElement('style') style.textContent = '.container { padding-left: 0; padding-right: 0; }' iframeDoc.head.appendChild(style) } } catch (e) { // если доступ к документу запрещён (кросс-домен), игнорируем } }) // --------------------------------------------------------- window.addEventListener( 'message', function (e) { if (e.data && 'frame-size' === e.data.action) { a.debug('event.data', e.data) n('.' + i + '__banner-content').css({ width: e.data.width, height: e.data.height, }) n('#' + i + '__banner-iframe').css({ height: e.data.height, }) n('#' + i + '__banner-wrap').css({ visibility: 'visible', left: '75px', }) } }, !1 ) window.addEventListener( 'message', function (n) { if (n.data && 'close-banner' === n.data.action) { a.debug('event.data', n.data) a.close(n.data.id) } }, !1 ) }, editFrame: function () { n('body').append( '\n \n ' ) n(document).ready(function () { n('.' + i + '__parent').hide() n('.' + i + '__parent').each(function () { var e = n(this).data('block-id'), t = i + '-' + e, a = window.gcGetCookie(t) || 1 if (a && '0' !== a) { n(this).show() setTimeout(function () { window.parent.postMessage({ action: 'frame-size', height: n('body').outerHeight(!0) + 'px', width: n('body').outerWidth(!0) + 'px', }) }, 1e3) n('.' + i + '__close-banner').on('click', function () { var e = n(this).closest('.' + i + '__parent') window.parent.postMessage({ action: 'close-banner', id: e.data('block-id'), }) }) return !1 } }) }) }, template: function () { return ( '\n
\n
\n \n
\n
\n ' ) }, checkAccess: function () { a.debug('checkAccess', window.userInfo) var n = !1 if (window.userInfo) { if ('user' === t.access && window.userInfo.isInAccount) n = !0 if ('manager' === t.access && window.userInfo.isManager) n = !0 if ('admin' === t.access && window.userInfo.isAdmin) n = !0 } return window.location.pathname.indexOf(t.uri) > 0 && n }, close: function (e) { var t = i + '-' + e, a = i + '-not-show' setTimeout(function () { n('#' + i + '__banner-wrap').remove() window.gcSetCookie(t, 0, { expires: 31536e3, path: '/', priority: 'High', }) window.gcSetCookie(a, 1, { expires: 86400, path: '/', priority: 'High', }) }, 100) }, debug: function (n, e) { if (t.debug) { // можно вывести в консоль, если нужно // console.log(n, e); } }, getUrlParam: function (n) { a.debug('getUrlParam', n) var e = window.location.href return new URL(e).searchParams.get(n) }, getStorage: function () { a.debug('getStorage') if (localStorage.getItem(storage_name)) { return JSON.parse(localStorage.getItem(storage_name))[window.lessonId] } return !1 }, updateStorage: function (n) { a.debug('updateStorage', n) var e = JSON.parse(localStorage.getItem(storage_name)) || {} e[window.lessonId] = { rating: n.rating, comment: n.comment, } localStorage.setItem(storage_name, JSON.stringify(e)) }, show: function (n) {}, hide: function (n) {}, getStyles: function () { return ( '\n \n ' ) }, } n.zygcbanners = function (e) { return a[e] ? a[e].apply(this, Array.prototype.slice.call(arguments, 1)) : 'object' != typeof e && e ? void n.error( 'Метод с именем ' + e + ' не существует для jQuery.zygcbanners' ) : a.init.apply(this, arguments) } })(jQuery) /** * КОД ВСТАВКИ В ГЕТКУРС * * * * */