Vinoteca: wine shop on 1C-Bitrix (module, template, components, pages)
This commit is contained in:
commit
0590195880
593 files changed
+27942
No files matched your search
@@ -0,0 +1,50 @@
|
||||
(function () {
|
||||
function init() {
|
||||
var btn = document.querySelector('[data-mega-toggle]'), panel = document.querySelector('[data-mega]');
|
||||
if(!btn || !panel) return;
|
||||
var header = document.querySelector('[data-header]');
|
||||
function set(open){
|
||||
panel.hidden = !open;
|
||||
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
|
||||
btn.classList.toggle('vino-catalog-btn--open', open);
|
||||
if(header) header.classList.toggle('vino-header--mega', open);
|
||||
}
|
||||
var canHover = window.matchMedia('(hover: hover) and (pointer: fine)');
|
||||
var openTimer = 0, closeTimer = 0;
|
||||
function enter(){
|
||||
if(!canHover.matches) return;
|
||||
clearTimeout(closeTimer);
|
||||
if(panel.hidden){ clearTimeout(openTimer); openTimer = setTimeout(function(){ set(true); }, 150); }
|
||||
}
|
||||
function leave(){
|
||||
if(!canHover.matches) return;
|
||||
clearTimeout(openTimer);
|
||||
closeTimer = setTimeout(function(){ set(false); }, 300);
|
||||
}
|
||||
[btn, panel].forEach(function(el){ el.addEventListener('mouseenter', enter); el.addEventListener('mouseleave', leave); });
|
||||
btn.addEventListener('click', function(e){
|
||||
if(canHover.matches || !panel.hidden) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
set(true);
|
||||
});
|
||||
var skipFocus = false;
|
||||
btn.addEventListener('focus', function(){
|
||||
if(skipFocus){ skipFocus = false; return; }
|
||||
if(btn.matches(':focus-visible')) set(true);
|
||||
});
|
||||
function focusOut(){
|
||||
setTimeout(function(){
|
||||
var a = document.activeElement;
|
||||
if(!panel.hidden && a !== btn && !panel.contains(a) && !btn.matches(':hover') && !panel.matches(':hover')) set(false);
|
||||
}, 0);
|
||||
}
|
||||
btn.addEventListener('blur', focusOut);
|
||||
panel.addEventListener('focusout', focusOut);
|
||||
document.addEventListener('click', function(e){ if(!panel.hidden && (e.target.closest('[data-sommelier-open]') || (!panel.contains(e.target) && !btn.contains(e.target)))) set(false); });
|
||||
document.addEventListener('keydown', function(e){ if(e.key === 'Escape' && !panel.hidden){ set(false); skipFocus = true; btn.focus(); } });
|
||||
var compact = window.matchMedia('(max-width: 980px)');
|
||||
window.addEventListener('resize', function(){ if(!panel.hidden && compact.matches) set(false); });
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init();
|
||||
})();
|
||||
Reference in new issue
Block a user