<!-- copilp.ru UC DEV MODS · Умная шапка сайта · v1.0 -->
<script>
/* ---------- НАСТРОЙКИ ---------- */
window.DEV_HEADER_OFFSET = 140; // скролл, после которого прятать
window.DEV_HEADER_SENSITIVITY = 6; // порог движения, px
window.DEV_HEADER_PROGRESS = true; // полоска прогресса
window.DEV_HEADER_SELECTOR = ''; // свой селектор, если нужно
window.DEV_HEADER_LINE_COLOR = '#77ed6c'; // цвет полоски
window.DEV_HEADER_RETRIES = 40; // попыток поиска (×300 мс)
window.DEV_HEADER_DEBUG = true; // логи в консоль
/* ✨ ПЛАВНОСТЬ ✨
Длительность анимации ухода/возврата в секундах.
Мягкие значения: .5 — .7 — .9
Совсем плавно (медленно): 1.1 — 1.4 */
window.DEV_HEADER_SPEED = 0.9;
/* Кривая анимации (CSS cubic-bezier). Варианты:
'cubic-bezier(.16,1,.3,1)' — быстрый старт, мягкое торможение (по умолчанию)
'cubic-bezier(.4,0,.2,1)' — классический ease-in-out, «тягучий»
'cubic-bezier(.22,.61,.36,1)' — очень мягкий (ease-out)
'ease' — стандартный CSS */
window.DEV_HEADER_EASING = 'cubic-bezier(.16,1,.3,1)';
/* --------------------------------- */
(function () {
'use strict';
var OFFSET = window.DEV_HEADER_OFFSET || 140;
var SENS = window.DEV_HEADER_SENSITIVITY || 6;
var PROGRESS = window.DEV_HEADER_PROGRESS !== false;
var COLOR = window.DEV_HEADER_LINE_COLOR || '#77ed6c';
var RETRIES = window.DEV_HEADER_RETRIES || 40;
var DEBUG = window.DEV_HEADER_DEBUG !== false;
var SPEED = window.DEV_HEADER_SPEED || 0.9; // секунды
var EASING = window.DEV_HEADER_EASING || 'cubic-bezier(.16,1,.3,1)';
function log() {
if (DEBUG && window.console) console.log.apply(console, ['[UC Header]'].concat([].slice.call(arguments)));
}
/* Поиск шапки */
function findHeader() {
if (window.DEV_HEADER_SELECTOR) {
var c = document.querySelector(window.DEV_HEADER_SELECTOR);
if (c) return c;
}
var sels = [
'.uc-dev-smart-header',
'.t228__container', '.t228',
'.t-zoce-header',
'header.t-header', '.t-header'
];
for (var i = 0; i < sels.length; i++) {
var el = document.querySelector(sels[i]);
if (el) return el;
}
return null;
}
/* Если внешний .t-rec имеет высоту 0 — ищем видимого ребёнка */
function resolveVisible(header) {
var h = header.offsetHeight;
if (h > 5) return { el: header, height: h };
log('высота внешнего блока =', h, '— ищу видимого ребёнка');
var found = null;
(function walk(node) {
if (found) return;
for (var i = 0; i < node.children.length; i++) {
var ch = node.children[i];
if (ch.offsetHeight > 5) {
var cs = getComputedStyle(ch);
if (cs.display !== 'none' && cs.visibility !== 'hidden') { found = ch; return; }
}
walk(ch);
if (found) return;
}
})(header);
if (found) {
log('найден видимый контейнер:', found, 'высота:', found.offsetHeight);
return { el: found, height: found.offsetHeight };
}
log('видимого контейнера не нашлось');
return { el: header, height: h };
}
function start() {
var header = findHeader();
if (!header) { log('шапка не найдена'); return false; }
if (header.__ucInit) { log('уже инициализирована'); return true; }
header.__ucInit = true;
var v = resolveVisible(header);
var target = v.el;
var height = v.height;
log('фиксирую:', target, 'высота:', height, 'плавность:', SPEED + 's');
/* ---------- Стили ---------- */
if (!document.getElementById('uc-dev-styles')) {
var st = document.createElement('style');
st.id = 'uc-dev-styles';
st.textContent =
'.uc-dev-smart-header{' +
'position:fixed !important;' +
'top:0 !important;' +
'left:0 !important;' +
'right:0 !important;' +
'width:100% !important;' +
'z-index:9998 !important;' +
/* ✨ длительность и кривая берутся из настроек */
'transition:top ' + SPEED + 's ' + EASING + ';' +
'will-change:top;' +
'}' +
'.uc-dev-hidden{' +
'top:-250px !important;' +
'}' +
'.uc-dev-line{' +
'position:absolute;left:0;bottom:0;height:2px;width:0;' +
'background:' + COLOR + ';z-index:9999;pointer-events:none;' +
'box-shadow:0 0 8px ' + COLOR + '88;' +
'transition:width .1s linear;' +
'}' +
'@media (prefers-reduced-motion: reduce){' +
'.uc-dev-smart-header{transition:none}' +
'.uc-dev-line{transition:none}' +
'}';
document.head.appendChild(st);
}
target.classList.add('uc-dev-smart-header');
/* Спейсер, чтобы контент не прыгал */
if (height > 5 && !document.getElementById('uc-dev-spacer')) {
var sp = document.createElement('div');
sp.id = 'uc-dev-spacer';
sp.style.cssText = 'height:' + height + 'px;pointer-events:none;visibility:hidden';
if (target.parentNode) {
target.parentNode.insertBefore(sp, target.nextSibling);
log('спейсер добавлен, высота', height);
}
}
/* Полоска прогресса */
var line = null;
if (PROGRESS) {
line = target.querySelector('.uc-dev-line');
if (!line) {
line = document.createElement('div');
line.className = 'uc-dev-line';
target.appendChild(line);
}
}
/* Скролл */
var lastY = window.pageYOffset || 0;
var ticking = false;
function upd() {
ticking = false;
var d = document.documentElement;
var y = window.pageYOffset || d.scrollTop || 0;
var delta = y - lastY;
if (y > OFFSET && delta > SENS) {
target.classList.add('uc-dev-hidden');
} else if (delta < -SENS || y <= OFFSET) {
target.classList.remove('uc-dev-hidden');
}
lastY = y;
if (line) {
var max = d.scrollHeight - d.clientHeight;
line.style.width = (max > 0 ? Math.min(1, y / max) * 100 : 0).toFixed(2) + '%';
}
}
function onScroll() {
if (!ticking) { ticking = true; requestAnimationFrame(upd); }
}
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onScroll, { passive: true });
target.addEventListener('focusin', function () {
target.classList.remove('uc-dev-hidden');
});
upd();
log('инициализация завершена');
return true;
}
function boot() {
if (start()) return;
var n = 0;
var t = setInterval(function () {
n++;
if (start() || n >= RETRIES) clearInterval(t);
}, 300);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', boot);
} else {
boot();
}
window.addEventListener('load', function () { setTimeout(boot, 300); });
})();
</script>