AndreNDarcie/gtfs-visualizer

View on GitHub
js/typeahead-main.js

Summary

Maintainability
A
0 mins
Test Coverage
var substringMatcher = function(strs) {
    return function findMatches(q, cb) {
        var matches, substringRegex;

        // an array that will be populated with substring matches
        matches = [];

        // regex used to determine if a string contains the substring `q`
        substrRegex = new RegExp(q, 'i');

        // iterate through the pool of strings and for any string that
        // contains the substring `q`, add it to the `matches` array
        $.each(strs, function(i, str) {
            if (substrRegex.test(str)) {
                matches.push(str);
            }
        });

        cb(matches);
    };
};

$('#the-basics .typeahead').typeahead({
    hint: true,
    highlight: true,
    minLength: 1
}, {
    name: 'listaRotas',
    source: substringMatcher(listaRotas)
});

$('.typeahead').on('typeahead:selected', function(evt, item) {

    var subString = item.split(":");
    var route_id = subString[0];

    drawSelectedRoute(route_id);
});