Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added minimize button to popup #1949

Merged
merged 5 commits into from
Mar 20, 2024
Merged

Added minimize button to popup #1949

merged 5 commits into from
Mar 20, 2024

Conversation

huggla
Copy link
Contributor

@huggla huggla commented Jan 22, 2024

This is my attempt to add a minimize button to popup (fix for #1945). It works, but I would appreciate if someone with more experience could make the code less ugly.

@huggla huggla marked this pull request as draft January 22, 2024 12:26
@huggla
Copy link
Contributor Author

huggla commented Jan 22, 2024

image
image

@Grammostola
Copy link
Contributor

I think it's a neat feature. Running the default map config and infoclicking an Origo city makes the overlay not show its contents and move to the right?

As for pretty you could formulate it like the close button's event, meaning no event handler declaration in the html string:

          <button id="o-minimize-button" class="small round margin-top-smaller margin-bottom-auto margin-right-small icon-smallest grey-lightest no-shrink" aria-label="Minimera">
            <span class="icon ">_</span>
          </button>

then a function where the other functions reside:

function minimizePopup() {
  const oidentify = document.getElementById('o-identify');
  const opopup = document.getElementById('o-popup');
  oidentify.style.display = oidentify.style.display === 'none' ? 'block' : 'none';
  opopup.style.width = oidentify.style.display === 'none' ? 'auto' : null;
}

then the event handler by the close one:

  function bindUIActions() {
    const closeel = document.querySelector('#o-popup .o-popup #o-close-button');
    closeel.addEventListener('click', (evt) => {
      closePopupInternal(closeCb);
      evt.preventDefault();
    });

    const minel = document.querySelector('#o-popup .o-popup #o-minimize-button');
    minel.addEventListener('click', (evt) => {
      minimizePopup();
      evt.preventDefault();
    });
  }

Something along those lines is what I would try anyways.

Code suggestion from Grammostola
@huggla huggla marked this pull request as ready for review February 28, 2024 12:54
@huggla
Copy link
Contributor Author

huggla commented Feb 29, 2024 via email

@huggla
Copy link
Contributor Author

huggla commented Feb 29, 2024

Also, what are the pros, in this case, to adding event listeners at runtime vs. having them in the static html? (I'm trying to learn)

@Grammostola
Copy link
Contributor

Grammostola commented Mar 1, 2024

s (evt) => {} shorthand for function(evt) {}?

yes

What is the purpose of evt.preventDefault()? Is it strictly needed?

Based on my non-complete understanding the preventDefault method prevents the default browser method. What's the default browser method of a button click? There doesn't seem to be one. Removing it doesn't have an obvious effect so I would probably suggest that. (I merely echoed the existing button's setup in the example above. You are right to question what doesn't seem right)

Why not simply write minel.addEventListener('click', minimizePopup);?

No reason but to keep things consistent. That's not a hard requirement though so I'd call it optional. And your way still has access to the event object (even if we don't appear to need it)

Also, what are the pros, in this case, to adding event listeners at runtime vs. having them in the static html?

Writing code as a string is unpleasant and hard to maintain for one

As for the functionality, when I test it with the default Origo map config the minimize click makes the popup go sideways.

@huggla
Copy link
Contributor Author

huggla commented Mar 1, 2024

Thanks for your clarification and input. I can confirm that the button doesn't work in the default configuration and I'll try to fix it.

@huggla
Copy link
Contributor Author

huggla commented Mar 1, 2024

I think it should be fixed now.

@Grammostola
Copy link
Contributor

Lgtm (the preventDefault() can both be removed in a separate pr some other time)

@huggla huggla merged commit 1bc7516 into origo-map:master Mar 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants