Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Searchable

(function () {
    var client = algoliasearch('Application ID', 'Admin API Key');
    var index = client.initIndex('headlines');
    //initialize autocomplete on search input (ID selector must match)
    autocomplete('#aa-search-input',
        {hint: false}, {
            source: autocomplete.sources.hits(index),
            //value to be displayed in input control after user's suggestion selection
            displayKey: 'title',
            //hash of templates used when rendering dataset
            templates: {
                suggestion: function (suggestion) {
                    return `
                        <div class="algolia-result">
                            <span>
                                ${suggestion._highlightResult.title.value.replace(/^(.{50}[^s]*).*/, "$1")}
                            </span>
                            <span>${suggestion._highlightResult.category.value}</span>
                        </div>
                    `;
                }
            }
        }).on('autocomplete:selected', function (event, suggestion, dataset) {
            // console.log(suggestion)
        window.location.href = window.location.origin + '/headlines/' + suggestion.slug;
    });
})();
Copy code
Comment

PREVIOUS NEXT
Code Example
Javascript :: Plumsail To change the modal popup window size you can try injecting the CSS to the SharePoint list view page 
Javascript :: Plumsail - DataTable Cascading Dropdowns 
Javascript :: js get data from liocalstorage 
Javascript :: how to add another model into type of model in mongodb schema 
Javascript :: copy array using spread operator 
Javascript :: user key value within the obj js 
Javascript :: absolute item onPress ToucableOpacity problem 
Javascript :: create index with multiple fields mongo 
Javascript :: laravel data showing in single option instead of multiple option from json array 
Javascript :: how to hide javascript code from client 
Javascript :: hide navbar and footer on certain pages like dashboard. react-router 
Javascript :: How to pass variables from one page to another with AngularJS 
Javascript :: angularjs Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup 
Javascript :: angularjs Split date and time from api response 
Javascript :: AngularJS disable default form submit hook 
Javascript :: Relaxed "angularjs" style expression parsing missing in vue 
Javascript :: npx create-create-app movie-app 
Javascript :: How to check the increase/decrease of letter input in pasting clipboard in jQuery 
Javascript :: sort lowest to highest js 
Javascript :: Connect session middleware - regenerate vs reload 
Javascript :: react native mirror text 
Javascript :: echarts js 
Javascript :: div auto extend win righting in 
Javascript :: how to have two entry files in webpack 
Javascript :: Make Floating label TextInput with password show/hide in react native 
Javascript :: Fibonacci numbers for n terms 
Javascript :: air config file 
Javascript :: Toggle child element onclick of parent element 
Javascript :: aws cognito user pool and angular 
Javascript :: get images from mysql with php jquery ajax and display them in html page inside DIVs 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =