• Почему не работает removeEventListener?

    Xuxicheta
    @Xuxicheta
    инженер
    const focusedCallbacks = new WeakMap();
    document.addEventListener('click', (e) => {
        let target = e.target,
            open = target.dataset.open ? target.dataset.open : 0,
            close = target.dataset.close ? target.dataset.close : 0,
            element = open || close ? document.querySelector(`[data-window=${open || close}]`) : 0,
            
    
        if (open) {
            element.classList.add(`${element.dataset.window}-open`);
            focusedCallback.set(element,trapFocus.bind(null, element));
            element.addEventListener('keydown', focusedCallback.get(element));
        }
        
        if (close) {
            element.classList.remove(`${element.dataset.window}-open`);
            element.removeEventListener('keydown', focusedCallback.get(element));
            focusedCallback.delete(element);
        }
    });
    Ответ написан
    2 комментария