@@ -4,18 +4,49 @@ require('aos/dist/aos.css');
44( function ( ) {
55 "use strict" ;
66
7- window . onscroll = function ( ) {
8- // show or hide the back-top-top button
9- const backToTop = document . querySelector ( ".back-to-top" ) ;
10- if (
11- document . body . scrollTop > 50 ||
12- document . documentElement . scrollTop > 50
13- ) {
14- backToTop . style . display = "flex" ;
15- } else {
16- backToTop . style . display = "none" ;
7+ // Debounce function to improve performance
8+ function debounce ( func , wait ) {
9+ let timeout ;
10+ return function executedFunction ( ...args ) {
11+ const later = ( ) => {
12+ clearTimeout ( timeout ) ;
13+ func ( ...args ) ;
14+ } ;
15+ clearTimeout ( timeout ) ;
16+ timeout = setTimeout ( later , wait ) ;
17+ } ;
18+ }
19+
20+ // Show or hide scroll-dependent elements
21+ function handleScrollElements ( ) {
22+ const scrollTop = document . documentElement . scrollTop || document . body . scrollTop ;
23+ const backToTop = document . querySelector ( "#back-to-top" ) ;
24+ const footerContact = document . querySelector ( "#footer-contact" ) ;
25+ const shouldShow = scrollTop > 50 ;
26+
27+ if ( backToTop ) {
28+ if ( shouldShow ) {
29+ backToTop . classList . add ( "visible" ) ;
30+ backToTop . setAttribute ( "aria-hidden" , "false" ) ;
31+ } else {
32+ backToTop . classList . remove ( "visible" ) ;
33+ backToTop . setAttribute ( "aria-hidden" , "true" ) ;
34+ }
1735 }
18- } ;
36+
37+ if ( footerContact ) {
38+ if ( shouldShow ) {
39+ footerContact . classList . add ( "visible" ) ;
40+ footerContact . setAttribute ( "aria-hidden" , "false" ) ;
41+ } else {
42+ footerContact . classList . remove ( "visible" ) ;
43+ footerContact . setAttribute ( "aria-hidden" , "true" ) ;
44+ }
45+ }
46+ }
47+
48+ // Attach scroll handler with debounce
49+ window . addEventListener ( "scroll" , debounce ( handleScrollElements , 10 ) ) ;
1950
2051 //===== close navbar-collapse when a clicked
2152 let navbarToggler = document . querySelector ( ".navbar-toggler" ) ;
@@ -77,7 +108,46 @@ require('aos/dist/aos.css');
77108 return ( - c / 2 ) * ( t * ( t - 2 ) - 1 ) + b ;
78109 } ;
79110
80- document . querySelector ( ".back-to-top" ) . onclick = ( ) => {
81- scrollTo ( document . documentElement ) ;
82- } ;
111+ // Back to top button functionality
112+ const backToTopBtn = document . querySelector ( ".back-to-top" ) ;
113+ if ( backToTopBtn ) {
114+ backToTopBtn . addEventListener ( "click" , ( e ) => {
115+ e . preventDefault ( ) ;
116+ scrollTo ( document . documentElement ) ;
117+ } ) ;
118+
119+ // Keyboard support
120+ backToTopBtn . addEventListener ( "keydown" , ( e ) => {
121+ if ( e . key === "Enter" || e . key === " " ) {
122+ e . preventDefault ( ) ;
123+ scrollTo ( document . documentElement ) ;
124+ }
125+ } ) ;
126+ }
127+
128+ // Footer contact functionality
129+ const footerContact = document . querySelector ( "#footer-contact" ) ;
130+ if ( footerContact ) {
131+ const handleContactClick = ( ) => {
132+ // Add your contact/sales redirect logic here
133+ // For example: window.location.href = '/contact-us' or open a modal
134+ const contactLink = footerContact . getAttribute ( "data-contact-url" ) ;
135+ if ( contactLink ) {
136+ window . location . href = contactLink ;
137+ }
138+ } ;
139+
140+ footerContact . addEventListener ( "click" , handleContactClick ) ;
141+
142+ // Keyboard support
143+ footerContact . addEventListener ( "keydown" , ( e ) => {
144+ if ( e . key === "Enter" || e . key === " " ) {
145+ e . preventDefault ( ) ;
146+ handleContactClick ( ) ;
147+ }
148+ } ) ;
149+ }
150+
151+ // Initialize scroll elements state
152+ handleScrollElements ( ) ;
83153} ) ( ) ;
0 commit comments