<commit_before>import $ from 'jquery';
import { around } from 'meld';
import Plugin from '../Plugin';
import Events from 'plug/core/Events';
import SaveSettingsAction from 'plug/actions/users/SaveSettingsAction';
import Lang from 'lang/Lang';

const GuestPlugin = Plugin.extend({
  name: 'Guest UI',
  description: 'Skips the guest walkthrough and adds login and settings ' +
               'buttons to the plug.dj footer.',

  style: {
    '.is-guest': {
      '#header-panel-bar': {
        '#chat-button': {
          'width': '33%',
          'span': { 'display': 'none' }
        },
        '#users-button': {
          'left': '33%',
          'width': '34%'
        },
        '#waitlist-button': {
          'left': '67%',
          'width': '33%'
        },
        '#friends-button': { 'display': 'none' }
      },
      '#user-lists': {
        // even the staff one doesn't work for guest users!
        '.button.staff, .button.ignored': { 'display': 'none' }
      },
      '#footer-user': {
        '.signup': { 'width': '40%' },
        '.signup.login': {
          'margin-left': 'calc(40% + 1px)',
          'width': 'calc(40% - 1px)',
          'background': '#555d70'
        },
        '.buttons': {
          'display': 'block',
          '.button': { 'display': 'none' },
          '.button.extplug-guest-settings': {
            'display': 'block',
            'margin-left': '80%'
          }
        }
      },
      '#user-menu .item:not(.settings)': {
        'display': 'none'
      },
      '#room-bar': {
        '.extplug-room-bar-overlay': {
          'height': 'inherit',
          'width': 'inherit',
          'position': 'absolute',
          'z-index': 10
        }
      }
    }
  },

  enable() {
    // Presumably, this isn't the first time someone has used plug.dj.
    this.skipWalkthrough();

    this.$settings = $('<div />')
      .addClass('button settings extplug-guest-settings')
      .attr('data-tooltip', Lang.userMenu.settings)
      .attr('data-tooltip-dir', 'left')
      .append($('<i />').addClass('icon icon-settings-white'))
      .appendTo('#footer-user .buttons')
      .on('click', this.onSettings);

    // add login button
    this.$signup = $('#footer-user .signup')
      .find('span')
        .text(Lang.signup.signup)
      .end();
    this.$login = $('<div />')
      .addClass('signup login')
      .append($('<span />').text(Lang.signup.login))
      .insertAfter(this.$signup)
      .on('click', this.login.bind(this));

    // disable saving settings to the server when not logged in
    this.ssaAdvice = around(SaveSettingsAction.prototype, 'execute', () => {
      // do nothing \o/
    });

    this.$roomBar = $('<div />').addClass('extplug-room-bar-overlay')
      .appendTo('#room-bar')
      .on('click', e => {
        e.stopPropagation();
        if ($('#room-settings').is(':visible')) {
          Events.trigger('hide:settings');
        }
        else {
          Events.trigger('show:settings');
        }
      });

    this._enabled = true;
  },

  disable() {
    if (this._enabled) {
      this.ssaAdvice.remove();
      this.$settings.remove();
      this.$roomBar.remove();
      this.$login.remove();
      this.$signup.find('span').text(Lang.signup.signupFree);
      this.$settings = this.$login = this.$signup = null;
    }

    this._enabled = false;
  },

  skipWalkthrough() {
    const roomView = this.ext.appView.room;
    roomView.onWTFinish();
  },

  login() {
    const app = this.ext.appView;
    app.showSignUp();
    app.signup.swap('login');
    // show email login by default
    $('.sign-up-overlay .box').addClass('show-email');
    $('.email-login input.email').focus();
  },

  onSettings(e) {
    e.stopPropagation();
    Events.trigger('tooltip:hide')
          .trigger('show:user', 'settings', 'extplug');
  }

});
<commit_msg>guest: disable walkthrough entirely when using ExtPlug<commit_after>import $ from 'jquery';
import { around } from 'meld';
import Plugin from '../Plugin';
import Events from 'plug/core/Events';
import SaveSettingsAction from 'plug/actions/users/SaveSettingsAction';
import currentUser from 'plug/models/currentUser';
import Lang from 'lang/Lang';

const GuestPlugin = Plugin.extend({
  name: 'Guest UI',
  description: 'Skips the guest walkthrough and adds login and settings ' +
               'buttons to the plug.dj footer.',

  style: {
    '.is-guest': {
      '#header-panel-bar': {
        '#chat-button': {
          'width': '33%',
          'span': { 'display': 'none' }
        },
        '#users-button': {
          'left': '33%',
          'width': '34%'
        },
        '#waitlist-button': {
          'left': '67%',
          'width': '33%'
        },
        '#friends-button': { 'display': 'none' }
      },
      '#user-lists': {
        // even the staff one doesn't work for guest users!
        '.button.staff, .button.ignored': { 'display': 'none' }
      },
      '#footer-user': {
        '.signup': { 'width': '40%' },
        '.signup.login': {
          'margin-left': 'calc(40% + 1px)',
          'width': 'calc(40% - 1px)',
          'background': '#555d70'
        },
        '.buttons': {
          'display': 'block',
          '.button': { 'display': 'none' },
          '.button.extplug-guest-settings': {
            'display': 'block',
            'margin-left': '80%'
          }
        }
      },
      '#user-menu .item:not(.settings)': {
        'display': 'none'
      },
      '#room-bar': {
        '.extplug-room-bar-overlay': {
          'height': 'inherit',
          'width': 'inherit',
          'position': 'absolute',
          'z-index': 10
        }
      }
    }
  },

  enable() {
    // Presumably, this isn't the first time someone has used plug.dj.
    this.skipWalkthrough();

    this.$settings = $('<div />')
      .addClass('button settings extplug-guest-settings')
      .attr('data-tooltip', Lang.userMenu.settings)
      .attr('data-tooltip-dir', 'left')
      .append($('<i />').addClass('icon icon-settings-white'))
      .appendTo('#footer-user .buttons')
      .on('click', this.onSettings);

    // add login button
    this.$signup = $('#footer-user .signup')
      .find('span')
        .text(Lang.signup.signup)
      .end();
    this.$login = $('<div />')
      .addClass('signup login')
      .append($('<span />').text(Lang.signup.login))
      .insertAfter(this.$signup)
      .on('click', this.login.bind(this));

    // disable saving settings to the server when not logged in
    this.ssaAdvice = around(SaveSettingsAction.prototype, 'execute', () => {
      // do nothing \o/
    });

    this.$roomBar = $('<div />').addClass('extplug-room-bar-overlay')
      .appendTo('#room-bar')
      .on('click', e => {
        e.stopPropagation();
        if ($('#room-settings').is(':visible')) {
          Events.trigger('hide:settings');
        }
        else {
          Events.trigger('show:settings');
        }
      });

    this._enabled = true;
  },

  disable() {
    if (this._enabled) {
      this.ssaAdvice.remove();
      this.$settings.remove();
      this.$roomBar.remove();
      this.$login.remove();
      this.$signup.find('span').text(Lang.signup.signupFree);
      this.$settings = this.$login = this.$signup = null;
    }

    this._enabled = false;
  },

  skipWalkthrough() {
    const roomView = this.ext.appView.room;
    currentUser.off('change:walkthrough', roomView.onWTChange);
    roomView.onWTFinish();
  },

  login() {
    const app = this.ext.appView;
    app.showSignUp();
    app.signup.swap('login');
    // show email login by default
    $('.sign-up-overlay .box').addClass('show-email');
    $('.email-login input.email').focus();
  },

  onSettings(e) {
    e.stopPropagation();
    Events.trigger('tooltip:hide')
          .trigger('show:user', 'settings', 'extplug');
  }

});

{'fraction_non_alphanumeric': 0.1923763386027537, 'fraction_numerical': 0.006884242733299337, 'mean_word_length': 2.114331083763398, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '5365594', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2456, 'n_words': 480}