Bug 38899: Remove code duplication

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2025-05-14 16:04:30 +02:00 committed by Lucas Gass
parent 56eb4a6850
commit b44c08eb4f
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 10 additions and 13 deletions

View File

@ -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;

View File

@ -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);
}
},
};