Skip to content
Snippets Groups Projects
Select Git revision
  • 1cc6bdd3c578ac7c8c2e1e56274603b9f8e8fe49
  • main default protected
  • simplified
3 results

docker-compose.yml

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Popup.mjs 1.71 KiB
    const TIMEOUT = 800;
    let unlock = true;
    
    const lockPaddingElements = document.querySelectorAll('.lock-padding');
    
    function bodyLock() {
      const lockPaddingValue = `${
        window.innerWidth - document.querySelector('.wrapper').offsetWidth
      }px`;
    
      if (lockPaddingValue.length > 0)
        for (let i = 0; i < lockPaddingElements.length; i++) {
          const el = lockPaddingElements[i];
          el.style.paddingRight = lockPaddingValue;
        }
    
      document.body.style.paddingRight = lockPaddingValue;
      document.body.classList.add('lock');
    
      unlock = false;
      setTimeout(() => {
        unlock = true;
      }, TIMEOUT);
    }
    
    function bodyUnlock() {
      setTimeout(() => {
        for (let i = 0; i < lockPaddingElements.length; i++) {
          const el = lockPaddingElements[i];
          el.style.paddingRight = '0px';
        }
    
        document.body.style.paddingRight = '0px';
        document.body.classList.remove('lock');
      }, TIMEOUT);
    
      unlock = false;
      setTimeout(() => {
        unlock = true;
      }, TIMEOUT);
    }
    
    export default class Popup {
      static close(popupActive, doUnlock = true) {
        if (unlock) {
          popupActive.classList.remove('open');
          if (doUnlock) bodyUnlock();
        }
      }
    
      static closeOnEscape(event) {
        if (event.key === 'Escape') {
          const popupActive = document.querySelector('.popup.open');
          this.close(popupActive);
        }
      }
    
      static open(currentPopup) {
        if (currentPopup && unlock) {
          const popupActive = document.querySelector('.popup.open');
    
          if (popupActive) this.close(popupActive, false);
          else bodyLock();
    
          currentPopup.classList.add('open');
          currentPopup.addEventListener('click', (e) => {
            if (!e.target.closest('.popup__content')) this.close(e.target.closest('.popup'));
          });
        }
      }
    }