Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Fix bugs with overlays when dialog was opened from another dialog #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions jquery.dialogOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* recenter dialog - ajax loaded content
*/

(function () {

// add new options with default values
$.ui.dialog.prototype.options.clickOut = true;
$.ui.dialog.prototype.options.responsive = true;
Expand Down Expand Up @@ -143,30 +145,31 @@ $.ui.dialog.prototype.open = function () {
// close on clickOut
if (self.options.clickOut && !self.options.modal) {
// use transparent div - simplest approach (rework)
$('<div id="dialog-overlay"></div>').insertBefore(self.element.parent());
$('#dialog-overlay').css({
"position": "fixed",
"top": 0,
"right": 0,
"bottom": 0,
"left": 0,
"background-color": "transparent"
});
$('#dialog-overlay').click(function (e) {
e.preventDefault();
e.stopPropagation();
self.close();
});
self.overlay = $('<div class="dialog-overlay"></div>')
.css({
"position": "fixed",
"top": 0,
"right": 0,
"bottom": 0,
"left": 0,
"background-color": "transparent"
})
.click(function (e) {
e.preventDefault();
e.stopPropagation();
self.close();
})
.insertBefore(self.element.parent());
// else close on modal click
} else if (self.options.clickOut && self.options.modal) {
$('.ui-widget-overlay').click(function (e) {
self.overlay.click(function (e) {
self.close();
});
}

// add dialogClass to overlay
if (self.options.dialogClass) {
$('.ui-widget-overlay').addClass(self.options.dialogClass);
self.overlay.addClass(self.options.dialogClass);
}
};
//end open
Expand All @@ -179,13 +182,11 @@ $.ui.dialog.prototype.close = function () {
// apply original arguments
_close.apply(this, arguments);

// remove dialogClass to overlay
if (self.options.dialogClass) {
$('.ui-widget-overlay').removeClass(self.options.dialogClass);
}
//remove clickOut overlay
if ($("#dialog-overlay").length) {
$("#dialog-overlay").remove();
if (!self.options.modal && self.overlay) {
self.overlay.remove();
}
};
//end close

})();