From 60dc763f536d1b8deecde2cde7fbb720cce39df2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 14 May 2025 16:04:30 +0200 Subject: [PATCH] Bug 38899: Remove code duplication --- koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 12 ++++++++---- .../intranet-tmpl/prog/js/vue/components/Toolbar.vue | 11 ++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index b660011277a..5c4e2f63159 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -75,17 +75,21 @@ function togglePanel(node) { } } -$(document).ready(function () { - //check if sticky element is stuck, if so add floating class - if ($(".sticky").length) { +function apply_sticky(nodes) { + if (nodes) { const observer = new IntersectionObserver( ([e]) => e.target.classList.toggle("floating", e.intersectionRatio < 1), { threshold: [1] } ); - observer.observe(document.querySelector(".sticky")); + observer.observe(nodes); } +} + +$(document).ready(function () { + //check if sticky element is stuck, if so add floating class + apply_sticky(document.querySelector(".sticky")); //check for a hash before setting focus let hash = window.location.hash; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Toolbar.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Toolbar.vue index 3db1eee90b3..1e4d40da7bd 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Toolbar.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Toolbar.vue @@ -22,17 +22,10 @@ export default { observer: null, }; }, - methods: { - stickyToolbar([e]) { - e.target.classList.toggle("floating", e.intersectionRatio < 1); - }, - }, + methods: {}, mounted() { if (this.sticky) { - this.observer = new IntersectionObserver(this.stickyToolbar, { - threshold: [1], - }); - this.observer.observe(this.$refs.toolbar); + apply_sticky(this.$refs.toolbar); } }, }; -- 2.34.1