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

Add originalEvent to eventListeners #26336

Closed
jakubhonisek opened this issue Apr 18, 2018 · 8 comments
Closed

Add originalEvent to eventListeners #26336

jakubhonisek opened this issue Apr 18, 2018 · 8 comments

Comments

@jakubhonisek
Copy link
Contributor

Add originalEvent to bootstrap eventListeners like hide.bs.dropdown, if support it.

I need to know, which element was clicked, before a dropdown was closed. I tried to add this code to the Dropdown._clearMenus function in dropdown.js file (after the definition of the relatedTarget variable).

if (event) { relatedTarget.original = event.originalEvent; }

This code snippet make the originalEvent accessible from the hide.bs.dropdown event. For other events may be used similar way.

@Johann-S
Copy link
Member

you already know which element was clicked before the dropdown was closed by relatedTarget 🤔

@jakubhonisek
Copy link
Contributor Author

In relatedTarget is toggle element (link, button), but i need to know, which element was actually clicked. For example: if you click to body or some element inside dropdown, like p, span etc., the dropdown will close. I need to know the actually clicked element, because i want, for example, stop closing dropdown, if the element has certain class.

@Johann-S
Copy link
Member

Hmm ok, understood thanks 👍

@morrissey-ingenious
Copy link
Contributor

You could include something like this above where you include bootstrap js.

       $(document).on('click', function(e){
          if($(e.target).hasClass('prevent-dropdown-close')){
            e.stopImmediatePropagation();
            return false;
          }
        });

If you want to modify the function you were with something like this.

    static _clearMenus(event) {
      if(event && $(event.target).hasClass('prevent-dropdown-close')){
        return;
      }

@alecpl
Copy link
Contributor

alecpl commented Apr 19, 2018

This is similar/the same request to my #24010.

@Johann-S
Copy link
Member

thats right ! Thanks @alecpl, so close for consistency 👍

@ondrajodas
Copy link

@morrissey-ingenious: But this modification stops propagation all click on the page. I have the same problem.

@Johann-S Will you modify dropdown.js?

@Johann-S
Copy link
Member

When I'll have time to work on that @ondrajodas, but every issues are open, so if someone want to fix this issue he should do it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants