<commit_before>"use strict";

var _ = require("underscore");
// A wrapper around twitter's typeahead library with some sane defaults

require('typeahead');

var $ = require("jquery"),
    mustache = require("mustache"),
    Bacon = require("baconjs"),
    keyCodeIs = require("./baconUtils").keyCodeIs;

function setTypeahead($typeahead, val) {
    $typeahead.typeahead('setQuery', val);
}

function setTypeaheadAfterDataLoaded($typeahead, key, query) {
    if (!key) {
        setTypeahead($typeahead, query);
    } else if (query === null || query.length === 0) {
        setTypeahead($typeahead, '');
    } else {
        var data = _.filter(
            $typeahead.data('ttView').datasets[0].itemHash,
            function(data) {
                return data.datum[key] == query;
            });

        if (data.length > 0) {
            setTypeahead($typeahead, data[0].value);
        }
    }
}

exports.create = function(options) {
    var config = options.config,
        template = mustache.compile($(options.template).html()),
        $input = $(options.input),
        $hidden_input = $(options.hidden),
        reverse = options.reverse;<commit_msg>Invert conditional in setTypeaheadAfterDataLoaded, Fixes #215<commit_after>"use strict";

var _ = require("underscore");
// A wrapper around twitter's typeahead library with some sane defaults

require('typeahead');

var $ = require("jquery"),
    mustache = require("mustache"),
    Bacon = require("baconjs"),
    keyCodeIs = require("./baconUtils").keyCodeIs;

function setTypeahead($typeahead, val) {
    $typeahead.typeahead('setQuery', val);
}

function setTypeaheadAfterDataLoaded($typeahead, key, query) {
    if (!key) {
        setTypeahead($typeahead, query);
    } else if (query && query.length !== 0) {
        var data = _.filter(
            $typeahead.data('ttView').datasets[0].itemHash,
            function(data) {
                return data.datum[key] == query;
            });

        if (data.length > 0) {
            setTypeahead($typeahead, data[0].value);
        }
    } else {
        setTypeahead($typeahead, '');
    }
}

exports.create = function(options) {
    var config = options.config,
        template = mustache.compile($(options.template).html()),
        $input = $(options.input),
        $hidden_input = $(options.hidden),
        reverse = options.reverse;
{'fraction_non_alphanumeric': 0.15010570824524314, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 2.840909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2967679', 'n_tokens_mistral': 737, 'n_tokens_neox': 685, 'n_words': 143}