<commit_before>var getValue = function(inp) {
  var $val = undefined;

  // special case for our multi-select list object
  if ($(inp).hasClass("multiSelectList")) {
    var $ul = $(inp).parent().next();
    return clientShared.typeaheadSelectListGetLIs($ul);
  }

  // special case for single-reference selector
  if ($(inp).hasClass("referenceSingleSelect")) {
    var $div = $(inp).parent().next();
    return $div.find('p').data('id');
  }

  // special case for multiple-reference selector
  if ($(inp).hasClass("referenceMultiSelect")) {
    var results = [],
        $ul = $(inp).parent().next();
    $ul.find('li').each(function(i, li){
      results.push($(li).data('id'));
    })
    return results;
  }

  // otherwise it's a standard html input
  val = undefined;
  switch (inp.type) {
    case "text":
    case "hidden":
    case "textarea":
    case "url":
      val = inp.value;
      break;
    case "number":
      val = parseFloat(inp.value, 10);
      if (isNaN(val)) val = undefined;
      break;
    case "checkbox":
      val = inp.checked;
      break;
    case "select-one":
      val = $(inp).find('option:selected').val();
      break;
    default:
      console.log('input not recognized');
  }
  return val;
},
b64toBlob = function(b64, contentType, sliceSize) {
  var byteArray, byteArrays, byteCharacters, byteNumbers, i, offset, slice;
  contentType = contentType || '';
  sliceSize = sliceSize || 512;
  byteCharacters = window.atob(b64);
  byteArrays = [];
  offset = 0;

  while (offset < byteCharacters.length) {
    slice = byteCharacters.slice(offset, offset + sliceSize);
    byteNumbers = new Array(slice.length);
    i = 0;
    while (i < slice.length) {
      byteNumbers[i] = slice.charCodeAt(i);
      i++;
    }
    byteArray = new Uint8Array(byteNumbers);
    byteArrays.push(byteArray);
    offset += sliceSize;
  }

  return new Blob(byteArrays, {type: contentType});
},
s2ab = function(s) {
  var buf = new ArrayBuffer(s.length),
      view = new Uint8Array(buf),
      i, j, ref;
  for (i = j = 0, ref = s.length; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
    view[i] = s.charCodeAt(i) & 0xFF;
  }
  return buf;
};

// template-utility functions
clientShared = {
  createErrorDiv: function(context) {
    var  msg, ul = $("<ul>");

    context.invalidKeys().forEach(function(obj){
      msg = undefined;
      try {
        msg = context.keyErrorMessage(obj.name);
      } catch (err) {}
      if (msg != null) {
        ul.append("<li>" + msg + "</li>");
      } else {
        ul.append("<li>" + obj.name + " is " + obj.type + "; got \"" + obj.value + "\" </li>");
      }
    });

    return $("<div class='bg-danger'>")
      .append('<p><strong>The following errors were found:</strong></p>')
      .append(ul);
  },
  activateInput: function(input) {
    input.focus();
    input.select();
  },
  updateValues: function(form, obj) {
    var obj = {}, key, val;
    $(form).find("select,input,textarea").each(function(i, inp){
      key = inp.name;
      if (key.length > 0) {
        val = getValue(inp);
        if (obj[key] !== val) obj[key] = val;
      }
    });
    return obj;
  },
  newValues: function(form) {
    var obj = {}, key;
    $(form).find("select,input,textarea").each(function(i, inp){
      key = inp.name;
      if (key.length > 0) obj[key] = getValue(inp);
    });
    return obj;
  },
  returnExcelFile: function(raw_data, fn) {
    var blob = new Blob([s2ab(raw_data)], {type: "application/octet-stream"});
    fn = fn || "download.xlsx";
    return saveAs(blob, fn);
  },
  returnWordFile: function(raw_data, fn) {
    var blob, s2ab;
    fn = fn || "download.docx";
    blob = new Blob([s2ab(raw_data)], {type: "application/octet-stream"});
    return saveAs(blob, fn);
  },
  b64toWord: function(b64, fn) {
    var blob = b64toBlob(b64, "application/octet-stream");
    fn = fn || "download.docx";
    return saveAs(blob, fn);
  },
  toggleRowVisibilty: function(display, $els) {
    return (display) ? $els.fadeIn() : $els.fadeOut();
  },
  moveRowCheck: function(evt) {
    var data, newIdx, next_pos, prev_pos, self, this_pos;
    self = $(evt.target);
    this_pos = self.data('sortidx');
    prev_pos = self.prev().data('sortidx') || 0;
    next_pos = self.next().data('sortidx') || prev_pos + 1;
    if ((this_pos < prev_pos) || (this_pos > next_pos)) {
      data = UI.getData(evt.target);
      newIdx = d3.mean([prev_pos, next_pos]);
      this.options.Cls.update(data._id, {$set: {sortIdx: newIdx}});
      return self.data('sortidx', newIdx);
    }
  },
  typeaheadSelectListAddLI: function($ul, val) {
    var txts = clientShared.typeaheadSelectListGetLIs($ul);
    if ((txts.index(val) < 0) && (val !== "")) {
      Blaze.renderWithData(Template.typeaheadSelectListLI, val, $ul[0]);
      return true;
    }
    return false;
  },
  typeaheadSelectListGetLIs: function($ul) {
    return $ul.find('li').each(function(i, li){
      return $(li).data('value');
    });
  },
  toggleRiskPlot: function() {
    var gridline_data, gridlines, header, header_pos, height, svg, tbl,
        tbl_pos, width, xPlotBuffer, x_left, xaxis, xscale, yPlotBuffer,
        y_top, yscale;

    d3.select('.epiRiskAxes').remove();
    if (!Session.get('epiRiskShowPlots')) return;
    Tracker.flush();

    header = $('.riskTR');
    tbl = $('.evidenceTable');
    tbl_pos = tbl.position();
    header_pos = header.position();<commit_msg>fix list-text bug<commit_after>var getValue = function(inp) {
  var $val = undefined;

  // special case for our multi-select list object
  if ($(inp).hasClass("multiSelectList")) {
    var $ul = $(inp).parent().next();
    return clientShared.typeaheadSelectListGetLIs($ul);
  }

  // special case for single-reference selector
  if ($(inp).hasClass("referenceSingleSelect")) {
    var $div = $(inp).parent().next();
    return $div.find('p').data('id');
  }

  // special case for multiple-reference selector
  if ($(inp).hasClass("referenceMultiSelect")) {
    var results = [],
        $ul = $(inp).parent().next();
    $ul.find('li').each(function(i, li){
      results.push($(li).data('id'));
    })
    return results;
  }

  // otherwise it's a standard html input
  val = undefined;
  switch (inp.type) {
    case "text":
    case "hidden":
    case "textarea":
    case "url":
      val = inp.value;
      break;
    case "number":
      val = parseFloat(inp.value, 10);
      if (isNaN(val)) val = undefined;
      break;
    case "checkbox":
      val = inp.checked;
      break;
    case "select-one":
      val = $(inp).find('option:selected').val();
      break;
    default:
      console.log('input not recognized');
  }
  return val;
},
b64toBlob = function(b64, contentType, sliceSize) {
  var byteArray, byteArrays, byteCharacters, byteNumbers, i, offset, slice;
  contentType = contentType || '';
  sliceSize = sliceSize || 512;
  byteCharacters = window.atob(b64);
  byteArrays = [];
  offset = 0;

  while (offset < byteCharacters.length) {
    slice = byteCharacters.slice(offset, offset + sliceSize);
    byteNumbers = new Array(slice.length);
    i = 0;
    while (i < slice.length) {
      byteNumbers[i] = slice.charCodeAt(i);
      i++;
    }
    byteArray = new Uint8Array(byteNumbers);
    byteArrays.push(byteArray);
    offset += sliceSize;
  }

  return new Blob(byteArrays, {type: contentType});
},
s2ab = function(s) {
  var buf = new ArrayBuffer(s.length),
      view = new Uint8Array(buf),
      i, j, ref;
  for (i = j = 0, ref = s.length; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
    view[i] = s.charCodeAt(i) & 0xFF;
  }
  return buf;
};

// template-utility functions
clientShared = {
  createErrorDiv: function(context) {
    var  msg, ul = $("<ul>");

    context.invalidKeys().forEach(function(obj){
      msg = undefined;
      try {
        msg = context.keyErrorMessage(obj.name);
      } catch (err) {}
      if (msg != null) {
        ul.append("<li>" + msg + "</li>");
      } else {
        ul.append("<li>" + obj.name + " is " + obj.type + "; got \"" + obj.value + "\" </li>");
      }
    });

    return $("<div class='bg-danger'>")
      .append('<p><strong>The following errors were found:</strong></p>')
      .append(ul);
  },
  activateInput: function(input) {
    input.focus();
    input.select();
  },
  updateValues: function(form, obj) {
    var obj = {}, key, val;
    $(form).find("select,input,textarea").each(function(i, inp){
      key = inp.name;
      if (key.length > 0) {
        val = getValue(inp);
        if (obj[key] !== val) obj[key] = val;
      }
    });
    return obj;
  },
  newValues: function(form) {
    var obj = {}, key;
    $(form).find("select,input,textarea").each(function(i, inp){
      key = inp.name;
      if (key.length > 0) obj[key] = getValue(inp);
    });
    return obj;
  },
  returnExcelFile: function(raw_data, fn) {
    var blob = new Blob([s2ab(raw_data)], {type: "application/octet-stream"});
    fn = fn || "download.xlsx";
    return saveAs(blob, fn);
  },
  returnWordFile: function(raw_data, fn) {
    var blob, s2ab;
    fn = fn || "download.docx";
    blob = new Blob([s2ab(raw_data)], {type: "application/octet-stream"});
    return saveAs(blob, fn);
  },
  b64toWord: function(b64, fn) {
    var blob = b64toBlob(b64, "application/octet-stream");
    fn = fn || "download.docx";
    return saveAs(blob, fn);
  },
  toggleRowVisibilty: function(display, $els) {
    return (display) ? $els.fadeIn() : $els.fadeOut();
  },
  moveRowCheck: function(evt) {
    var data, newIdx, next_pos, prev_pos, self, this_pos;
    self = $(evt.target);
    this_pos = self.data('sortidx');
    prev_pos = self.prev().data('sortidx') || 0;
    next_pos = self.next().data('sortidx') || prev_pos + 1;
    if ((this_pos < prev_pos) || (this_pos > next_pos)) {
      data = UI.getData(evt.target);
      newIdx = d3.mean([prev_pos, next_pos]);
      this.options.Cls.update(data._id, {$set: {sortIdx: newIdx}});
      return self.data('sortidx', newIdx);
    }
  },
  typeaheadSelectListAddLI: function($ul, val) {
    var txts = clientShared.typeaheadSelectListGetLIs($ul);
    if ((val !== "") && (!_.contains(txts, val))) {
      Blaze.renderWithData(Template.typeaheadSelectListLI, val, $ul[0]);
      return true;
    }
    return false;
  },
  typeaheadSelectListGetLIs: function($ul) {
    return _.map(
        $ul.find('li'),
        function(li){return li.getAttribute('data-value');});
  },
  toggleRiskPlot: function() {
    var gridline_data, gridlines, header, header_pos, height, svg, tbl,
        tbl_pos, width, xPlotBuffer, x_left, xaxis, xscale, yPlotBuffer,
        y_top, yscale;

    d3.select('.epiRiskAxes').remove();
    if (!Session.get('epiRiskShowPlots')) return;
    Tracker.flush();

    header = $('.riskTR');
    tbl = $('.evidenceTable');
    tbl_pos = tbl.position();
    header_pos = header.position();
{'fraction_non_alphanumeric': 0.1780431786862655, 'fraction_numerical': 0.00707395498392283, 'mean_word_length': 2.9427743571169866, 'pattern_counts': {'":': 14, '<': 36, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2942715', 'n_tokens_mistral': 3875, 'n_tokens_neox': 3740, 'n_words': 817}