Created
November 21, 2018 00:46
-
-
Save haxorgist/3c0198af75349dd2473ce62f5af4b29b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
| <style> | |
| .algolia-autocomplete { | |
| width: 100%; | |
| } | |
| .algolia-autocomplete .aa-input, .algolia-autocomplete .aa-hint { | |
| width: 100%; | |
| } | |
| .algolia-autocomplete .aa-hint { | |
| color: #999; | |
| } | |
| .algolia-autocomplete .aa-dropdown-menu { | |
| width: 100%; | |
| background-color: #fff; | |
| border: 1px solid #999; | |
| border-top: none; | |
| } | |
| .algolia-autocomplete .aa-dropdown-menu .aa-suggestion { | |
| cursor: pointer; | |
| padding: 5px 4px; | |
| } | |
| .algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor { | |
| background-color: #B2D7FF; | |
| } | |
| .algolia-autocomplete .aa-dropdown-menu .aa-suggestion em { | |
| font-weight: bold; | |
| font-style: normal; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="row"> | |
| <div class="col-sm-6 col-sm-offset-3"> | |
| <form action="#" class="form"> | |
| <h3>Algolia API Tutorial</h3> | |
| <input class="form-control" id="search-input" name="contacts" type="text" placeholder='Search for events...' /> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/autocomplete.js/0/autocomplete.min.js"></script> | |
| <script> | |
| var client = algoliasearch('YourApplicationID', 'YourAPIKey'); | |
| var index = client.initIndex('your_index_name'); | |
| autocomplete('#search-input', { hint: false }, [ | |
| { | |
| source: autocomplete.sources.hits(index, { hitsPerPage: 5 }), | |
| displayKey: 'name', | |
| templates: { | |
| suggestion: function(suggestion) { | |
| return suggestion._highlightResult.name.value; | |
| } | |
| } | |
| } | |
| ]).on('autocomplete:selected', function(event, suggestion, dataset) { | |
| console.log(suggestion, dataset); | |
| alert('dataset: ' + dataset + ', ' + suggestion.name); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment