aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2014-04-22 14:50:50 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2014-04-22 14:50:50 +0200
commitf396b9b8714fdcc191a66967a8d34b187ae8944a (patch)
treefd44a1f535cd2903e6b8efd1a10cb5435e7cab50 /plugin
parentc02d185cfd7c5077b3e296d72e5f0c879bc15bb4 (diff)
downloadfosdem-2018-presentation-f396b9b8714fdcc191a66967a8d34b187ae8944a.tar
fosdem-2018-presentation-f396b9b8714fdcc191a66967a8d34b187ae8944a.tar.gz
limit how often the notes window updates presentation states
Diffstat (limited to 'plugin')
-rw-r--r--plugin/notes/notes.html34
1 files changed, 34 insertions, 0 deletions
diff --git a/plugin/notes/notes.html b/plugin/notes/notes.html
index 2a3b2ba..9e9dfb5 100644
--- a/plugin/notes/notes.html
+++ b/plugin/notes/notes.html
@@ -244,6 +244,9 @@
}
+ // Limit to max one state update per X ms
+ handleStateMessage = debounce( handleStateMessage, 200 );
+
/**
* Creates the preview iframes.
*/
@@ -340,6 +343,37 @@
}
+ /**
+ * Limits the frequency at which a function can be called.
+ */
+ function debounce( fn, ms ) {
+
+ var lastTime = 0,
+ timeout;
+
+ return function() {
+
+ var args = arguments;
+ var context = this;
+
+ clearTimeout( timeout );
+
+ var timeSinceLastCall = Date.now() - lastTime;
+ if( timeSinceLastCall > ms ) {
+ fn.apply( context, args );
+ lastTime = Date.now();
+ }
+ else {
+ timeout = setTimeout( function() {
+ fn.apply( context, args );
+ lastTime = Date.now();
+ }, ms - timeSinceLastCall );
+ }
+
+ }
+
+ }
+
})();
</script>