@@ -1999,107 +1999,133 @@ <h2 class="feedback-title text-center mb-3">Feedback & Reviews</h2>
1999
1999
< script src ="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js " crossorigin ="anonymous "
2000
2000
defer > </ script >
2001
2001
< script >
2002
- // Logo switching functionality for dark mode
2003
- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
2004
- const logo = document . querySelector ( "#logo" ) ;
2005
-
2006
- // Function to update logo based on theme
2007
- function updateLogo ( ) {
2008
- const isDark = document . documentElement . getAttribute ( "data-bs-theme" ) === "dark" ;
2009
- if ( isDark ) {
2010
- logo . src = 'images/Logo.png' ;
2011
- } else {
2012
- logo . src = 'images/Logo_new.png' ;
2002
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2003
+ /* ----------------------------
2004
+ Logo Switching for Dark Mode
2005
+ ----------------------------- */
2006
+ const logo = document . querySelector ( "#logo" ) ;
2007
+
2008
+ function updateLogo ( ) {
2009
+ const isDark = document . documentElement . getAttribute ( "data-bs-theme" ) === "dark" ;
2010
+ logo . src = isDark ? "images/Logo.png" : "images/Logo_new.png" ;
2011
+ }
2012
+
2013
+ // Initial update
2014
+ updateLogo ( ) ;
2015
+
2016
+ // Watch for theme changes
2017
+ const observer = new MutationObserver ( function ( mutations ) {
2018
+ for ( const mutation of mutations ) {
2019
+ if ( mutation . type === "attributes" && mutation . attributeName === "data-bs-theme" ) {
2020
+ updateLogo ( ) ;
2013
2021
}
2014
2022
}
2023
+ } ) ;
2015
2024
2016
- // Update logo when page loads
2017
- updateLogo ( ) ;
2025
+ observer . observe ( document . documentElement , {
2026
+ attributes : true ,
2027
+ attributeFilter : [ "data-bs-theme" ] ,
2028
+ } ) ;
2018
2029
2019
- // Watch for theme changes
2020
- const observer = new MutationObserver ( function ( mutations ) {
2021
- mutations . forEach ( function ( mutation ) {
2022
- if ( mutation . type === 'attributes' && mutation . attributeName === 'data-bs-theme' ) {
2023
- updateLogo ( ) ;
2024
- }
2025
- } ) ;
2030
+ /* ----------------------------
2031
+ Carousel Initialization
2032
+ ----------------------------- */
2033
+ const carouselEl = document . getElementById ( "carouselExampleDark" ) ;
2034
+ let carouselInstance = null ;
2035
+ if ( carouselEl ) {
2036
+ carouselInstance = new bootstrap . Carousel ( carouselEl , {
2037
+ interval : 4000 ,
2038
+ wrap : true ,
2026
2039
} ) ;
2040
+ }
2027
2041
2028
- observer . observe ( document . documentElement , {
2029
- attributes : true ,
2030
- attributeFilter : [ 'data-bs-theme' ]
2042
+ // Custom next button
2043
+ const customNextButton = document . getElementById ( "customNextButton" ) ;
2044
+ if ( customNextButton && carouselInstance ) {
2045
+ customNextButton . addEventListener ( "click" , function ( ) {
2046
+ carouselInstance . next ( ) ;
2031
2047
} ) ;
2032
- } ) ;
2048
+ }
2049
+
2050
+ /* ----------------------------
2051
+ Feedback Form Handling
2052
+ ----------------------------- */
2053
+ const feedbackForm = document . getElementById ( "feedbackForm" ) ;
2054
+ const successMessage = document . getElementById ( "successMessage" ) ;
2055
+ const errorMessage = document . getElementById ( "errorMessage" ) ;
2056
+
2057
+ if ( feedbackForm ) {
2058
+ feedbackForm . addEventListener ( "submit" , function ( event ) {
2059
+ event . preventDefault ( ) ;
2060
+
2061
+ const name = document . getElementById ( "userName" ) . value . trim ( ) ;
2062
+ const email = document . getElementById ( "userEmail" ) . value . trim ( ) ;
2063
+ const feedback = document . getElementById ( "userFeedback" ) . value . trim ( ) ;
2064
+
2065
+ const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
2066
+
2067
+ if ( ! name || ! email || ! feedback ) {
2068
+ showError ( "⚠️ Please fill in all required fields." ) ;
2069
+ return ;
2070
+ }
2071
+
2072
+ if ( ! emailRegex . test ( email ) ) {
2073
+ showError ( "⚠️ Please enter a valid email address." ) ;
2074
+ return ;
2075
+ }
2033
2076
2034
- // JavaScript (custom carousel)
2035
- var myCarousel = new bootstrap . Carousel ( '#carouselExampleDark' , {
2036
- interval : 4000 , // auto-slide time
2037
- wrap : true // enables infinite loop
2038
- } ) ;
2039
- // SIMPLE FEEDBACK FUNCTIONS - FORM STAYS VISIBLE
2040
- function showSuccessMessage ( event ) {
2041
- event . preventDefault ( ) ;
2042
-
2043
- // Get form values
2044
- var name = document . getElementById ( 'userName' ) . value ;
2045
- var email = document . getElementById ( 'userEmail' ) . value ;
2046
- var feedback = document . getElementById ( 'userFeedback' ) . value ;
2047
-
2048
- // Check if all fields are filled
2049
- if ( name && email && feedback ) {
2050
2077
// Save to localStorage
2051
- var data = {
2052
- name : name ,
2053
- email : email ,
2054
- feedback : feedback ,
2055
- timestamp : new Date ( ) . toISOString ( )
2078
+ const data = {
2079
+ name,
2080
+ email,
2081
+ feedback,
2082
+ timestamp : new Date ( ) . toISOString ( ) ,
2056
2083
} ;
2057
-
2058
- var feedbacks = JSON . parse ( localStorage . getItem ( ' growcraft_feedbacks' ) || '[]' ) ;
2084
+
2085
+ const feedbacks = JSON . parse ( localStorage . getItem ( " growcraft_feedbacks" ) || "[]" ) ;
2059
2086
feedbacks . push ( data ) ;
2060
- localStorage . setItem ( 'growcraft_feedbacks' , JSON . stringify ( feedbacks ) ) ;
2061
-
2062
- // KEEP FORM VISIBLE - Just show success message below
2063
- document . getElementById ( 'successMessage' ) . style . display = 'block' ;
2064
-
2065
- // Reset form fields and hide success message after 4 seconds
2066
- setTimeout ( function ( ) {
2067
- document . getElementById ( 'successMessage' ) . style . display = 'none' ;
2068
- document . getElementById ( 'feedbackForm' ) . reset ( ) ;
2087
+ localStorage . setItem ( "growcraft_feedbacks" , JSON . stringify ( feedbacks ) ) ;
2088
+
2089
+ // Show success message
2090
+ showSuccess ( "✅ Feedback submitted successfully!" ) ;
2091
+
2092
+ // Reset after delay
2093
+ setTimeout ( function ( ) {
2094
+ feedbackForm . reset ( ) ;
2095
+ successMessage . style . display = "none" ;
2096
+ if ( errorMessage ) errorMessage . style . display = "none" ;
2069
2097
} , 4000 ) ;
2070
-
2071
- } else {
2072
- alert ( 'Please fill all required fields!' ) ;
2098
+ } ) ;
2099
+ }
2100
+
2101
+ function showSuccess ( msg ) {
2102
+ if ( successMessage ) {
2103
+ successMessage . textContent = msg ;
2104
+ successMessage . style . display = "block" ;
2105
+ }
2106
+ if ( errorMessage ) {
2107
+ errorMessage . style . display = "none" ;
2073
2108
}
2074
-
2075
- return false ;
2076
2109
}
2077
-
2078
- function clearForm ( ) {
2079
- document . getElementById ( 'feedbackForm' ) . reset ( ) ;
2080
- document . getElementById ( 'successMessage' ) . style . display = 'none' ;
2110
+
2111
+ function showError ( msg ) {
2112
+ if ( errorMessage ) {
2113
+ errorMessage . textContent = msg ;
2114
+ errorMessage . style . display = "block" ;
2115
+ }
2116
+ if ( successMessage ) {
2117
+ successMessage . style . display = "none" ;
2118
+ }
2081
2119
}
2082
2120
2083
- </ script >
2084
- < script >
2085
- document . addEventListener ( "DOMContentLoaded" , function ( ) {
2121
+ /* ----------------------------
2122
+ Dynamic Year in Footer
2123
+ ----------------------------- */
2086
2124
const yearSpan = document . getElementById ( "currentYear" ) ;
2087
- yearSpan . textContent = new Date ( ) . getFullYear ( ) ;
2125
+ if ( yearSpan ) {
2126
+ yearSpan . textContent = new Date ( ) . getFullYear ( ) ;
2127
+ }
2088
2128
} ) ;
2089
- </ script >
2090
- < script >
2091
- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
2092
- // Get the custom button and Bootstrap carousel
2093
- const customNextButton = document . getElementById ( 'customNextButton' ) ;
2094
- const carousel = new bootstrap . Carousel ( document . getElementById ( 'carouselExampleDark' ) ) ;
2095
-
2096
- // Add click event to custom button
2097
- if ( customNextButton ) {
2098
- customNextButton . addEventListener ( 'click' , function ( ) {
2099
- carousel . next ( ) ; // Go to next slide
2100
- } ) ;
2101
- }
2102
- } ) ;
2103
2129
</ script >
2104
2130
</ body >
2105
2131
0 commit comments