<commit_before>"use strict";
(function (K, $) {
    var methods = {
        init: function (uconfig, callback) {
            callback = callback || $.noop;
            var self = this;
            this.data('kwarqueChat', {
                windows : {},
                activeRoom : null,
                config : $.extend({
                    activeClass: 'active',
                    headerClass: 'header',
                    togglerClass: 'toggler',
                    infoIconClass: 'infoIcon',
                    closeIconClass: 'closeIcon',
                    privateClass: 'private',
                    publicClass: 'public',
                    statusClass: 'status',
                    containerClass: 'container'
                }, uconfig)
            });
            var d = this.data('kwarqueChat');

            K.chat.authenticate(d.config.nick, d.config.password, function (response) {
                d.activeRoom = response.room;
                self.data('kwarqueChat', d);
                methods.openWindow.apply(self, [response.room, function () {
                    methods.message.apply(self, [response]);
                    callback();
                }]);
            });
            K.chat.on('message', $.proxy(methods.message, self));
            K.chat.on('clientJoined', function(msg) {
                methods.message.apply(self, [$.extend(msg, {
                    msg : msg.nick + ' has joined',
                    nick : 'sixth sense'
                })]);
            });
            K.chat.on('clientLeft', function(msg) {
                methods.message.apply(self, [$.extend(msg, {
                    msg : msg.nick + ' has left',
                    nick : 'sixth sense'
                })]);
            });
            methods.createAccordion.apply(this);
            $(this).find('.kwarque-chat-input').submit(function (e) {
                e.preventDefault();
                var messageNode = $(this).find('.kwarque-chat-message');
                var m = messageNode.val();
                messageNode.val("");
                K.chat.send(m, d.activeRoom, $.proxy(methods.message, self));
            });
            K.on("fragmentOpened", function(id) {
                methods.openWindow.apply(self, ["@fragment" + id]);
            });
            return this;
        },
        message: function(msg) {
            var d = this.data('kwarqueChat');
            var container = d.windows[msg.room].container;
            container.append(K.dce('p').text(msg.nick + ': ' + msg.msg));
            container.scrollTop(container.prop('scrollHeight') - container.height());
            return this;
        },
        removeWindow: function (room, callback) {
            callback = callback || $.noop;
            this.accordion('destroy');
            var d = this.data('kwarqueChat');
            d.windows[room].header.remove();
            d.windows[room].container.remove();
            delete d.windows[room];
            if (room === d.activeRoom) d.activeRoom = 0;<commit_msg>scroll only if already at bottom<commit_after>"use strict";
(function (K, $) {
    var methods = {
        init: function (uconfig, callback) {
            callback = callback || $.noop;
            var self = this;
            this.data('kwarqueChat', {
                windows : {},
                activeRoom : null,
                config : $.extend({
                    activeClass: 'active',
                    headerClass: 'header',
                    togglerClass: 'toggler',
                    infoIconClass: 'infoIcon',
                    closeIconClass: 'closeIcon',
                    privateClass: 'private',
                    publicClass: 'public',
                    statusClass: 'status',
                    containerClass: 'container'
                }, uconfig)
            });
            var d = this.data('kwarqueChat');

            K.chat.authenticate(d.config.nick, d.config.password, function (response) {
                d.activeRoom = response.room;
                self.data('kwarqueChat', d);
                methods.openWindow.apply(self, [response.room, function () {
                    methods.message.apply(self, [response]);
                    callback();
                }]);
            });
            K.chat.on('message', $.proxy(methods.message, self));
            K.chat.on('clientJoined', function(msg) {
                methods.message.apply(self, [$.extend(msg, {
                    msg : msg.nick + ' has joined',
                    nick : 'sixth sense'
                })]);
            });
            K.chat.on('clientLeft', function(msg) {
                methods.message.apply(self, [$.extend(msg, {
                    msg : msg.nick + ' has left',
                    nick : 'sixth sense'
                })]);
            });
            methods.createAccordion.apply(this);
            $(this).find('.kwarque-chat-input').submit(function (e) {
                e.preventDefault();
                var messageNode = $(this).find('.kwarque-chat-message');
                var m = messageNode.val();
                messageNode.val("");
                K.chat.send(m, d.activeRoom, $.proxy(methods.message, self));
            });
            K.on("fragmentOpened", function(id) {
                methods.openWindow.apply(self, ["@fragment" + id]);
            });
            return this;
        },
        message: function(msg) {
            var d = this.data('kwarqueChat');
            var container = d.windows[msg.room].container;
            var bottom = container.prop('scrollHeight') - container.innerHeight() - container.scrollTop();
            container.append(K.dce('p').text(msg.nick + ': ' + msg.msg));
            if (bottom === 0) {
                container.scrollTop(container.prop('scrollHeight') - container.innerHeight());
            }
            return this;
        },
        removeWindow: function (room, callback) {
            callback = callback || $.noop;
            this.accordion('destroy');
            var d = this.data('kwarqueChat');
            d.windows[room].header.remove();
            d.windows[room].container.remove();
            delete d.windows[room];
            if (room === d.activeRoom) d.activeRoom = 0;
{'fraction_non_alphanumeric': 0.13977979894686454, 'fraction_numerical': 0.0004786979415988511, 'mean_word_length': 1.4006127920337035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5481595', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1559, 'n_words': 290}