<commit_before>/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter;
var small_screen = require('../is-small-screen');
var ocreate = require('../object-create');

var regex = require('../regex');
var i18n = require('../i18n');
var bind = require('../bind');
var _ = require('underscore');
var okeys = _.keys;

/**
 * Expose `OptionsManager`
 */

module.exports = OptionsManager;

/**
 * Create an `OptionsManager` from
 * instanceOptions and displayOptions
 *
 * @param {Auth0Lock} widget
 * @param {Object} displayOptions
 * @constructor
 */

function OptionsManager(widget, options) {
  if (!(this instanceof OptionsManager)) {
    return new OptionsManager(widget, options);
  }

  // Initiate `EventEmitter`
  EventEmitter.call(this);

  // Flag OptionsManager as `unloaded`
  this.state('loading');

  // holds widget as reference
  this.$widget = widget;

  // save widget's $client object reference
  this.$client = widget.$client;

  // save copy of widget's valid strategies
  this.$strategies = widget.$strategies;

  // save widget's `auth0-js` instance object
  this.$auth0 = widget.$auth0;


  // save widget instance options with `$` prepended
  _.each(okeys(widget.$options), function(key) {
    this['$' + key] = widget.$options[key];
  }, this);

  // copies all provided options to instance
  // filtering by allowed options `whitelist`
  _.each(okeys(options), function(key) {
    // we should whitelist options
    // so no OptionsManager method gets overriden
    // by user configurable object
    // XXX: Broken, fix it!
    // if (!~whitelist.indexOf(key) && !~supportedParams.indexOf(key)) return;
    this[key] = options[key];
  }, this);

  // Set `i18n` dictionary for templates
  this.i18n = i18n.getDict(this.dict);

  // default authParams to empty object
  this.authParams = _.extend({}, options.authParams);

  // enable/disable last login and AD discovery
  this.rememberLastLogin = null != options.rememberLastLogin ? !!options.rememberLastLogin : true;
  this.integratedWindowsLogin = null != options.integratedWindowsLogin ? !!options.integratedWindowsLogin : true;


  // enable/disable gravatar image fetch
  this.gravatar = null != options.gravatar ? !!options.gravatar : true;

  // If popupCallback, enable popup mode
  if ('function' === typeof options.popupCallback) {
    this.popup = true;
    // XXX: the following to should already come with
    // the options from constructor... right?
    this.popupOptions = _.extend({}, options.popupOptions);
    this.popupCallback = options.popupCallback;
  }

  // save default responseType
  if (options.responseType) {
    this.responseType = options.responseType;
  } else {
    this.responseType = (this.popup || !options.callbackURL) ? 'token' : 'code';
  }

  // Options moved from constructor and hacked into `auth0-js` instance
  this.$auth0._useJSONP = options.forceJSONP || this.$auth0._useJSONP;
  this.$auth0._callbackURL = options.callbackURL || this.$auth0._callbackURL;
  this.$auth0._callbackOnLocationHash = 'token' === this.responseType || !!this.$auth0._callbackOnLocationHash;

  // force `closable` when provided with `container`
  this.closable = null != options.closable ? !!options.closable : !this.container;

  // Delay options requiring $client configuration
  this.$widget.getClientConfiguration(bind(this._onclientloaded, this));
}

/**
 * Inherit from `EventEmitter`
 */

OptionsManager.prototype = ocreate(EventEmitter.prototype);

/**<commit_msg>sso is true by default<commit_after>/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter;
var small_screen = require('../is-small-screen');
var ocreate = require('../object-create');

var regex = require('../regex');
var i18n = require('../i18n');
var bind = require('../bind');
var _ = require('underscore');
var okeys = _.keys;

/**
 * Expose `OptionsManager`
 */

module.exports = OptionsManager;

/**
 * Create an `OptionsManager` from
 * instanceOptions and displayOptions
 *
 * @param {Auth0Lock} widget
 * @param {Object} displayOptions
 * @constructor
 */

function OptionsManager(widget, options) {
  if (!(this instanceof OptionsManager)) {
    return new OptionsManager(widget, options);
  }

  // Initiate `EventEmitter`
  EventEmitter.call(this);

  // Flag OptionsManager as `unloaded`
  this.state('loading');

  // holds widget as reference
  this.$widget = widget;

  // save widget's $client object reference
  this.$client = widget.$client;

  // save copy of widget's valid strategies
  this.$strategies = widget.$strategies;

  // save widget's `auth0-js` instance object
  this.$auth0 = widget.$auth0;

  // save widget instance options with `$` prepended
  _.each(okeys(widget.$options), function(key) {
    this['$' + key] = widget.$options[key];
  }, this);

  // copies all provided options to instance
  // filtering by allowed options `whitelist`
  _.each(okeys(options), function(key) {
    // we should whitelist options
    // so no OptionsManager method gets overriden
    // by user configurable object
    // XXX: Broken, fix it!
    // if (!~whitelist.indexOf(key) && !~supportedParams.indexOf(key)) return;
    this[key] = options[key];
  }, this);

  // Set `i18n` dictionary for templates
  this.i18n = i18n.getDict(this.dict);

  // default authParams to empty object
  this.authParams = _.extend({}, options.authParams);

  // enable/disable last login and AD discovery
  this.rememberLastLogin = null != options.rememberLastLogin ? !!options.rememberLastLogin : true;
  this.integratedWindowsLogin = null != options.integratedWindowsLogin ? !!options.integratedWindowsLogin : true;


  // enable/disable gravatar image fetch
  this.gravatar = null != options.gravatar ? !!options.gravatar : true;

  // If popupCallback, enable popup mode
  if ('function' === typeof options.popupCallback) {
    this.popup = true;
    // XXX: the following to should already come with
    // the options from constructor... right?
    this.popupOptions = _.extend({}, options.popupOptions);
    this.popupCallback = options.popupCallback;
  }

  // save default responseType
  if (options.responseType) {
    this.responseType = options.responseType;
  } else {
    this.responseType = (this.popup || !options.callbackURL) ? 'token' : 'code';
  }

  // Options moved from constructor and hacked into `auth0-js` instance
  this.$auth0._useJSONP = options.forceJSONP || this.$auth0._useJSONP;
  this.$auth0._callbackURL = options.callbackURL || this.$auth0._callbackURL;
  this.$auth0._callbackOnLocationHash = 'token' === this.responseType || !!this.$auth0._callbackOnLocationHash;

  // force `closable` when provided with `container`
  this.closable = null != options.closable ? !!options.closable : !this.container;


  // SSO by default. User&Password can be authenticated with an ajax call
  // However, since this call is CORS or JSONP it will not set the cookie,
  // hence SSO will not work.
  // To enable Ajax/jsonp/cors use sso: false.
  this.sso = null != this.sso ? !!this.sso : true;

  // Delay options requiring $client configuration
  this.$widget.getClientConfiguration(bind(this._onclientloaded, this));
}

/**
 * Inherit from `EventEmitter`
 */

OptionsManager.prototype = ocreate(EventEmitter.prototype);

/**
{'fraction_non_alphanumeric': 0.1365197088312045, 'fraction_numerical': 0.0057684384013185, 'mean_word_length': 3.787639710716634, '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': '4711443', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2101, 'n_words': 575}