<commit_before>var input = document.querySelector('.form-control');
var iframe = document.querySelector('iframe');
var timestamp = $('.replay-date');
var linklist = $('.linklist');
var index = 0;
var tagIdx = 0;
var linklistData = [];

// buttons
var next = $('.btn-next');
var prev = $('.btn-prev');
var dropdown = $('.input-group-btn .dropdown-menu');

// ui event binding
next.on('click', function () {
  if(index + 1 < data[keys[tagIdx]].length)
    setInput(data[keys[tagIdx]][++index]);
});

prev.on('click', function () {
  if(index - 1 >= 0)
    setInput(data[keys[tagIdx]][--index]);
});

timestamp.on('click', function (evt) {
  evt.stopPropagation();
  console.log('click')
  linklist.toggleClass('open');
})

dropdown.on('click', 'a', function (evt) {
  evt.preventDefault();
  var newTagIdx = $(evt.target).parent().index();

  if(newTagIdx === tagIdx) return;

  tagIdx = newTagIdx;
  index = 0;
  $('.tagName').html(keys[tagIdx]);

  if(data[keys[tagIdx]].length > 0)
    setInput(data[keys[tagIdx]][0]);

  // rerender link list
  linklist.find('ul.dropdown-menu').html(linklistData[tagIdx]);
});

$(document).on('keyup', function (evt) {
  // esc key
  if(evt.keyCode === 27) {
    $('.open').removeClass('open');
  }
});


function compile_links() {
  for(var i=0; i < keys.length; i++) {
    var linkopts = '';
    if(data[keys[i]].length > 0) {
      for(var tag of data[keys[i]]) {
        var parts = tag.id.split(' ');
        linkopts += "<li>"+(parts[0].replace(/(\?.*)/, '?...'))+"<span class='replay-date'>"+TimesAndSizesFormatter.ts_to_date(parts[1])+"</span></li>";
      }
      linklistData.push(linkopts);
    } else {
      linklistData.push('<li class="disabled">No results</li>');
    }
  }
}

function setInput(obj) {
  var parts = obj.id.split(' ');
  var url = parts[0];
  var ts = parts[1];
  var total = data[keys[tagIdx]].length;

  // prev button presentation
  if(index===0){
    prev.addClass('disabled');
  } else if(index > 0 && prev.hasClass('disabled')){
    prev.removeClass('disabled');
  }

  // next button presentation
  if(index===data[keys[tagIdx]].length-1) {
    next.addClass('disabled');
  } else if(index < total - 1 && next.hasClass('disabled')) {
    next.removeClass('disabled');
  }

  input.value = '('+("0000"+(index + 1)).slice(-String(total).split('').length)+' of '+total+')  ' + url;
  timestamp.html(TimesAndSizesFormatter.ts_to_date(ts));
  iframe.src = '/_embed/'+obj.user+'/'+obj.coll+'/'+ts+(obj.br?'$br:'+obj.br:'')+'/'+url;
}


compile_links();

if(data[keys[tagIdx]].length)
  setInput(data[keys[tagIdx]][0]);

linklist.find('ul.dropdown-menu').html(linklistData[tagIdx]);
linklist.find('ul.dropdown-menu').on('click', 'li', function () {
  var newIndex = $(this).index();
  if(newIndex !== index) {
    index = newIndex;
    setInput(data[keys[tagIdx]][index]);
  }
});<commit_msg>If only one collection displaying, store index in hash<commit_after>var input = document.querySelector('.form-control');
var iframe = document.querySelector('iframe');
var timestamp = $('.replay-date');
var linklist = $('.linklist');
var index = 0;
var tagIdx = 0;
var linklistData = [];

// buttons
var next = $('.btn-next');
var prev = $('.btn-prev');
var dropdown = $('.input-group-btn .dropdown-menu');

// ui event binding
next.on('click', function () {
  if(index + 1 < data[keys[tagIdx]].length)
    setInput(data[keys[tagIdx]][++index]);
});

prev.on('click', function () {
  if(index - 1 >= 0)
    setInput(data[keys[tagIdx]][--index]);
});

timestamp.on('click', function (evt) {
  evt.stopPropagation();
  linklist.toggleClass('open');
})

dropdown.on('click', 'a', function (evt) {
  evt.preventDefault();
  var newTagIdx = $(evt.target).parent().index();

  if(newTagIdx === tagIdx) return;

  tagIdx = newTagIdx;
  index = 0;
  $('.tagName').html(keys[tagIdx]);

  if(data[keys[tagIdx]].length > 0)
    setInput(data[keys[tagIdx]][0]);

  // rerender link list
  linklist.find('ul.dropdown-menu').html(linklistData[tagIdx]);
});

$(document).on('keyup', function (evt) {
  // esc key
  if(evt.keyCode === 27) {
    $('.open').removeClass('open');
  }
});


function compile_links() {
  for(var i=0; i < keys.length; i++) {
    var linkopts = '';
    if(data[keys[i]].length > 0) {
      for(var tag of data[keys[i]]) {
        var parts = tag.id.split(' ');
        linkopts += "<li>"+(parts[0].replace(/(\?.*)/, '?...'))+"<span class='replay-date'>"+TimesAndSizesFormatter.ts_to_date(parts[1])+"</span></li>";
      }
      linklistData.push(linkopts);
    } else {
      linklistData.push('<li class="disabled">No results</li>');
    }
  }
}

function setInput(obj) {
  var parts = obj.id.split(' ');
  var url = parts[0];
  var ts = parts[1];
  var total = data[keys[tagIdx]].length;

  // prev button presentation
  if(index===0){
    prev.addClass('disabled');
  } else if(index > 0 && prev.hasClass('disabled')){
    prev.removeClass('disabled');
  }

  // next button presentation
  if(index===data[keys[tagIdx]].length-1) {
    next.addClass('disabled');
  } else if(index < total - 1 && next.hasClass('disabled')) {
    next.removeClass('disabled');
  }

  if(keys.length === 1)
    window.location.hash = index;

  input.value = '('+("0000"+(index + 1)).slice(-String(total).split('').length)+' of '+total+')  ' + url;
  timestamp.html(TimesAndSizesFormatter.ts_to_date(ts));
  iframe.src = '/_embed/'+obj.user+'/'+obj.coll+'/'+ts+(obj.br?'$br:'+obj.br:'')+'/'+url;
}


compile_links();

if(data[keys[tagIdx]].length) {
  index = parseInt(window.location.hash.slice(1), 10) || 0;
  setInput(data[keys[tagIdx]][index]);
}

linklist.find('ul.dropdown-menu').html(linklistData[tagIdx]);
linklist.find('ul.dropdown-menu').on('click', 'li', function () {
  var newIndex = $(this).index();
  if(newIndex !== index) {
    index = newIndex;
    setInput(data[keys[tagIdx]][index]);
  }
});
{'fraction_non_alphanumeric': 0.2288150042625746, 'fraction_numerical': 0.009548167092924126, 'mean_word_length': 4.065630397236615, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '4124663', 'n_tokens_mistral': 2136, 'n_tokens_neox': 2090, 'n_words': 353}