<commit_before>$.fn.autosuggest = function() {
    this.each(function () {
        $self = $(this);

        $self.keyup(function(event) {
            $this = $(this);
            var auto = $this.attr('data-suggest-at')==='false'?false:true;

            
            var caret = $this.getCursorPosition().end;
            var val = this.value + ' ';
            var word = /\S+$/.exec(val.slice(0, val.indexOf(' ', caret)));

            if (!word) {
                $this.siblings('.autosuggest').remove();
                return;
            }

            word = word[0];

            if (auto) {
                if (word.substr(0,1) !== '@') {
                    $this.siblings('.autosuggest').remove();
                    return;
                }
                word = word.substr(1);
            }

            var max = $this.attr('data-suggest-max')?$this.attr('data-suggest-max'):5;
            
            //lookup word
            $.get('/files/ajax/autosuggest.php', {user: word, max: max}, function(data) {
                $this.siblings('.autosuggest').remove();
                
                var list = $('<ul>', {class: 'autosuggest'});
                if (data.status == false)
                    return;

                for (var i = 0; i < data.users.length; ++i) {
                    user = data.users[i];

                    var icon = $('<i>', {class: 'icon-addfriend'});
                    var link = $('<a>', {text: user.username, href: '#'+user.username});
                    if (user.friends == 1)
                        link.append(icon);
                    $('<li>').append(link).appendTo(list);
                }

                $this.after(list);
            }, 'json');

            $(document).bind('click.suggest-hide', function(e) {
                if ($(e.target).closest('.autosuggest').length != 0 || $(e.target).hasClass('suggest')) return true;
                $('.autosuggest').remove();
                $(document).unbind('click.suggest-hide');
            });
        });

        $self.parent().on('click', '.autosuggest a', function(e) {
            $this = $(this);
            e.preventDefault();
            e.stopPropagation();

            $self = $this.closest('.autosuggest').prev();
            var auto = $self.attr('data-suggest-at')==='false'?false:true;

            $this.closest('.autosuggest').remove();
            var insert = this.hash.slice(1);
            if (!auto) insert += ",";

            tmp = $self.val() + ' ';

            var caret = $self.getCursorPosition().end;
            var wordEnd = tmp.indexOf(' ', caret);
            var word = /\S+$/.exec(tmp.slice(0, wordEnd));

            if (auto)
                var start = tmp.substr(0, wordEnd-word[0].length+1);
            else
                var start = tmp.substr(0, wordEnd-word[0].length);
            var end = tmp.substr(wordEnd);

            var tmp = start + insert + end;
            $self.val(tmp).focus().setCursorPosition(start.length+insert.length+1);
        });
    });
};
<commit_msg>Fixed namespacing errors in autosuggest feature throughout site<commit_after>$.fn.autosuggest = function() {
    this.each(function () {
        $self = $(this);

        $self.keyup(function(event) {
            var $this = $(this);
            var auto = $this.attr('data-suggest-at')==='false'?false:true;

            var caret = $this.getCursorPosition().end;
            var val = this.value + ' ';
            var word = /\S+$/.exec(val.slice(0, val.indexOf(' ', caret)));

            if (!word) {
                $this.siblings('.autosuggest').remove();
                return;
            }

            word = word[0];

            if (auto) {
                if (word.substr(0,1) !== '@') {
                    $this.siblings('.autosuggest').remove();
                    return;
                }
                word = word.substr(1);
            }

            var max = $this.attr('data-suggest-max')?$this.attr('data-suggest-max'):5;
            
            //lookup word
            $.get('/files/ajax/autosuggest.php', {user: word, max: max}, function(data) {
                $this.siblings('.autosuggest').remove();
                
                var list = $('<ul>', {class: 'autosuggest'});
                if (data.status == false)
                    return;

                for (var i = 0; i < data.users.length; ++i) {
                    user = data.users[i];

                    var icon = $('<i>', {class: 'icon-addfriend'});
                    var link = $('<a>', {text: user.username, href: '#'+user.username});
                    if (user.friends == 1)
                        link.append(icon);
                    $('<li>').append(link).appendTo(list);
                }

                $this.after(list);
            }, 'json');

            $(document).bind('click.suggest-hide', function(e) {
                if ($(e.target).closest('.autosuggest').length != 0 || $(e.target).hasClass('suggest')) return true;
                $('.autosuggest').remove();
                $(document).unbind('click.suggest-hide');
            });
        });

        $self.parent().on('click', '.autosuggest a', function(e) {
            var $this = $(this);
            e.preventDefault();
            e.stopPropagation();

            var $self = $this.closest('.autosuggest').prev();
            var auto = $self.attr('data-suggest-at')==='false'?false:true;

            $this.closest('.autosuggest').remove();
            var insert = this.hash.slice(1);
            if (!auto) insert += ",";

            tmp = $self.val() + ' ';

            var caret = $self.getCursorPosition().end;
            var wordEnd = tmp.indexOf(' ', caret);
            var word = /\S+$/.exec(tmp.slice(0, wordEnd));

            if (auto)
                var start = tmp.substr(0, wordEnd-word[0].length+1);
            else
                var start = tmp.substr(0, wordEnd-word[0].length);
            var end = tmp.substr(wordEnd);

            var tmp = start + insert + end;
            $self.val(tmp).focus().setCursorPosition(start.length+insert.length+1);
        });
    });
};

{'fraction_non_alphanumeric': 0.1775321086002276, 'fraction_numerical': 0.005527556494878881, 'mean_word_length': 1.4393338620142744, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '7030832', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1698, 'n_words': 306}