Skip to content

Commit 38f07c7

Browse files
committed
feat: Add new option to append the backdrop to any element. FIxes kylefox#260
1 parent a8b9c9b commit 38f07c7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ $.modal.defaults = {
190190
// HTML appended to the default spinner during AJAX requests.
191191
spinnerHtml: '<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div>',
192192

193-
showSpinner: true, // Enable/disable the default spinner during AJAX requests.
194-
fadeDuration: null, // Number of milliseconds the fade transition takes (null means no transition)
195-
fadeDelay: 1.0 // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
193+
showSpinner: true, // Enable/disable the default spinner during AJAX requests.
194+
fadeDuration: null, // Number of milliseconds the fade transition takes (null means no transition)
195+
fadeDelay: 1.0, // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
196+
backdropParent: $('body') // Blocker parent element. (defaults to the <body>)
196197
};
197198
```
198199

jquery.modal.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114

115115
block: function() {
116116
this.$elm.trigger($.modal.BEFORE_BLOCK, [this._ctx()]);
117-
this.$body.css('overflow','hidden');
118-
this.$blocker = $('<div class="' + this.options.blockerClass + ' blocker current"></div>').appendTo(this.$body);
117+
this.options.backdropParent.css('overflow','hidden');
118+
this.$blocker = $('<div class="' + this.options.blockerClass + ' blocker current"></div>').appendTo(this.options.backdropParent);
119119
selectCurrent();
120120
if(this.options.doFade) {
121121
this.$blocker.css('opacity',0).animate({opacity: 1}, this.options.fadeDuration);
@@ -127,12 +127,12 @@
127127
if (!now && this.options.doFade)
128128
this.$blocker.fadeOut(this.options.fadeDuration, this.unblock.bind(this,true));
129129
else {
130-
this.$blocker.children().appendTo(this.$body);
130+
this.$blocker.children().appendTo(this.options.backdropParent);
131131
this.$blocker.remove();
132132
this.$blocker = null;
133133
selectCurrent();
134134
if (!$.modal.isActive())
135-
this.$body.css('overflow','');
135+
this.options.backdropParent.css('overflow','');
136136
}
137137
},
138138

@@ -212,7 +212,8 @@
212212
showSpinner: true,
213213
showClose: true,
214214
fadeDuration: null, // Number of milliseconds the fade animation takes.
215-
fadeDelay: 1.0 // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
215+
fadeDelay: 1.0, // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
216+
backdropParent: $('body') // Blocker parent
216217
};
217218

218219
// Event constants

0 commit comments

Comments
 (0)