JSFiddle - React, Tailwind, and code Playground

by voigtan

HTML

<script src="https://raw.github.com/laktek/jQuery-Smart-Auto-Complete/master/jquery.smart_autocomplete.js"></script>
<script src="http://rails-oceania.googlecode.com/svn/lachiecox/qs_score/trunk/qs_score.js"></script>
<input>

JavaScript

$("input").smartAutoComplete({
    source: [
        {"url":"http://www.google.se","name":"Niklas"},
        {"url":"http://www.google.se","name":"Ludde"},
        {"url":"http://www.google.se","name":"Olle"}
    ],
    resultFormatter: function(result){
         return '<li><a href="' + result.url + '">' + result.name + '</a></li>';
    },
    filter: function(term, source){
        var filtered_and_sorted_list = $.map(source, function(item) {
            var score = item.name.toLowerCase().score(term.toLowerCase());
            if(score > 0) {
                return { 'result': item, 'value': score }
            }
        }).sort(function(a, b){ return b.value - a.value });

        return $.map(filtered_and_sorted_list, function(item){
            return item.result;
        });
    }
});