73 lines
3.2 KiB
HTML
73 lines
3.2 KiB
HTML
{{ $coffeeOn := site.Params.buymeacoffee.globalWidget | default false }}
|
||
{{ $coffeePos := lower (site.Params.buymeacoffee.globalWidgetPosition | default "right") }}
|
||
{{ $coffeeOnRight := and $coffeeOn (eq $coffeePos "right") }}
|
||
{{ $scrollTopOn := site.Params.footer.showScrollToTop | default true }}
|
||
|
||
{{ $side := "right" }}
|
||
{{ $bottomPx := 24 }}
|
||
{{ if $coffeeOnRight }}
|
||
{{ $side = "left" }}
|
||
{{ else if $scrollTopOn }}
|
||
{{ $bottomPx = 90 }}
|
||
{{ end }}
|
||
|
||
<button id="survey-trigger" type="button" aria-label="Пройти опрос"
|
||
style="{{ $side }}: 20px; bottom: {{ $bottomPx }}px;">
|
||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-hidden="true"><path fill="currentColor" d="M152.1 38.2c9.9 8.9 10.7 24 1.8 33.9l-72 80c-4.4 4.9-10.6 7.8-17.2 7.9s-12.9-2.4-17.6-7L7 113C-2.3 103.6-2.3 88.4 7 79s24.6-9.4 33.9 0l22.1 22.1 55.1-61.2c8.9-9.9 24-10.7 33.9-1.8zm0 160c9.9 8.9 10.7 24 1.8 33.9l-72 80c-4.4 4.9-10.6 7.8-17.2 7.9s-12.9-2.4-17.6-7L7 273c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l22.1 22.1 55.1-61.2c8.9-9.9 24-10.7 33.9-1.8zM224 96c0-17.7 14.3-32 32-32H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H256c-17.7 0-32-14.3-32-32zm0 160c0-17.7 14.3-32 32-32H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H256c-17.7 0-32-14.3-32-32zM160 416c0-17.7 14.3-32 32-32H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H192c-17.7 0-32-14.3-32-32zM48 368a48 48 0 1 1 0 96 48 48 0 1 1 0-96z"/></svg>
|
||
<span>Опрос</span>
|
||
</button>
|
||
|
||
<script src="https://forms.yandex.ru/_static/embed.js"></script>
|
||
|
||
<div id="survey-modal" class="survey-modal" hidden>
|
||
<div class="survey-modal__overlay" data-survey-close></div>
|
||
<div class="survey-modal__box">
|
||
<button class="survey-modal__close" data-survey-close aria-label="Закрыть">×</button>
|
||
<iframe
|
||
data-src="https://forms.yandex.ru/cloud/6a6de0cc90290299827b1dca?iframe=1"
|
||
name="ya-form-6a6de0cc90290299827b1dca"
|
||
frameborder="0"
|
||
width="100%"
|
||
class="survey-modal__iframe"></iframe>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
(function () {
|
||
var article = document.querySelector('.article-content');
|
||
if (!article) return;
|
||
|
||
var DISMISS_KEY = 'survey-dismissed-until';
|
||
var DISMISS_DAYS = 14;
|
||
var SCROLL_THRESHOLD = 0.55;
|
||
|
||
var trigger = document.getElementById('survey-trigger');
|
||
var modal = document.getElementById('survey-modal');
|
||
var iframe = modal ? modal.querySelector('iframe') : null;
|
||
if (!trigger || !modal) return;
|
||
|
||
if (Date.now() < Number(localStorage.getItem(DISMISS_KEY) || 0)) return;
|
||
|
||
function onScroll() {
|
||
var rect = article.getBoundingClientRect();
|
||
if (rect.height > 0 && (window.innerHeight - rect.top) / rect.height >= SCROLL_THRESHOLD) {
|
||
trigger.classList.add('is-visible');
|
||
window.removeEventListener('scroll', onScroll);
|
||
}
|
||
}
|
||
window.addEventListener('scroll', onScroll, { passive: true });
|
||
onScroll();
|
||
|
||
trigger.addEventListener('click', function () {
|
||
if (iframe && !iframe.src) { iframe.src = iframe.dataset.src; }
|
||
modal.hidden = false;
|
||
});
|
||
modal.querySelectorAll('[data-survey-close]').forEach(function (el) {
|
||
el.addEventListener('click', function () {
|
||
modal.hidden = true;
|
||
localStorage.setItem(DISMISS_KEY, Date.now() + DISMISS_DAYS * 86400000);
|
||
});
|
||
});
|
||
})();
|
||
</script>
|