@@ -254,9 +254,9 @@ document.addEventListener('DOMContentLoaded', () => {
254254 let filteredProducts = [ ] ; // ืืืืจื ืืืืฅ
255255
256256 // ืืืคืื ืืืืืฆื ืขื Enter
257- search . addEventListener ( 'keypress' , function ( e ) {
258- if ( e . key === 'Enter' ) {
259- e . preventDefault ( ) ;
257+ search . addEventListener ( 'keypress' , function ( event ) {
258+ if ( event . key === 'Enter' ) {
259+ event . preventDefault ( ) ;
260260 if ( filteredProducts . length > 0 ) {
261261 // ืฉืืืจืช ืชืืฆืืืช ืืืืคืืฉ ื-localStorage
262262 localStorage . setItem ( 'searchResults' , JSON . stringify ( filteredProducts ) ) ;
@@ -278,8 +278,9 @@ document.addEventListener('DOMContentLoaded', () => {
278278 console . log ( 'Filtered products:' , filteredProductsNames ) ;
279279 }
280280
281+ // ืืฆืืจืช ืชืืืช ืืฆืขืืช
281282 if ( filteredProducts . length > 0 ) {
282- let suggestionsBox = document . createElement ( 'div' ) ;
283+ const suggestionsBox = document . createElement ( 'div' ) ;
283284 suggestionsBox . classList . add ( 'suggestions_box' ) ;
284285 suggestionsBox . style . width = '100%' ;
285286 suggestionsBox . style . height = 'auto' ;
@@ -290,54 +291,57 @@ document.addEventListener('DOMContentLoaded', () => {
290291 suggestionsBox . style . left = '0' ;
291292 suggestionsBox . style . zIndex = '997' ;
292293 suggestionsBox . style . border = '1px solid #601E1E' ;
293- suggestionsBox . style . borderTop = '3px solid white' ;
294+ suggestionsBox . style . borderTop = '1px solid white' ;
294295 suggestionsBox . style . borderBottomLeftRadius = '6px' ;
295296 suggestionsBox . style . borderBottomRightRadius = '6px' ;
296297 suggestionsBox . style . overflowY = 'auto' ;
297298 suggestionsBox . style . opacity = '0' ; // Start hidden
298299 suggestionsBox . style . transform = 'translateY(-10px)' ; // Start slightly above
300+ suggestionsBox . style . scrollbarWidth = 'thin' ;
299301
300302 // Add transition for smooth animation
301303 suggestionsBox . style . transition = 'opacity 0.5s ease, transform 0.5s ease' ;
302304
303305 // ืืืกืคืช ืืชืืฆืืืช ืืชืืื
304- filteredProducts . forEach ( product => {
305- const suggestion = document . createElement ( 'div' ) ;
306- suggestion . style . padding = '10px' ;
307- suggestion . style . borderBottom = '1px solid #eee' ;
308- suggestion . style . cursor = 'pointer' ;
309- suggestion . style . display = 'flex' ;
310- suggestion . style . alignItems = 'center' ;
311- suggestion . style . justifyContent = 'space-between' ;
312-
313- // ืืฆืืจืช ืชืืื ืืืงืกื
314- const textDiv = document . createElement ( 'div' ) ;
315- textDiv . textContent = product . name ;
316- textDiv . style . flex = '1' ;
317-
318- // ืืฆืืจืช ืชืืื ื ืืืืืขืจืช
319- const thumbnailImg = document . createElement ( 'img' ) ;
320- thumbnailImg . src = product . image ;
321- thumbnailImg . style . width = '40px' ;
322- thumbnailImg . style . height = '40px' ;
323- thumbnailImg . style . objectFit = 'cover' ;
324- thumbnailImg . style . marginLeft = '10px' ;
325- thumbnailImg . style . borderRadius = '4px' ;
326-
327- // ืืืกืคืช ืืืจืืข ืืืืฆื ืืื ืืฆืขื
328- suggestion . addEventListener ( 'click' , ( ) => {
329- const urlParams = new URLSearchParams ( ) ;
330- urlParams . append ( 'category' , product . category ) ;
331- urlParams . append ( 'id' , product . id ) ;
332- urlParams . append ( 'name' , product . name ) ;
333- window . location . href = `pages/product.html?${ urlParams . toString ( ) } ` ;
334- } ) ;
306+ filteredProducts . forEach ( product => {
307+ const suggestion = document . createElement ( 'div' ) ;
308+ suggestion . style . padding = '10px' ;
309+ suggestion . style . borderBottom = '1px solid #eee' ;
310+ suggestion . style . cursor = 'pointer' ;
311+ suggestion . style . display = 'flex' ;
312+ suggestion . style . alignItems = 'center' ;
313+ suggestion . style . justifyContent = 'space-between' ;
314+
315+ // ืืืกืคืช ืฉื ืืืืฆืจ
316+ const textDiv = document . createElement ( 'div' ) ;
317+ textDiv . textContent = product . name ;
318+ textDiv . style . flex = '1' ;
319+
320+ // ืืฆืืจืช ืชืืื ื ืืืืืขืจืช
321+ const thumbnailImg = document . createElement ( 'img' ) ;
322+ thumbnailImg . src = product . image ;
323+ thumbnailImg . alt = product . name ;
324+ thumbnailImg . style . width = '40px' ;
325+ thumbnailImg . style . height = '40px' ;
326+ thumbnailImg . style . objectFit = 'cover' ;
327+ thumbnailImg . style . marginLeft = '10px' ;
328+ thumbnailImg . style . borderRadius = '4px' ;
329+
330+ // ืืืกืคืช ืืืจืืข ืืืืฆื ืืื ืืฆืขื
331+ suggestion . addEventListener ( 'click' , ( ) => {
332+ const urlParams = new URLSearchParams ( ) ;
333+ urlParams . append ( 'category' , product . category ) ;
334+ urlParams . append ( 'id' , product . id ) ;
335+ urlParams . append ( 'name' , product . name ) ;
336+ window . location . href = `pages/product.html?${ urlParams . toString ( ) } ` ;
337+ } ) ;
335338
336- suggestion . appendChild ( textDiv ) ;
337- suggestion . appendChild ( thumbnailImg ) ;
338- suggestionsBox . appendChild ( suggestion ) ;
339- } ) ;
339+ suggestion . appendChild ( textDiv ) ;
340+ suggestion . appendChild ( thumbnailImg ) ;
341+ suggestionsBox . appendChild ( suggestion ) ;
342+ } ) ;
340343
344+ // ืืืกืคืช ืชืืืช ืืืฆืขืืช ืืืืื ืืืืคืืฉ
341345 const container = document . querySelector ( '.welcome_animation_box' ) ;
342346 if ( container ) {
343347 container . style . position = 'relative' ;
@@ -348,9 +352,6 @@ document.addEventListener('DOMContentLoaded', () => {
348352 suggestionsBox . style . transform = 'translateY(0)' ; // Move down to original position
349353 } ) ;
350354 }
351-
352- document . querySelector ( '.welcome_animation_box' ) . style . borderBottomLeftRadius = '0px !important' ;
353- document . querySelector ( '.welcome_animation_box' ) . style . borderBottomRightRadius = '0px !important' ;
354355 }
355356 } ) ;
356357 } )
0 commit comments