2011-02-04 4 views
1

여러 개의 열기/닫기 모달 요청과 동시에 함수를 만들어야합니다.Simplemodal 객체에 대한 동시 호출

exemple 들어

: 내가 showAjaxLoading (true)를 호출하면, 그것은 모달을 보여주는, 그리고 (false)를 showAjaxLoading 그것은 모달를 배치하는 것.

문제 : 내가 처음으로 모달을 보여줄 것을 요청할 때, 또 다른 빠른 요청으로 닫을 수 있습니다. 배열에 모든 요청을 보관하고 마지막 요청이 끝난 경우에만 모달을 삭제할 수 있기를 원합니다.

SimpleModal : 개체 simplemodal은 고유합니다. 모달을 만들면 객체 자체를 반환합니다. 그러나 이미 모달이 열려 있으면 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(); 
     }; 
    }; 
}; 

?

답변

2
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 
     } 
    } 
} 

것은이 같은 시도/이제 때마다 당신이 AJAX 요청을하고 modalDialog.hideAjaxLoading() 할 때마다이 요청이 완료 modalDialog.showAjaxLoading()를 호출 할 수 있습니다.

관련 문제