diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-10-11 10:41:15 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-10-11 11:31:11 +0200 |
commit | d3879c07b1b2140bd19433ae06855894228bd90f (patch) | |
tree | 95d79cbf675206abaa937c3aaf964d323ec52acb /app/javascript/flavours/glitch/util/intersection_observer_wrapper.js | |
parent | 1be97ce17fa6c5635b0922ec97378360d793db59 (diff) |
Rename flavours/glitch/util into flavours/glitch/utils
Diffstat (limited to 'app/javascript/flavours/glitch/util/intersection_observer_wrapper.js')
-rw-r--r-- | app/javascript/flavours/glitch/util/intersection_observer_wrapper.js | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/app/javascript/flavours/glitch/util/intersection_observer_wrapper.js b/app/javascript/flavours/glitch/util/intersection_observer_wrapper.js deleted file mode 100644 index 2b24c6583..000000000 --- a/app/javascript/flavours/glitch/util/intersection_observer_wrapper.js +++ /dev/null @@ -1,57 +0,0 @@ -// Wrapper for IntersectionObserver in order to make working with it -// a bit easier. We also follow this performance advice: -// "If you need to observe multiple elements, it is both possible and -// advised to observe multiple elements using the same IntersectionObserver -// instance by calling observe() multiple times." -// https://developers.google.com/web/updates/2016/04/intersectionobserver - -class IntersectionObserverWrapper { - - callbacks = {}; - observerBacklog = []; - observer = null; - - connect (options) { - const onIntersection = (entries) => { - entries.forEach(entry => { - const id = entry.target.getAttribute('data-id'); - if (this.callbacks[id]) { - this.callbacks[id](entry); - } - }); - }; - - this.observer = new IntersectionObserver(onIntersection, options); - this.observerBacklog.forEach(([ id, node, callback ]) => { - this.observe(id, node, callback); - }); - this.observerBacklog = null; - } - - observe (id, node, callback) { - if (!this.observer) { - this.observerBacklog.push([ id, node, callback ]); - } else { - this.callbacks[id] = callback; - this.observer.observe(node); - } - } - - unobserve (id, node) { - if (this.observer) { - delete this.callbacks[id]; - this.observer.unobserve(node); - } - } - - disconnect () { - if (this.observer) { - this.callbacks = {}; - this.observer.disconnect(); - this.observer = null; - } - } - -} - -export default IntersectionObserverWrapper; |