<commit_before>/*
 * Copyright 2009-2011 Mozilla Foundation and contributors
 * Licensed under the New BSD license. See LICENSE.txt or:
 * http://opensource.org/licenses/BSD-3-Clause
 */

define(function(require, exports, module) {


var util = require('gcli/util');
var domtemplate = require('gcli/ui/domtemplate');

var completerHtml = require('text!gcli/ui/completer.html');

/**
 * Completer is an 'input-like' element that sits  an input element annotating
 * it with visual goodness.
 * @param {object} options An object that contains various options which
 * customizes how the completer functions.
 * Properties on the options object:
 * - document (required) DOM document to be used in creating elements
 * - requisition (required) A GCLI Requisition object whose state is monitored
 * - completeElement (optional) An element to use
 * - completionPrompt (optional) The prompt - defaults to '\u00bb'
 *   (double greater-than, a.k.a right guillemet). The prompt is used directly
 *   in a TextNode, so HTML entities are not allowed.
 */
function Completer(options) {
  this.document = options.document || document;
  this.requisition = options.requisition;
  this.elementCreated = false;
  this.scratchpad = options.scratchpad;
  this.inputter = options.inputter;
  this.input = { typed: '', cursor: { start: 0, end: 0 } };

  this.element = options.completeElement || 'gcli-row-complete';
  if (typeof this.element === 'string') {
    var name = this.element;
    this.element = this.document.getElementById(name);

    if (!this.element) {
      this.elementCreated = true;
      this.element = util.createElement(this.document, 'div');
      this.element.className = 'gcli-in-complete gcli-in-valid';
      this.element.setAttribute('tabindex', '-1');
      this.element.setAttribute('aria-live', 'polite');
    }
  }

  this.completionPrompt = typeof options.completionPrompt === 'string'
      ? options.completionPrompt
      : '\u00bb';

  if (options.inputBackgroundElement) {
    this.backgroundElement = options.inputBackgroundElement;
  }
  else {
    this.backgroundElement = this.element;
  }

  this.inputter.onInputChange.add(this.update, this);
  this.inputter.onAssignmentChange.add(this.update, this);
  this.template = util.toDom(this.document, completerHtml);
  // We want the spans to line up without the spaces in the template
  util.removeWhitespace(this.template, true);

  // If we were told which element to use, then assume it is already
  // correctly positioned. Otherwise insert it alongside the input element
  if (this.elementCreated) {
    this.decorate();
  }
  this.update();
}

/**
 * Avoid memory leaks
 */
Completer.prototype.destroy = function() {<commit_msg>Bug 726422 (toplevel): Add dontDecorate option This is a temp workaround.<commit_after>/*
 * Copyright 2009-2011 Mozilla Foundation and contributors
 * Licensed under the New BSD license. See LICENSE.txt or:
 * http://opensource.org/licenses/BSD-3-Clause
 */

define(function(require, exports, module) {


var util = require('gcli/util');
var domtemplate = require('gcli/ui/domtemplate');

var completerHtml = require('text!gcli/ui/completer.html');

/**
 * Completer is an 'input-like' element that sits  an input element annotating
 * it with visual goodness.
 * @param {object} options An object that contains various options which
 * customizes how the completer functions.
 * Properties on the options object:
 * - document (required) DOM document to be used in creating elements
 * - requisition (required) A GCLI Requisition object whose state is monitored
 * - completeElement (optional) An element to use
 * - completionPrompt (optional) The prompt - defaults to '\u00bb'
 *   (double greater-than, a.k.a right guillemet). The prompt is used directly
 *   in a TextNode, so HTML entities are not allowed.
 */
function Completer(options) {
  this.document = options.document || document;
  this.requisition = options.requisition;
  this.elementCreated = false;
  this.scratchpad = options.scratchpad;
  this.inputter = options.inputter;
  this.input = { typed: '', cursor: { start: 0, end: 0 } };

  this.element = options.completeElement || 'gcli-row-complete';
  if (typeof this.element === 'string') {
    var name = this.element;
    this.element = this.document.getElementById(name);

    if (!this.element) {
      this.elementCreated = true;
      this.element = util.createElement(this.document, 'div');
      this.element.className = 'gcli-in-complete gcli-in-valid';
      this.element.setAttribute('tabindex', '-1');
      this.element.setAttribute('aria-live', 'polite');
    }
  }

  this.completionPrompt = typeof options.completionPrompt === 'string'
      ? options.completionPrompt
      : '\u00bb';

  if (options.inputBackgroundElement) {
    this.backgroundElement = options.inputBackgroundElement;
  }
  else {
    this.backgroundElement = this.element;
  }

  this.inputter.onInputChange.add(this.update, this);
  this.inputter.onAssignmentChange.add(this.update, this);
  this.template = util.toDom(this.document, completerHtml);
  // We want the spans to line up without the spaces in the template
  util.removeWhitespace(this.template, true);

  // If we were told which element to use, then assume it is already
  // correctly positioned. Otherwise insert it alongside the input element
  if (this.elementCreated && !options.dontDecorate) {
    this.decorate();
  }
  this.update();
}

/**
 * Avoid memory leaks
 */
Completer.prototype.destroy = function() {
{'fraction_non_alphanumeric': 0.11674849972722313, 'fraction_numerical': 0.0069103473358792505, 'mean_word_length': 3.854368932038835, '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': '4858656', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1576, 'n_words': 467}