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
Feature request :) noPropagateClicks #216
Comments
Here is final fork, which displaying what could be updated: There is no "preventDefault's", only stopPropagation, so all links displayed in alerts still working. |
Thanks for the details. However, I believe adding the below line after creating the root element is enough? elements.root.onclick = function(e){e.stopPropagation()} |
No, unfortunately this will not work. Because the legacy code also listens for all clicks of the root element. It's also "closable by dimmer". Let's imagine that page uses 2 libraries for modal windows. Both libraries can display popup windows, "closable by dimmer". But I would like to give an AlertifyJS higher priority for the "dimmer area", and allow Alertify alerts over another non-alertify modal windows. |
The dimmer is placed inside the root element and it's always added at the end of the document (which ensures being on top of elements having the same z-index).
How would the legacy code listen to the click events of AlertifyJS root element ? Can you provide an online sample ? |
There is following code which uses jQuery:
And in fact, that window being hidden on any click, inside or outside AlertifyJS alert box, if the "clicks propagation" not disabled. |
Yes, I was wrong when I called it "dimmer". It just listens to all clicks over document.body. I see that Alertify really adding another separate elements as "dimmer". However any "propagated" clicks closing the side windows. |
This won’t catch the clicks on the Dialog or the Dimmer if AlertifyJS root element stops event propagation. Try adding this after creating the root element.
|
@utilmind no worries! |
Hello! I have added suggested code after creating of elements.root into https://palmbeachcuisine.com/js/alertify.test.js:
However it doesn't works as expected. It still propagate event on OK button, or on Enter keypress. Here is the page which reproduces the problem: Here is how it should work: |
@utilmind When debugging through your updated version |
Yes, really :) Anyway I still prefer to have configurable noPropagateClicks. Who knows, maybe I will want to hook all clicks in one of my future project. In any case the following code works well at https://palmbeachcuisine.com/rs-test.html#BistroJupiter:
Thank you for suggestion! I hope you can make this improvement canonical :) |
v1.12.0 introduces two new global hooks ( alertify.defaults.hooks.postinit = function(instance){
instance.elements.root.onclick = function(e){e.stopPropagation()}
} |
Hello! I have added a new option in my fork, noPropagateClicks. This option prevent passing the clicks events to other event listeners, when the alert is displayed.
This has solved my problem, which was following...
My customer's website has some legacy code for the "side windows". Those windows listening for the click events of <body> and hiding itself on each click outside the window.
I must prevent them from hiding when the alert is displayed. However, unfortunately, I can't use isOpen() method to test whether the alert box is displayed. After any click on the alert's OK button or dimmer, isOpen() will return false. The side windows catching that click, recognizing it as "outside" click and hiding itself (which is wrong).
So it looks like the only solution to not pass the clicks to other listeners outside of an alert -- is to prevent their propagation.
And It would be really cool if you can add noPropagateClicks or similar option to the canonical version of AlertifyJS.
Thank you!
The text was updated successfully, but these errors were encountered: