I have to make a function concurrent to multiple open/close modal requests.
开发者_JAVA百科For exemple: When i call showAjaxLoading(true), it's showing the modal, and showAjaxLoading(false) it's disposing the modal.
The Problem: When i make a first long request to showing the modal, and another one quick request will close it. I want to be able keeping in a array all the requests and disposing the modal only when the last request is ended.
SimpleModal: The object simplemodal is unique. When you create the modal it return the object itself. But when you have a modal already open, it returns false. url: http://www.ericmmartin.com/projects/simplemodal/
var showAjaxLoading = function (show) {
var ajaxModal;
if (show) {
var aModal = $("#ajaxLoading").modal({ overlayId: 'ajaxloading-overlay', containerId: 'ajaxloading-container', closeClass: 'ajaxloading-close', close: false, escClose: false });
if (aModal !== false) {
ajaxModal = aModal;
};
} else {
if (ajaxModal !== undefined && $.isFunction(ajaxModal.close)) {
ajaxModal.close();
};
};
};
What the is the best solution to solve this problem ?
var modalDialog = {
_requestsInProcess: 0,
showAjaxLoading : function()
{
if ( this._requestsInProcess == 0 )
{
// open overlay here
}
this._requestsInProcess++;
},
hideAjaxLoading : function()
{
this._requestsInProcess--;
if ( this._requestsInProcess == 0 )
{
// hide overlay here
}
}
}
Try something like this/ Now you can call modalDialog.showAjaxLoading() each time you making AJAX request and modalDialog.hideAjaxLoading() each time your request is completed.
精彩评论