|
20 | 20 | // |
21 | 21 | // var netdataRegistryAfterMs = 1500 // the time to consult to registry on startup |
22 | 22 | // |
| 23 | +// var netdataCallback = null; // a function to call when netdata is ready |
| 24 | +// // netdata will be running while this is called (call NETDATA.pause to stop it) |
| 25 | +// var netdataPrepCallback = null; // a callback to be called before netdata does anything else |
| 26 | +// |
23 | 27 | // You can also set the default netdata server, using the following. |
24 | 28 | // When this variable is not set, we assume the page is hosted on your |
25 | 29 | // netdata server already. |
|
3476 | 3480 |
|
3477 | 3481 | // Registry initialization |
3478 | 3482 | setTimeout(NETDATA.registry.init, netdataRegistryAfterMs); |
| 3483 | + |
| 3484 | + if(typeof netdataCallback === 'function') |
| 3485 | + netdataCallback(); |
3479 | 3486 | }; |
3480 | 3487 |
|
3481 | 3488 | // ---------------------------------------------------------------------------------------------------------------- |
|
5546 | 5553 | } |
5547 | 5554 | ]; |
5548 | 5555 |
|
| 5556 | + NETDATA.loadedRequiredJs = 0; |
5549 | 5557 | NETDATA.loadRequiredJs = function(index, callback) { |
5550 | | - if(index >= NETDATA.requiredJs.length) { |
5551 | | - if(typeof callback === 'function') |
5552 | | - callback(); |
5553 | | - return; |
5554 | | - } |
| 5558 | + if(index >= NETDATA.requiredJs.length) return; |
5555 | 5559 |
|
5556 | 5560 | if(NETDATA.requiredJs[index].isAlreadyLoaded()) { |
| 5561 | + NETDATA.loadedRequiredJs++; |
5557 | 5562 | NETDATA.loadRequiredJs(++index, callback); |
5558 | 5563 | return; |
5559 | 5564 | } |
|
5564 | 5569 | $.ajax({ |
5565 | 5570 | url: NETDATA.requiredJs[index].url, |
5566 | 5571 | cache: true, |
| 5572 | + async: true, |
5567 | 5573 | dataType: "script", |
5568 | 5574 | xhrFields: { withCredentials: true } // required for the cookie |
5569 | 5575 | }) |
5570 | 5576 | .done(function() { |
5571 | 5577 | if(NETDATA.options.debug.main_loop === true) |
5572 | 5578 | console.log('loaded ' + NETDATA.requiredJs[index].url); |
5573 | | - |
5574 | | - NETDATA.loadRequiredJs(++index, callback); |
5575 | 5579 | }) |
5576 | 5580 | .fail(function() { |
5577 | 5581 | alert('Cannot load required JS library: ' + NETDATA.requiredJs[index].url); |
5578 | 5582 | }) |
| 5583 | + .always(function() { |
| 5584 | + NETDATA.loadedRequiredJs++; |
| 5585 | + if(typeof callback === 'function' && NETDATA.loadedRequiredJs >= NETDATA.requiredJs.length) |
| 5586 | + callback(); |
| 5587 | + }) |
| 5588 | + |
| 5589 | + NETDATA.loadRequiredJs(++index, callback); |
5579 | 5590 | }; |
5580 | 5591 |
|
5581 | 5592 | NETDATA.loadRequiredCSS = function(index) { |
|
6113 | 6124 | // ---------------------------------------------------------------------------------------------------------------- |
6114 | 6125 | // Boot it! |
6115 | 6126 |
|
| 6127 | + if(typeof netdataPrepCallback === 'function') |
| 6128 | + netdataPrepCallback(); |
| 6129 | + |
6116 | 6130 | NETDATA.errorReset(); |
6117 | 6131 | NETDATA.loadRequiredCSS(0); |
6118 | 6132 |
|
|
0 commit comments