Skip to content

Adding and refactoring methods that concern Loading feature. #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits 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
76 changes: 42 additions & 34 deletions js/bootstrap-modalmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,57 +298,65 @@
this.isLoading = false;
},

removeLoading: function () {
this.$backdropHandle && this.$backdropHandle.remove();
this.$backdropHandle = null;
this.removeSpinner();
},

loading: function (callback) {
createLoading: function (callback) {
callback = callback || function () { };

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

if (!this.isLoading) {

this.$backdropHandle = this.createBackdrop('fade', this.options.backdropTemplate);
this.$backdropHandle = this.createBackdrop('fade');

this.$backdropHandle[0].offsetWidth; // force reflow
this.$backdropHandle[0].offsetWidth; // force reflow

var openModals = this.getOpenModals();
this.$backdropHandle
.css('z-index', getzIndex('backdrop', this.stack.length))
.addClass('in');

this.$backdropHandle
.css('z-index', getzIndex('backdrop', openModals.length + 1))
.addClass('in');
var $spinner = $(this.options.spinner)
.css('z-index', getzIndex('modal', this.stack.length))
.appendTo(this.$element)
.addClass('in');

var $spinner = $(this.options.spinner)
.css('z-index', getzIndex('modal', openModals.length + 1))
.appendTo(this.$element)
.addClass('in');
this.$spinner = $(this.createContainer())
.append($spinner)
.on('click.modalmanager', $.proxy(this.loading, this));

this.$spinner = $(this.createContainer())
.append($spinner)
.on('click.modalmanager', $.proxy(this.loading, this));
this.isLoading = true;

this.isLoading = true;
$.support.transition ?
this.$backdropHandle.one($.support.transition.end, callback) :
callback();
},

$.support.transition ?
this.$backdropHandle.one($.support.transition.end, callback) :
callback();
removeLoading: function () {
this.$element
.removeClass('modal-open')
.toggleClass('page-overflow', $(window).height() < this.$element.height());

} else if (this.isLoading && this.$backdropHandle) {
if (this.$backdropHandle)
this.$backdropHandle.removeClass('in');

var that = this;
$.support.transition ?
this.$backdropHandle.one($.support.transition.end, function () { that.removeLoading() }) :
that.removeLoading();
function remove() {
this.$backdropHandle && this.$backdropHandle.remove();
this.$backdropHandle = null;
this.removeSpinner();
}
var that = this;
$.support.transition && this.$backdropHandle ?
this.$backdropHandle.one($.support.transition.end, function () { remove.call(that); }) :
remove.call(that);
},

} else if (callback) {
loading: function (callback) {
callback = callback || function () {};

if (!this.isLoading)
this.createLoading(callback);
else if (this.isLoading && this.$backdropHandle)
this.removeLoading(callback);
else if (callback)
callback(this.isLoading);
}
}
};

Expand Down