From fc45d3381f32c0a274073fc71a700a034beadcbc Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 10 Feb 2026 12:45:08 +0100 Subject: [PATCH] Add missing js file --- resources/js/alpine/components/back-to-top.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 resources/js/alpine/components/back-to-top.js diff --git a/resources/js/alpine/components/back-to-top.js b/resources/js/alpine/components/back-to-top.js new file mode 100644 index 000000000..949d14348 --- /dev/null +++ b/resources/js/alpine/components/back-to-top.js @@ -0,0 +1,34 @@ +/** + * Alpine.data('backToTop') - Back to top button, appears on scroll + * Works with both document scroll and overflow-y-auto containers (main, #app). + */ +import Alpine from '@alpinejs/csp'; + +Alpine.data('backToTop', (scrollContainerSelector = '[data-scroll-container]') => ({ + visible: false, + scrollThreshold: 300, + scrollContainer: null, + + init() { + this.scrollContainer = document.querySelector(scrollContainerSelector) || window; + const scrollTarget = this.scrollContainer === window ? window : this.scrollContainer; + + const handleScroll = () => { + const scrollTop = this.scrollContainer === window + ? window.scrollY || document.documentElement.scrollTop + : this.scrollContainer.scrollTop; + this.visible = scrollTop > this.scrollThreshold; + }; + + scrollTarget.addEventListener('scroll', handleScroll, { passive: true }); + handleScroll(); // Initial check + }, + + scrollToTop() { + if (this.scrollContainer === window) { + window.scrollTo({ top: 0, behavior: 'smooth' }); + } else { + this.scrollContainer.scrollTo({ top: 0, behavior: 'smooth' }); + } + }, +}));