<commit_before>// TODO: Inheritance from form to implement Form interface (show/hide/etc)
// That's very hard to do cross-browser in pure JS

var multlinePlaceholderPolyfill = (function()
{
    // allows to use multiline placeholders if textarea is given as field,
    // or imitates normal placeholders if an input is given as field
    var field

    // is placeholder content displayed inside the field?
    // (double state control allows user to type in a text identical to placeholder)
    var active

    var placeholder = ''

    function startPlaceholder()
    {
        if(!active && !field.val())
        {
            field.val(placeholder)
            field.addClass('placeholder')
            active = true
        }
    }

    function stopPlaceholder()
    {
        if(active && field.val() == placeholder)
        {
            field.val('')
            field.removeClass('placeholder')
            active = false
        }
    }

    var publicSpace = {
        init: function(element, initial_placeholder)
        {
            field = $(element)

            placeholder = initial_placeholder.replace(/\\n/g, '\n')
            var multiline = placeholder.indexOf('\n') > -1

            // only Chrome supports multiline placeholders.
            if('placeholder' in element[0] && (window.chrome || !multiline))
            {
                field.attr('placeholder', placeholder)
            }
            else
            {
                field.attr('placeholder', '')

                startPlaceholder()

                field.on('blur', startPlaceholder)
                field.on('focus', stopPlaceholder)
                field.closest('form').on('submit', stopPlaceholder)
            }
        },
        setValue: function(value)
        {
            stopPlaceholder()
            field.val(value)
        }
    }

    return publicSpace
})

var ProteinForm = (function ()
{
    var element
    var empty_indicator, no_results_indicator, waiting_indicator
    var result_ul
    var recent_value
    var search_button

    function get_url()
    {
        var href = 'proteins'
        if(recent_value !== undefined && recent_value !== '')
        {
            href += '?proteins=' + recent_value
        }
        return href
    }

    function autocomplete(query)
    {
        $.ajax({
            url: '/search/autocomplete_proteins',
            type: 'GET',
            data:
                {
                    q: encodeURIComponent(query)
                },
            success: function(rawResult) {
                var results = JSON.parse(rawResult)
                // TODO add animation
                result_ul.innerHTML = ''

                waiting_indicator.addClass('hidden')
                if(!results.length)
                {
                    no_results_indicator.removeClass('hidden')
                }
                else
                {
                    no_results_indicator.addClass('hidden')
                    for(var i = 0; i < results.length; i++)
                    {
                        result_ul.innerHTML += results[i].html
                    }
                }

            }
        })
    }

    function onChangeHandler(event)
    {<commit_msg>Hide old results when displaying spinner<commit_after>// TODO: Inheritance from form to implement Form interface (show/hide/etc)
// That's very hard to do cross-browser in pure JS

var multlinePlaceholderPolyfill = (function()
{
    // allows to use multiline placeholders if textarea is given as field,
    // or imitates normal placeholders if an input is given as field
    var field

    // is placeholder content displayed inside the field?
    // (double state control allows user to type in a text identical to placeholder)
    var active

    var placeholder = ''

    function startPlaceholder()
    {
        if(!active && !field.val())
        {
            field.val(placeholder)
            field.addClass('placeholder')
            active = true
        }
    }

    function stopPlaceholder()
    {
        if(active && field.val() == placeholder)
        {
            field.val('')
            field.removeClass('placeholder')
            active = false
        }
    }

    var publicSpace = {
        init: function(element, initial_placeholder)
        {
            field = $(element)

            placeholder = initial_placeholder.replace(/\\n/g, '\n')
            var multiline = placeholder.indexOf('\n') > -1

            // only Chrome supports multiline placeholders.
            if('placeholder' in element[0] && (window.chrome || !multiline))
            {
                field.attr('placeholder', placeholder)
            }
            else
            {
                field.attr('placeholder', '')

                startPlaceholder()

                field.on('blur', startPlaceholder)
                field.on('focus', stopPlaceholder)
                field.closest('form').on('submit', stopPlaceholder)
            }
        },
        setValue: function(value)
        {
            stopPlaceholder()
            field.val(value)
        }
    }

    return publicSpace
})

var ProteinForm = (function ()
{
    var element
    var empty_indicator, no_results_indicator, waiting_indicator
    var result_ul
    var recent_value
    var search_button

    function get_url()
    {
        var href = 'proteins'
        if(recent_value !== undefined && recent_value !== '')
        {
            href += '?proteins=' + recent_value
        }
        return href
    }

    function autocomplete(query)
    {
        result_ul.innerHTML = ''
        $.ajax({
            url: '/search/autocomplete_proteins',
            type: 'GET',
            data:
                {
                    q: encodeURIComponent(query)
                },
            success: function(rawResult) {
                var results = JSON.parse(rawResult)
                // TODO add animation

                waiting_indicator.addClass('hidden')
                if(!results.length)
                {
                    no_results_indicator.removeClass('hidden')
                }
                else
                {
                    no_results_indicator.addClass('hidden')
                    for(var i = 0; i < results.length; i++)
                    {
                        result_ul.innerHTML += results[i].html
                    }
                }

            }
        })
    }

    function onChangeHandler(event)
    {
{'fraction_non_alphanumeric': 0.09594323615610056, 'fraction_numerical': 0.0009254974548819991, 'mean_word_length': 1.4467924528301888, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7524642', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1568, 'n_words': 385}