<commit_before>// vim: ts=4 et sw=4 sts=4

$(function () {
    // Micro-plugin for positioning the cursor
    $.fn.setCursor = $.fn.setCursor || function(pos) {
        return this.each(function() {
            if (this.setSelectionRange) {
                this.focus();
                this.setSelectionRange(pos, pos);
            } else if (this.createTextRange) {
                var range = this.createTextRange();
                range.collapse(true);
                range.moveEnd('character', pos);
                range.moveStart('character', pos);
                range.select();
            }
        });
    };
    // Micro-plugin for getting the position of the cursor
    $.fn.getCursor = $.fn.getCursor || function () {
        // IE doesn't have selectionStart, and I'm too lazy to implement
        // the IE specific version of this, so we'll just assume
        // the cursor is at the end of the input for this case.
        if (typeof this[0].selectionStart === 'undefined') {
            return this.value.length;
        } else {
            return this[0].selectionStart;
        }
    };
    $(".magic_grid[data-remote=true]").on( "click", ".pagination a, .sorter a", function (e) {
        var $a = $(this),
            $container = $a.closest(".magic_grid[data-remote=true]"),
            url = $a.attr('href');
        $a.addClass("ui-icon-spinner");
        $container.load(url + ' #' + $container.attr('id') + " > *");
        return false;
    });
    $(".magic_grid[data-searcher]").each( function () {
        var $grid = $(this),
            grid_id = this.id,
            input_id = "#" + $grid.data("searcher"),
            live = $grid.data("live-search"),
            // keydown seems to be the only reliable and portable way to capture
            // things like backspace and delete
            events = (live ? "keydown change search" : "change search"),
            timer = null,
            minLength = $(input_id).data("min-length") || 3,
            current = $(input_id).val();
        $grid.parent().on(events, input_id, function (e) {
            var is_manual = (e.type == 'search' ||
                             e.type == 'change' ||
                             (e.type == 'keydown' && e.which == '13')
                            ),
                base_url = $grid.data("current"),
                params = {'magic_grid_id' : grid_id},
                //40 wpm typists == 280ms
                //90 wpm typists == 120ms
                delay = is_manual ? 1 : 250;
            clearTimeout(timer);
            timer = setTimeout(function () {
                var $input = $(input_id),
                    value = $input.val(),
                    length = value.length,
                    url = base_url + "?",
                    relevant = is_manual || (value != current && (length >= minLength || length == 0)),
                    pos = $input.getCursor();
                clearTimeout(timer);
                params[grid_id + "_q"] = value;
                url += $.param(params);
                if (relevant) {
                    if ($grid.data("remote")) {
                        $(input_id).prop('disabled', true);
                        $grid.load(url + ' #' + grid_id + ' > *', function () {
                            // Move the cursor back to where it was,
                            // less surprising that way.
                            current = $(input_id).setCursor(pos).val();
                        });
                    } else {
                        window.location = url;
                    }
                }
            }, delay);
            e.stopImmediatePropagation();<commit_msg>Increase delay on live search fields<commit_after>// vim: ts=4 et sw=4 sts=4

$(function () {
    // Micro-plugin for positioning the cursor
    $.fn.setCursor = $.fn.setCursor || function(pos) {
        return this.each(function() {
            if (this.setSelectionRange) {
                this.focus();
                this.setSelectionRange(pos, pos);
            } else if (this.createTextRange) {
                var range = this.createTextRange();
                range.collapse(true);
                range.moveEnd('character', pos);
                range.moveStart('character', pos);
                range.select();
            }
        });
    };
    // Micro-plugin for getting the position of the cursor
    $.fn.getCursor = $.fn.getCursor || function () {
        // IE doesn't have selectionStart, and I'm too lazy to implement
        // the IE specific version of this, so we'll just assume
        // the cursor is at the end of the input for this case.
        if (typeof this[0].selectionStart === 'undefined') {
            return this.value.length;
        } else {
            return this[0].selectionStart;
        }
    };
    $(".magic_grid[data-remote=true]").on( "click", ".pagination a, .sorter a", function (e) {
        var $a = $(this),
            $container = $a.closest(".magic_grid[data-remote=true]"),
            url = $a.attr('href');
        $a.addClass("ui-icon-spinner");
        $container.load(url + ' #' + $container.attr('id') + " > *");
        return false;
    });
    $(".magic_grid[data-searcher]").each( function () {
        var $grid = $(this),
            grid_id = this.id,
            input_id = "#" + $grid.data("searcher"),
            live = $grid.data("live-search"),
            // keydown seems to be the only reliable and portable way to capture
            // things like backspace and delete
            events = (live ? "keydown change search" : "change search"),
            timer = null,
            minLength = $(input_id).data("min-length") || 3,
            current = $(input_id).val();
        $grid.parent().on(events, input_id, function (e) {
            var is_manual = (e.type == 'search' ||
                             e.type == 'change' ||
                             (e.type == 'keydown' && e.which == '13')
                            ),
                base_url = $grid.data("current"),
                params = {'magic_grid_id' : grid_id},
                //40 wpm typists == 280ms/keystroke
                //90 wpm typists == 120ms/keystroke
                delay = is_manual ? 1 : 500;
            clearTimeout(timer);
            timer = setTimeout(function () {
                var $input = $(input_id),
                    value = $input.val(),
                    length = value.length,
                    url = base_url + "?",
                    relevant = is_manual || (value != current && (length >= minLength || length == 0)),
                    pos = $input.getCursor();
                clearTimeout(timer);
                params[grid_id + "_q"] = value;
                url += $.param(params);
                if (relevant) {
                    if ($grid.data("remote")) {
                        $(input_id).prop('disabled', true);
                        $grid.load(url + ' #' + grid_id + ' > *', function () {
                            // Move the cursor back to where it was,
                            // less surprising that way.
                            current = $(input_id).setCursor(pos).val();
                        });
                    } else {
                        window.location = url;
                    }
                }
            }, delay);
            e.stopImmediatePropagation();
{'fraction_non_alphanumeric': 0.13971084988515065, 'fraction_numerical': 0.006215376300499932, 'mean_word_length': 1.3678822776711452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '804379', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1906, 'n_words': 474}