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

mouseUp on overlay is closing modal

Open VascoRatoFCCN opened this issue 3 years ago • 0 comments

Recently I was selecting some text on a modal and ended up with the mouse cursor outside the modal. To my surprise, this closed the modal! You can test this behavior on the first example on the jQuery modal website:

image

In my eyes this is an undesired behavior, and it could be easily fixed by changing the following code (line 100 on jquery.modal.js):

if (this.options.clickClose)
        this.$blocker.click(function(e) {
          if (e.target === this)
            $.modal.close();
        });

with something like this:

if (this.options.clickClose) {
    if (!this.$blocker.properties) {
        this.$blocker.properties = {};
    }
    this.$blocker.properties.mousedown = false;
    this.$blocker.off('mousedown').on('mousedown', function (e) {
        if (e.target === this){
            m.$blocker.properties.mousedown = true;
        }
    });
    this.$blocker.off('mouseup').on('mouseup', function (e) {
        if (e.target === this && m.$blocker.properties.mousedown) {
            $.modal.close();
        } else {
            m.$blocker.properties.mousedown = false;
        }
    });
}

My code isn't very elegant but does the trick.

VascoRatoFCCN avatar Nov 19 '21 18:11 VascoRatoFCCN