Skip to content

mouseUp on overlay is closing modal  #303

@VascoRatoFCCN

Description

@VascoRatoFCCN

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions