This repository was archived by the owner on Feb 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change 33
44import './responsive-navigation.js' ;
55
6- places ( {
6+ const placesAutocomplete = places ( {
77 container : document . querySelector ( '#landing-demo' )
8- } ) . on ( 'change' , suggestion => console . log ( suggestion ) ) ;
8+ } ) ;
9+
10+ const events = [ 'change' , 'suggestions' , 'cursorchanged' ] ;
11+ events . forEach ( eventName =>
12+ placesAutocomplete . on ( eventName , eventData => {
13+ if ( ! Array . isArray ( eventData ) ) {
14+ eventData = [ eventData ] ;
15+ }
16+
17+ console . log ( `Algolia Places: received event **${ eventName } **` ) ;
18+ if ( typeof console . table === 'function' ) {
19+ console . table ( eventData ) ;
20+ } else {
21+ console . log ( 'event data:' , eventData ) ;
22+ }
23+ } )
24+ ) ;
Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ export default function places({
3737 const source = ( query , cb ) => client
3838 . search ( { query} )
3939 . then ( ( { hits} ) => hits . slice ( 0 , 5 ) . map ( hitFormatter ) )
40- . then ( hits => { console . log ( hits ) ; return hits ; } )
40+ . then ( suggestions => {
41+ placesInstance . emit ( 'suggestions' , suggestions ) ;
42+ return suggestions ;
43+ } )
4144 . then ( cb )
4245 . catch ( err => console . error ( err ) ) ;
4346
@@ -49,12 +52,15 @@ export default function places({
4952 }
5053 ) ;
5154
52- const autocompleteEvents = [ 'selected' , 'autocompleted' ] ;
53- autocompleteEvents . forEach ( eventName => {
55+ const autocompleteChangeEvents = [ 'selected' , 'autocompleted' ] ;
56+ autocompleteChangeEvents . forEach ( eventName => {
5457 autocompleteInstance . on ( `autocomplete:${ eventName } ` , ( _ , suggestion ) => {
5558 placesInstance . emit ( 'change' , suggestion ) ;
5659 } ) ;
5760 } ) ;
61+ autocompleteInstance . on ( 'autocomplete:cursorchanged' , ( _ , suggestion ) => {
62+ placesInstance . emit ( 'cursorchanged' , suggestion ) ;
63+ } ) ;
5864
5965 const autocompleteContainer = container . parentNode ;
6066 autocompleteContainer . classList . add ( 'algolia-places' ) ;
You can’t perform that action at this time.
0 commit comments