javascript - Check if starSpin() is already running and stop it using stopSpin() in case it is running -
i using spin.js show spinner before data gets loaded on screen. have several tabs. everytime, click on tab, shows spinner , have kept stopspin() inside function when data gets loaded, spinner stop.
this runs fine in normal condition. user clicks tab -- spinner starts -- data gets loaded-- spinner stops.
but when click on tab , @ moment click on other tab, spinner keeps on spinning. spinner of first tab clicked. didnt let complete function run , when clicked on other tab, new spinner got loaded , stops. first tabs spinner continues spin...
is there way check if can see if spinner running , stop if @ running.
**\$("#rpt21 a.keepopen").click(function(){ \$("#report_panel").html(""); \$("#report_panel,#report_header,#report_panel_alldata,#report_header_alldata").hide();
$get_parameters; startspin(); x = getdataforrpt(rmanager,manager,account,folderdate,pricedate,"buy_list","$tmp_rpt_folder","$tmp_rpt","runrpt"); \$("#report_panel").show(); });**
**
function getdataforrpt(rmanager,manager,account,folderdate,pricedate,rpt_name,tmp_folder,tmp_rpt,action) { var perlurl= "$thiscode"; \$.ajax({ url: perlurl, data: {rmanager: rmanager, manager: manager, account: account, folderdate: folderdate, pricedate: pricedate, rpt_name: rpt_name, tmp_folder: tmp_folder, tmp_rpt: tmp_rpt, action: action }, success: function(result) { if(result.isok == false){ alert("no data");} //\$("#report_panel").load("$url_link/webtmp/$tmp_rpt"); \$("#report_panel").html("<object data='$url_link/webtmp/$tmp_rpt' , type='text/html' width=97% height=100%></object>"); //\$("#report_panel").html('<object data="http://apmqa.mcm.com/webtmp/web_table_rpt.html" type="text/html" width=1000 height=500 ></object>'); //\$("#report_panel").load("http://apmqa.mcm.com/webtmp/test_web_table_rpt.html"); stopspin(); }, }); }
**
you can see here have used start spin when tab clicked. there several functions , each has startspin() in it.
the getdataforrpt common. have kept 1 stopspin() there.
i got answer this. if wants know, here is.
**function startspin(){ startspin.called = true; var target = document.getelementbyid('spin_container'); var spinner = new spinner(opts).spin(target); \$('#spin_container').data('spinner', spinner); }**
insert startspin.called = true; in main function , type below wherever want spinner load. way, check if spinner active or not. if active, stop original spinner first , proceed next function.
**if (startspin.called){ stopspin();`enter code here`
}**
Comments
Post a Comment