<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
  'underscore',
  'backbone',
  'jquery',
  'lib/promise',
  'lib/session',
  'lib/auth-errors',
  'lib/url',
  'lib/strings',
  'lib/ephemeral-messages',
  'lib/null-metrics',
  'views/mixins/timer-mixin'
],
function (_, Backbone, $, p, Session, AuthErrors,
      Url, Strings, EphemeralMessages, NullMetrics, TimerMixin) {
  var ENTER_BUTTON_CODE = 13;
  var DEFAULT_TITLE = window.document.title;
  var EPHEMERAL_MESSAGE_ANIMATION_MS = 150;

  // Share one ephemeral messages across all views. View can be
  // intialized with an ephemeralMessages for testing.
  var ephemeralMessages = new EphemeralMessages();

  // A null metrics instance is created for unit tests. In the app,
  // when a view is initialized, an initialized Metrics instance
  // is passed in to the contstructor.
  var nullMetrics = new NullMetrics();

  function displaySuccess(displayStrategy, msg) {
    /*jshint validthis: true*/
    this.hideError();

    if (msg) {
      this.$('.success')[displayStrategy](this.translator.get(msg));
    }

    this.$('.success').slideDown(EPHEMERAL_MESSAGE_ANIMATION_MS);
    this.trigger('success', msg);
    this._isSuccessVisible = true;
  }

  function displayError(displayStrategy, err) {
    /*jshint validthis: true*/
    this.hideSuccess();
    this.$('.spinner').hide();

    err = this._normalizeError(err);

    this.logError(err);
    var translated = this.translateError(err);

    if (translated) {
      this.$('.error')[displayStrategy](translated);
    }

    this.$('.error').slideDown(EPHEMERAL_MESSAGE_ANIMATION_MS);
    this.trigger('error', translated);

    this._isErrorVisible = true;

    return translated;
  }

  var BaseView = Backbone.View.extend({
    constructor: function (options) {
      options = options || {};

      this.subviews = [];
      this.window = options.window || window;
      this.navigator = options.navigator || this.window.navigator || navigator;
      this.translator = options.translator || this.window.translator;
      this.router = options.router || this.window.router;
      this.ephemeralMessages = options.ephemeralMessages || ephemeralMessages;<commit_msg>fix(client): Fixed missing spinner on subsequent requests.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

define([
  'underscore',
  'backbone',
  'jquery',
  'lib/promise',
  'lib/session',
  'lib/auth-errors',
  'lib/url',
  'lib/strings',
  'lib/ephemeral-messages',
  'lib/null-metrics',
  'views/mixins/timer-mixin'
],
function (_, Backbone, $, p, Session, AuthErrors,
      Url, Strings, EphemeralMessages, NullMetrics, TimerMixin) {
  var ENTER_BUTTON_CODE = 13;
  var DEFAULT_TITLE = window.document.title;
  var EPHEMERAL_MESSAGE_ANIMATION_MS = 150;

  // Share one ephemeral messages across all views. View can be
  // intialized with an ephemeralMessages for testing.
  var ephemeralMessages = new EphemeralMessages();

  // A null metrics instance is created for unit tests. In the app,
  // when a view is initialized, an initialized Metrics instance
  // is passed in to the contstructor.
  var nullMetrics = new NullMetrics();

  function displaySuccess(displayStrategy, msg) {
    /*jshint validthis: true*/
    this.hideError();

    if (msg) {
      this.$('.success')[displayStrategy](this.translator.get(msg));
    }

    this.$('.success').slideDown(EPHEMERAL_MESSAGE_ANIMATION_MS);
    this.trigger('success', msg);
    this._isSuccessVisible = true;
  }

  function displayError(displayStrategy, err) {
    /*jshint validthis: true*/
    this.hideSuccess();

    err = this._normalizeError(err);

    this.logError(err);
    var translated = this.translateError(err);

    if (translated) {
      this.$('.error')[displayStrategy](translated);
    }

    this.$('.error').slideDown(EPHEMERAL_MESSAGE_ANIMATION_MS);
    this.trigger('error', translated);

    this._isErrorVisible = true;

    return translated;
  }

  var BaseView = Backbone.View.extend({
    constructor: function (options) {
      options = options || {};

      this.subviews = [];
      this.window = options.window || window;
      this.navigator = options.navigator || this.window.navigator || navigator;
      this.translator = options.translator || this.window.translator;
      this.router = options.router || this.window.router;
      this.ephemeralMessages = options.ephemeralMessages || ephemeralMessages;
{'fraction_non_alphanumeric': 0.12876884422110552, 'fraction_numerical': 0.0037688442211055275, 'mean_word_length': 3.523674242424242, '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': '1041840', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1449, 'n_words': 370}