jquery-modal icon indicating copy to clipboard operation
jquery-modal copied to clipboard

Don't close modal when MouseUp outside of modal

Open RoflJOE opened this issue 6 years ago • 1 comments

For those of you that don't want the Modal to close when you release your mouse outside of the modal, I found a fix(workaround) for it.

Fix Search for $blocker.click in the plugin, and replace with $blocker.mousedown

This is extremely helpful if you selecting text, and sometimes doing it too quickly so the cursor is outside of the modal when releasing.

Thanks for a great plugin!

RoflJOE avatar Sep 23 '19 20:09 RoflJOE

I agree that the close shouldn't be firing on mouseup - this is especially noticeable in the use case wherein users are copying something out of the modal for pasting elsewhere; the mouseup of a click & drag text selection is closing the modal.

In the meantime, I've used a workaround that doesn't require altering the code:

  1. Instantiate with clickClose: false:
$(this).modal({
  clickClose: false,
});
  1. In the $.modal.OPEN event, add a mousedown listener to the .blocker.current element:
$('div.jquery-modal.blocker.current').mousedown(function(e) { 
  if ($(e.target).hasClass('blocker')) $.modal.close();
});

adamkempa avatar Oct 31 '19 17:10 adamkempa