Question

Is it possible to have many busyIndicators depending on context? I tried with 4, but it doesn't work (only the last busyIndicator seems to be used, and can't be hidden):

Here's the code:

var myBusyIndicator1;
var myBusyIndicator2;
var myBusyIndicator3;
var myBusyIndicator4;
wlCommonInit(){
   myBusyIndicator1 = new WL.BusyIndicator('content', {text : 'Loading data 1'});
   myBusyIndicator2 = new WL.BusyIndicator('content', {text : 'Loading data 2'});
   myBusyIndicator3 = new WL.BusyIndicator('content', {text : 'Loading data 3'});
   myBusyIndicator4 = new WL.BusyIndicator('content', {text : 'Loading data 4'});
}
$('#myPage').on('showpage', function(e, ui){
   myBusyIndicator1.show(); // 'Loading data 4' is displayed in modal window
   //do some stuff
   myBusyIndicator1.hide(); // modal window still, and app is not responsive anymore
});

No correct solution

OTHER TIPS

"Busy indicator is a singleton. If you create several busy indicators, show them and then hide of them - all will be hidden." - Anton (source)

You could try to wrap it in your own "singleton", for example:

var Busy = (function () {

    var busyObject;

    var _show = function (message, options) {

        //If you're using WL v6.0, 
        //see: https://stackoverflow.com/q/18501456/186909
        WL.ClientMessages.loading = message;
        //Others version of WL may not require 
        //the line above or the message parameter.

        busyObject = new WL.BusyIndicator('content', options);
        busyObject.show();
    };

    var _hide = function () {
        if (busyObject !== null) {
            busyObject.hide();
            busyObject = null;
        }
        //else no busy indicator to hide
    };

    return {
        show: _show,
        hide: _hide
    };

}());

//Usage:
Busy.show('message1', options1);
//Later...
Busy.hide();
//Later...
Busy.show('message2', options2);
//Later...
Busy.hide();

I did not test the code above, it's just meant to give the reader ideas, not to be copy/pasted into a project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top