diff --git a/jquery.modal.js b/jquery.modal.js index 7e62a4d..f70d543 100644 --- a/jquery.modal.js +++ b/jquery.modal.js @@ -97,11 +97,26 @@ var current = getCurrent(); if (event.which === 27 && current.options.escapeClose) current.close(); }); - if (this.options.clickClose) - this.$blocker.click(function(e) { - if (e.target === this) + if (this.options.clickClose) { + // Close only when the press BOTH started and ended on the overlay itself. + // The modal content lives inside the blocker, so a drag that starts on the + // content and ends on the overlay used to register as an overlay click and + // close the modal (issue #303). Arm on mousedown-target, fire on mouseup. + this.$blocker.off('mousedown.modalclickclose mouseup.modalclickclose click.modalclickclose'); + this.$blocker.on('mousedown.modalclickclose', function(e) { + m._clickCloseArmed = (e.target === this); + }); + this.$blocker.on('mouseup.modalclickclose', function(e) { + if (e.target === this && m._clickCloseArmed) { + m._clickCloseArmed = false; $.modal.close(); + } }); + // Keyboard / programmatic clicks carry no mousedown (detail === 0). + this.$blocker.on('click.modalclickclose', function(e) { + if (e.detail === 0 && e.target === this) $.modal.close(); + }); + } }, close: function() {