summaryrefslogtreecommitdiffstats
path: root/web/gui/src/dashboard.js/timeout.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
commitc69cb8cc094cc916adbc516b09e944cd3d137c01 (patch)
treef2878ec41fb6d0e3613906c6722fc02b934eeb80 /web/gui/src/dashboard.js/timeout.js
parentInitial commit. (diff)
downloadnetdata-003423236c4cd249ed4246231d71a062f8f3d45a.tar.xz
netdata-003423236c4cd249ed4246231d71a062f8f3d45a.zip
Adding upstream version 1.29.3.upstream/1.29.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/gui/src/dashboard.js/timeout.js')
-rw-r--r--web/gui/src/dashboard.js/timeout.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/web/gui/src/dashboard.js/timeout.js b/web/gui/src/dashboard.js/timeout.js
new file mode 100644
index 0000000..4adf9bb
--- /dev/null
+++ b/web/gui/src/dashboard.js/timeout.js
@@ -0,0 +1,100 @@
+
+// *** src/dashboard.js/timeout.js
+
+// TODO: Better name needed
+
+NETDATA.timeout = {
+ // by default, these are just wrappers to setTimeout() / clearTimeout()
+
+ step: function (callback) {
+ return window.setTimeout(callback, 1000 / 60);
+ },
+
+ set: function (callback, delay) {
+ return window.setTimeout(callback, delay);
+ },
+
+ clear: function (id) {
+ return window.clearTimeout(id);
+ },
+
+ init: function () {
+ let custom = true;
+
+ if (window.requestAnimationFrame) {
+ this.step = function (callback) {
+ return window.requestAnimationFrame(callback);
+ };
+
+ this.clear = function (handle) {
+ return window.cancelAnimationFrame(handle.value);
+ };
+ // } else if (window.webkitRequestAnimationFrame) {
+ // this.step = function (callback) {
+ // return window.webkitRequestAnimationFrame(callback);
+ // };
+
+ // if (window.webkitCancelAnimationFrame) {
+ // this.clear = function (handle) {
+ // return window.webkitCancelAnimationFrame(handle.value);
+ // };
+ // } else if (window.webkitCancelRequestAnimationFrame) {
+ // this.clear = function (handle) {
+ // return window.webkitCancelRequestAnimationFrame(handle.value);
+ // };
+ // }
+ // } else if (window.mozRequestAnimationFrame) {
+ // this.step = function (callback) {
+ // return window.mozRequestAnimationFrame(callback);
+ // };
+
+ // this.clear = function (handle) {
+ // return window.mozCancelRequestAnimationFrame(handle.value);
+ // };
+ // } else if (window.oRequestAnimationFrame) {
+ // this.step = function (callback) {
+ // return window.oRequestAnimationFrame(callback);
+ // };
+
+ // this.clear = function (handle) {
+ // return window.oCancelRequestAnimationFrame(handle.value);
+ // };
+ // } else if (window.msRequestAnimationFrame) {
+ // this.step = function (callback) {
+ // return window.msRequestAnimationFrame(callback);
+ // };
+
+ // this.clear = function (handle) {
+ // return window.msCancelRequestAnimationFrame(handle.value);
+ // };
+ } else {
+ custom = false;
+ }
+
+ if (custom) {
+ // we have installed custom .step() / .clear() functions
+ // overwrite the .set() too
+
+ this.set = function (callback, delay) {
+ let start = Date.now(),
+ handle = new Object();
+
+ const loop = () => {
+ let current = Date.now(),
+ delta = current - start;
+
+ if (delta >= delay) {
+ callback.call();
+ } else {
+ handle.value = this.step(loop);
+ }
+ }
+
+ handle.value = this.step(loop);
+ return handle;
+ };
+ }
+ }
+};
+
+NETDATA.timeout.init();