<commit_before>define([
    'bluebird',
    'kb_common/html',
    'kb_common/gravatar',
    'kb_common/domEvent2',
    'kb_plugin_auth2-client',
    'bootstrap'
], function (
    Promise,
    html,
    Gravatar,
    DomEvents,
    Plugin
) {
    'use strict';

    function myWidget(config) {
        var runtime = config.runtime;
        if (!runtime) {
            throw {
                name: 'RuntimeMissing',
                message: 'The runtime argument is required but is missing',
                suggestion: 'This is an application error, and no fault of yours.'
            };
        }

        var t = html.tag,
            button = t('button'),
            div = t('div'),
            a = t('a'),
            span = t('span'),
            ul = t('ul'),
            li = t('li'),
            img = t('img');

        function handleSignout(e) {
            e.preventDefault();

            runtime.service('session').logout()
                .then(function () {
                    runtime.send('app', 'navigate', {
                        path: 'auth2/signedout'
                    });
                })
                .catch(function (err) {
                    console.error('ERROR');
                    console.error(err);
                    alert('Error signing out (check console for details)');
                });
        }

        function buildAvatarUrl(profile) {
            switch (profile.profile.userdata.avatarOption || 'gravatar') {
            case 'gravatar':
                var gravatarDefault = profile.profile.userdata.gravatarDefault || 'identicon';
                var gravatarHash = profile.profile.synced.gravatarHash;
                if (gravatarHash) {
                    return 'https://www.gravatar.com/avatar/' + gravatarHash + '?s=32&amp;r=pg&d=' + gravatarDefault;
                } else {
                    return Plugin.plugin.fullPath + '/images/nouserpic.png';
                }
            case 'silhouette':
            case 'mysteryman':
            default:
                return Plugin.plugin.fullPath + '/images/nouserpic.png';
            }
        }

        function buildAvatar(profile) {
            if (!profile || !profile.profile) {
                console.warn('no profile?', profile);
                return '';
            }
            var avatarUrl = buildAvatarUrl(profile);

            return img({
                src: avatarUrl,
                style: {
                    width: '40px;'
                },
                class: 'login-button-avatar',
                dataElement: 'avatar'
            });
        }

        function renderLogin(events) {
            return Promise.try(function () {
                if (runtime.service('session').isLoggedIn()) {
                    return runtime.service('userprofile').getProfile()
                        .then(function (profile) {
                            if (!profile) {
                                // Don't bother rendering yet if the profile is not ready 
                                // yet.
                                return;
                            }
                            var realname = profile.user.realname;
                            var username = profile.user.username;
                            return div({
                                class: 'navbar container-fluid'
                            }, div({
                                class: 'navbar-right'
                            }, div({
                                class: 'dropdown',
                                style: 'display:inline-block',
                                dataKBTesthookMenu: 'signed-in'
                            }, [
                                button({
                                    type: 'button',
                                    class: 'btn btn-default dropdown-toggle',
                                    dataToggle: 'dropdown',
                                    ariaExpanded: 'false',
                                    dataKBTesthookButton: 'avatar'
                                }, [
                                    buildAvatar(profile),
                                    span({ class: 'caret', style: 'margin-left: 5px;' })
                                ]),
                                ul({ class: 'dropdown-menu', role: 'menu' }, [
                                    li({}, [
                                        div({
                                            display: 'inline-block',
                                            dataElement: 'user-label',
                                            style: {
                                                textAlign: 'center'
                                            }
                                        }, [
                                            div({
                                                dataKBTesthookLabel: 'realname'
                                            }, realname),<commit_msg>encode realname before embedding in markup - jeeze<commit_after>define([
    'bluebird',
    'kb_common/html',
    'kb_common/gravatar',
    'kb_common/domEvent2',
    'kb_plugin_auth2-client',
    'bootstrap'
], function (
    Promise,
    html,
    Gravatar,
    DomEvents,
    Plugin
) {
    'use strict';

    function cleanText(text) {
        const n = document.createElement('div');
        n.textContent = text;
        return n.innerHTML;
    }

    function myWidget(config) {
        var runtime = config.runtime;
        if (!runtime) {
            throw {
                name: 'RuntimeMissing',
                message: 'The runtime argument is required but is missing',
                suggestion: 'This is an application error, and no fault of yours.'
            };
        }

        var t = html.tag,
            button = t('button'),
            div = t('div'),
            a = t('a'),
            span = t('span'),
            ul = t('ul'),
            li = t('li'),
            img = t('img');

        function handleSignout(e) {
            e.preventDefault();

            runtime.service('session').logout()
                .then(function () {
                    runtime.send('app', 'navigate', {
                        path: 'auth2/signedout'
                    });
                })
                .catch(function (err) {
                    console.error('ERROR');
                    console.error(err);
                    alert('Error signing out (check console for details)');
                });
        }

        function buildAvatarUrl(profile) {
            switch (profile.profile.userdata.avatarOption || 'gravatar') {
            case 'gravatar':
                var gravatarDefault = profile.profile.userdata.gravatarDefault || 'identicon';
                var gravatarHash = profile.profile.synced.gravatarHash;
                if (gravatarHash) {
                    return 'https://www.gravatar.com/avatar/' + gravatarHash + '?s=32&amp;r=pg&d=' + gravatarDefault;
                } else {
                    return Plugin.plugin.fullPath + '/images/nouserpic.png';
                }
            case 'silhouette':
            case 'mysteryman':
            default:
                return Plugin.plugin.fullPath + '/images/nouserpic.png';
            }
        }

        function buildAvatar(profile) {
            if (!profile || !profile.profile) {
                console.warn('no profile?', profile);
                return '';
            }
            var avatarUrl = buildAvatarUrl(profile);

            return img({
                src: avatarUrl,
                style: {
                    width: '40px;'
                },
                class: 'login-button-avatar',
                dataElement: 'avatar'
            });
        }

        function renderLogin(events) {
            return Promise.try(function () {
                if (runtime.service('session').isLoggedIn()) {
                    return runtime.service('userprofile').getProfile()
                        .then(function (profile) {
                            if (!profile) {
                                // Don't bother rendering yet if the profile is not ready 
                                // yet.
                                return;
                            }
                            var realname = cleanText(profile.user.realname);
                            var username = cleanText(profile.user.username);
                            return div({
                                class: 'navbar container-fluid'
                            }, div({
                                class: 'navbar-right'
                            }, div({
                                class: 'dropdown',
                                style: 'display:inline-block',
                                dataKBTesthookMenu: 'signed-in'
                            }, [
                                button({
                                    type: 'button',
                                    class: 'btn btn-default dropdown-toggle',
                                    dataToggle: 'dropdown',
                                    ariaExpanded: 'false',
                                    dataKBTesthookButton: 'avatar'
                                }, [
                                    buildAvatar(profile),
                                    span({ class: 'caret', style: 'margin-left: 5px;' })
                                ]),
                                ul({ class: 'dropdown-menu', role: 'menu' }, [
                                    li({}, [
                                        div({
                                            display: 'inline-block',
                                            dataElement: 'user-label',
                                            style: {
                                                textAlign: 'center'
                                            }
                                        }, [
                                            div({
                                                dataKBTesthookLabel: 'realname'
                                            }, realname),
{'fraction_non_alphanumeric': 0.0986261040235525, 'fraction_numerical': 0.0015701668302257115, 'mean_word_length': 0.8699082568807339, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3302111', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2137, 'n_words': 456}