From a43e2d3efab6008a6e3c52be9bf44c9d872139c4 Mon Sep 17 00:00:00 2001
From: Lucas Gass <lucas@bywatersolutions.com>
Date: Wed, 24 Apr 2024 23:18:15 +0000
Subject: [PATCH] Bug 36694: Add JS observer to detect stuck sticky element

---
 koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
index 71db55ae88..9a4b3cb6fc 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
@@ -60,6 +60,16 @@ $.fn.selectTabByID = function (tabID) {
 };
 
 $(document).ready(function () {
+    //check if sticky element is stuck, if so add floating class
+    if ( $('#toolbar.sticky').length ) {
+      const observer = new IntersectionObserver(
+        ([e]) => e.target.classList.toggle('floating', e.intersectionRatio < 1),
+        {threshold: [1]}
+      );
+
+      observer.observe(document.querySelector('.sticky'));
+    }
+
     //check for a hash before setting focus
     let hash = window.location.hash;
     if (!hash) {
-- 
2.30.2