Modals without duplicate event listeners #956
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the "duplicate modal listener" issue detailed in #954.
Similar to the pattern in dropdowns, check if the
click
event is already there before adding it to the modal toggles.Note that
toggleClick
is moved outside the functionmodal
. Otherwise, when callingmodal()
multiple times, duplicate events are getting bound. This is because the toggle click method is a different instance of the function each timemodal()
is called. Sticking it outside of themodal
function ensures that it's the same instance of the function used by all modals (so thee.fn === toggleClick
conditional is true when we'd expect).I wasn't sure what to do with the
else
case (whennode
is passed tobindModals
). I didn't see any usage ofbindModals
being called withnode
as an argument, but maybe that's in there for user customization? If it needs to remain there, it will need a similar "if the event exists, don't add it again" logic.