Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавляет баннер вверх сайта. Ссылка на исследование #1250

Merged
merged 16 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3c42ec5
Добавляет баннер вверх сайта
solarrust Mar 19, 2024
2f02f81
Добавляет условие для ссылки
solarrust Mar 19, 2024
0fc5fc4
Удаляет hidden
solarrust Mar 19, 2024
8e84469
Использует гибкие стили для шрифта и кнопки
skorobaeus Mar 20, 2024
e26c9fa
Отделяет глаза от зубов
skorobaeus Mar 20, 2024
733dd22
Уменьшает мордашку для экранов поменбше
skorobaeus Mar 20, 2024
40f1f8b
Увеличивает ссылку на мобильных, чтобы удобнее было нажимать пальцем
skorobaeus Mar 20, 2024
1bd0331
Возвращает hidden
igsekor Mar 20, 2024
33f64ae
Добавляет настройку для стилей
igsekor Mar 20, 2024
4e959cc
Добавляет скрипт для работы баннера
igsekor Mar 20, 2024
12df3f4
Меняет имя переменной
igsekor Mar 20, 2024
e2822a5
Меняет простой шаблон на макрос с шаблоном
igsekor Mar 20, 2024
ba62cec
Убирает баннер из базового шаблона
igsekor Mar 20, 2024
e22d483
Добавляет баннер на все требуемые страницы
igsekor Mar 20, 2024
33d63a9
Добавляет условия для показа в отсутствии других баннеров
igsekor Mar 20, 2024
dfc744a
Добавляет дополнительное услловие для закрытого попапа
igsekor Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/images/top-banner/bat-eyes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/images/top-banner/bat-teeth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/includes/blocks/top-banner.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% macro topBanner(isMainPage = false) %}
<div class="top-banner notification" hidden>
<p class="top-banner__content">Мы хотим понять, кто нас читает. Поможете нам? Займёт всего 5 минут.</p>
<a class="top-banner__button notification__button button" target="_blank" rel="noreferrer nofollow" href="{% if isMainPage %}https://forms.yandex.ru/cloud/65f1aaf35d2a061e4ff460e0/?utm_source=doka_main{% else %}https://forms.yandex.ru/cloud/65f1aaf35d2a061e4ff460e0/?utm_source=doka_other{% endif %}">Пройти опрос</a>
</div>
{% endmacro %}
1 change: 0 additions & 1 deletion src/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

</head>
<body class="base__body {{ bodyClass }}">

{{ content | safe }}

{% include "blocks/cookie-notification.njk" %}
Expand Down
1 change: 1 addition & 0 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import './modules/question-form.js'
import './modules/subscribe-form.js'
import './modules/code-line-numbers.js'
import './modules/cookie-notification.js'
import './modules/top-banner.js'
import './modules/copy-code-snippet.js'
import './modules/people.js'
import './modules/filter-panel.js'
Expand Down
48 changes: 48 additions & 0 deletions src/scripts/modules/top-banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function init() {
const banner = document.querySelector('.top-banner')
const button = banner?.querySelector('.top-banner__button')
const interval = 10000
const visitedPagesKey = 'pages-list'

if (!banner && !button) {
return
}

const storageKey = 'top-banner'

try {
const isBannerAccepted = JSON.parse(localStorage.getItem(storageKey))

if (isBannerAccepted) {
return
}

const visitedPages = localStorage.getItem(visitedPagesKey)
const pageList = visitedPages ? JSON.parse(visitedPages) : {}

let timer = setInterval(() => {
if (pageList) {
for (const key in pageList) {
if (pageList[key].duration >= interval * 2) {
banner.hidden = false
clearInterval(timer)
break
}
}
}
}, interval)
} catch (error) {
console.error(error)
}

button.addEventListener(
'click',
() => {
banner.hidden = true
localStorage.setItem(storageKey, true)
},
{ once: true },
)
}

init()
78 changes: 78 additions & 0 deletions src/styles/blocks/top-banner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.top-banner {
position: relative;
justify-content: space-between;
align-items: center;
padding-inline-start: 150px;
color: #fff;
background-color: #000;
z-index: 999;
}

.top-banner[hidden] {
display: none;
}

.top-banner::before {
content: "";
position: absolute;
inset-inline-start: 15px;
inset-block-start: calc(50% - 15px);
inline-size: 120px;
block-size: 30px;
background-image: url("../../images/top-banner/bat-eyes.svg");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}

.top-banner::after {
content: "";
position: absolute;
inset-inline-start: 45px;
inset-block-end: -12px;
inline-size: 60px;
block-size: 13px;
background-image: url("../../images/top-banner/bat-teeth.svg");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}

.top-banner__content {
margin: 0;
}

@media (width <= 1366px) {
.top-banner {
padding-inline-start: 110px;
}

.top-banner::before {
inset-block-start: calc(50% - 10px);
inline-size: 80px;
block-size: 20px;
}

.top-banner::after {
inset-inline-start: 33px;
inset-block-end: -8px;
inline-size: 45px;
block-size: 9px;
}
}

@media (width <= 768px) {
.top-banner {
margin-block-end: 0;
padding-inline-start: 15px;
font-size: 14px;
}

.top-banner::before, .top-banner::after {
display: none;
}

.top-banner__button {
padding-block: 0.3em;
}
}
1 change: 1 addition & 0 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@
@import url("blocks/subscribe-popup.css");
@import url("blocks/subscribe-page.css");
@import url("blocks/baseline.css");
@import url("blocks/top-banner.css");
5 changes: 5 additions & 0 deletions src/views/article-index.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}

{% set isLogoContrastColor = hasCategory %}

{{ topBanner(
isMainPage=false
) }}

{% set iconEditPlaceholder %}<span class="articles-group__placeholder-icon font-theme font-theme--code" aria-hidden="true"></span>{% endset %}

{{ header(
Expand Down
5 changes: 5 additions & 0 deletions src/views/doc.njk
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}
{% from "blocks/article-image.njk" import articleImage %}
{% from "blocks/linked-article.njk" import linkedArticle %}

{% set isLogoContrastColor = hasCategory %}

{{ topBanner(
isMainPage=false
) }}

{{ header(
pageCategoryId=category,
category=categoryName,
Expand Down
5 changes: 5 additions & 0 deletions src/views/index.njk
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}
{% from "promos/" + promoData.design + ".njk" import promo with context %}

{% set isLogoContrastColor = hasCategory %}

{{ topBanner(
isMainPage=true
) }}

{{ header(
isLogoContrastColor=isLogoContrastColor,
isMainPage=true
Expand Down
5 changes: 5 additions & 0 deletions src/views/page.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}

{% set isLogoContrastColor = hasCategory %}

{{ topBanner(
isMainPage=false
) }}

{{ header(
title=title,
isLogoContrastColor=isLogoContrastColor
Expand Down
6 changes: 6 additions & 0 deletions src/views/people.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}
{% from "blocks/person.njk" import person %}

Expand All @@ -22,6 +23,11 @@
{% endmacro %}

<div class="people-page">

{{ topBanner(
isMainPage=false
) }}

{{ header(
pageCategoryId='people',
category=title,
Expand Down
6 changes: 6 additions & 0 deletions src/views/person.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "blocks/header.njk" import header with context %}
{% from "blocks/top-banner.njk" import topBanner with context %}
{% from "blocks/footer.njk" import footer with context %}
{% from "blocks/person-avatar.njk" import personAvatar %}
{% from "blocks/person-badges.njk" import personBadges %}
Expand Down Expand Up @@ -57,6 +58,11 @@
{% endset %}

<div class="person-page">

{{ topBanner(
isMainPage=false
) }}

{{ header(
pageCategoryId='people',
category=categoryName,
Expand Down
Loading