Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 9 additions & 8 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

this.tab();

this.isLoading && this.loading();
this.removeLoading();

$(document).off('focusin.modal');

Expand Down Expand Up @@ -221,10 +221,13 @@
.trigger('hidden');
},

removeLoading: function () {
this.$loading.remove();
removeLoading: function (callback) {
this.$loading && this.$loading.remove();

this.$loading = null;
this.isLoading = false;

if (callback) callback.call();
},

loading: function (callback) {
Expand Down Expand Up @@ -253,12 +256,10 @@
this.$loading.removeClass('in');

var that = this;
$.support.transition && this.$element.hasClass('fade')?
this.$loading.one($.support.transition.end, function () { that.removeLoading() }) :
that.removeLoading();

} else if (callback) {
callback(this.isLoading);
$.support.transition && this.$element.hasClass('fade') ?
this.$loading.one($.support.transition.end, function () { that.removeLoading(callback) }) :
that.removeLoading(callback);
}
},

Expand Down
44 changes: 37 additions & 7 deletions js/bootstrap-modalmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@

var transition = $.support.transition && modal.$element.hasClass('fade');

that.$element
.toggleClass('modal-open', that.hasOpenModal())
.toggleClass('page-overflow', $(window).height() < that.$element.height());
toggleOverflow(that, function() {
this.$element
.toggleClass('modal-open', this.hasOpenModal())
.toggleClass('page-overflow', $(window).height() < this.$element.height());
});

modal.$parent = modal.$element.parent();

Expand Down Expand Up @@ -138,7 +140,9 @@

var hasOpenModal = this.hasOpenModal();

this.$element.toggleClass('modal-open', hasOpenModal);
toggleOverflow(this, function() {
this.$element.toggleClass('modal-open', hasOpenModal);
});

if (!hasOpenModal){
this.$element.removeClass('page-overflow');
Expand Down Expand Up @@ -312,9 +316,11 @@
loading: function (callback) {
callback = callback || function () { };

this.$element
.toggleClass('modal-open', !this.isLoading || this.hasOpenModal())
.toggleClass('page-overflow', $(window).height() < this.$element.height());
toggleOverflow(this, function() {
this.$element
.toggleClass('modal-open', !this.isLoading || this.hasOpenModal())
.toggleClass('page-overflow', $(window).height() < this.$element.height());
});

if (!this.isLoading) {

Expand Down Expand Up @@ -396,6 +402,30 @@
}
}

// Allows to avoid visible body resizing when modal is appended
// Supposed to work properly only with body and if initial margin was 0
function toggleOverflow(elem, block) {
var current_margin = parseInt(elem.$element.css("marginRight"));

if (elem.$element[0].initialMargin === undefined) {
elem.$element[0].initialMargin = current_margin;
}

if (elem.$element[0].tagName == "BODY" && elem.$element[0].initialMargin === 0) {
var width_was = elem.$element.width();

block.call(elem);

var width_become = elem.$element.width(),
width_diff = width_become - width_was;

if (width_diff !== 0) {
elem.$element.css({ marginRight: current_margin + width_diff + "px" });
}
} else {
block.call(elem);
}
}

/* MODAL MANAGER PLUGIN DEFINITION
* ======================= */
Expand Down