<commit_before>var master = $('.igraphic-graphic.witnesses');

var Velocity = require('velocity-animate');

// This file will convert the raw data into something usable.
var prepareData = require('../../../common/js/prepareData.js');

// function setupSection() {

// }

function getCategories(array) {

	return _.chain(array)
		.pluck('category')
		.uniq()
		.sortBy(function(v) {
			return v;		
		})
		.value();
}

function filterItems(category, parent) {
	var items = $('ul.list > li', parent);

	if (category === 'All') {

		// if 'All', show all items
		items.show();

	} else {

		// else only show category items
		items.hide();
		$("ul.list li[data-category='" + category + "']", parent).show();
	}
}

function handleCategoryClick(e) {

	var ul = $(this).parents('ul');
	var parent = ul.parents('section');
	var buttons = $('button', ul);

	// disable all the other buttons
	buttons.addClass('btn--disabled');

	// and enable this one
	$(this).removeClass('btn--disabled');

	// find this category
	var chosenCategory = $(this).text().trim();

	// and filter witnesses accordingly
	filterItems(chosenCategory, parent);
}

function handleShayBrawnClick(e) {

	var animationOptions = {
		duration: 400,
		easing: [0.23, 1, 0.32, 1]
	};

	var parent = $(this).parents('li');

	var drawerSpacerHeight = 0;

	// drawer is expanded
	if (parent.hasClass('expanded')) {

		// animate shaybrawn down
		$('.to-down', this).get(0).beginElement();

		// collapse spacer
		Velocity($('.drawer-spacer', parent), {
			height: 0
		}, animationOptions);

	} else {

		// drawer is collapsed
		// animate shaybrawn up
		$('.to-up', this).get(0).beginElement();

		// find the right drawer spacer height
		drawerSpacerHeight = $('.drawer', parent).outerHeight(true);

		// expand drawer spacer
		Velocity($('.drawer-spacer', parent), {
			height: drawerSpacerHeight
		}, animationOptions);
	}

	parent.toggleClass('expanded');
}

function handleDrawerClick(e) {

	var parent = $(this).parents('li');

	// if drawer is closed, expand it
	if (!parent.hasClass('expanded')) {

		$('.shaybrawn', parent).click();
	}
}

// if there is a hash in location, navigate to it
function dealWithHash() {

	var key;
	var anchor;

	if (location.hash) {

		key = location.hash.replace('#', '');
		anchor = getAnchorByKey(key);
		anchor.get(0).scrollIntoView();
		expandDrawerByAnchor(anchor);
	}
}

function getAnchorByKey(key) {
	return $('a[name="' + key + '"]');
}

function expandDrawerByAnchor(anchor) {

	var match = anchor.parents('li');

	// if this drawer is collapsed, expand it
	if (!match.hasClass('expanded')) {
		$('.shaybrawn', match).click();
	}
}

window.loadedTsarnaevTrial = function(json) {

	var data = prepareData(json);

	var witnessesArray = _.values(data.witnesses);
	var witnessesDict = data.witnesses;

	var evidenceArray = _.values(data.evidences);
	var evidenceDict = data.evidences;

	var witnessCategories = ['All'].concat(getCategories(witnessesArray));
	var evidenceCategories = ['All'].concat(getCategories(evidenceArray));

	var $witnesses = $('section.witnesses', master);
	var $evidence = $('section.evidence', master);

	$('ul.categories', $witnesses)
		.html(_.templates.categories({
			categories: witnessCategories
		}))
		.on('click', 'button', handleCategoryClick);

	$('ul.categories', $evidence)
		.html(_.templates.categories({
			categories: evidenceCategories
		}))
		.on('click', 'button', handleCategoryClick);

	$witnesses.on('click', '.shaybrawn', handleShayBrawnClick);
	$evidence.on('click', '.shaybrawn', handleShayBrawnClick);

	$witnesses.on('click', '.wrapper', handleDrawerClick);
	$evidence.on('click', '.wrapper', handleDrawerClick);

	$('ul.list', $witnesses).html(_.templates.witnesses({
		witnesses: witnessesArray,
		evidences: evidenceDict,
		categories: witnessCategories
	}));

	$('ul.list', $evidence).html(_.templates.evidence({
		evidences: evidenceArray,
		witnesses: witnessesDict,
		categories: evidenceCategories
	}));

	$('ul.categories li:eq(0) button', $witnesses).click();
	$('ul.categories li:eq(0) button', $evidence).click();

	$('section', master).on('click', '.associated a', function(e) {

		e.preventDefault();

		var key = $(this).attr('href').replace('#', '');

		var anchor = getAnchorByKey(key);
		var drawer = anchor.parents('li');
		var category;

		// if the drawer isn't visible,
		if (!drawer.is(':visible')) {

			// the user has hidden it via a category button.
			// so find the category button, click it, then do the rest.

			// is this witness?<commit_msg>add documentation<commit_after>var master = $('.igraphic-graphic.witnesses');

var Velocity = require('velocity-animate');

// This file will convert the raw data into something usable.
var prepareData = require('../../../common/js/prepareData.js');

// function setupSection() {

// }

function getCategories(array) {

	return _.chain(array)
		.pluck('category')
		.uniq()
		.sortBy(function(v) {
			return v;		
		})
		.value();
}

function filterItems(category, parent) {
	var items = $('ul.list > li', parent);

	if (category === 'All') {

		// if 'All', show all items
		items.show();

	} else {

		// else only show category items
		items.hide();
		$("ul.list li[data-category='" + category + "']", parent).show();
	}
}

function handleCategoryClick(e) {

	var ul = $(this).parents('ul');
	var parent = ul.parents('section');
	var buttons = $('button', ul);

	// disable all the other buttons
	buttons.addClass('btn--disabled');

	// and enable this one
	$(this).removeClass('btn--disabled');

	// find this category
	var chosenCategory = $(this).text().trim();

	// and filter witnesses accordingly
	filterItems(chosenCategory, parent);
}

function handleShayBrawnClick(e) {

	var animationOptions = {
		duration: 400,
		easing: [0.23, 1, 0.32, 1]
	};

	var parent = $(this).parents('li');

	var drawerSpacerHeight = 0;

	// drawer is expanded
	if (parent.hasClass('expanded')) {

		// animate shaybrawn down
		$('.to-down', this).get(0).beginElement();

		// collapse spacer
		Velocity($('.drawer-spacer', parent), {
			height: 0
		}, animationOptions);

	} else {

		// drawer is collapsed
		// animate shaybrawn up
		$('.to-up', this).get(0).beginElement();

		// find the right drawer spacer height
		drawerSpacerHeight = $('.drawer', parent).outerHeight(true);

		// expand drawer spacer
		Velocity($('.drawer-spacer', parent), {
			height: drawerSpacerHeight
		}, animationOptions);
	}

	parent.toggleClass('expanded');
}

function handleDrawerClick(e) {

	var parent = $(this).parents('li');

	// if drawer is closed, expand it
	if (!parent.hasClass('expanded')) {

		$('.shaybrawn', parent).click();
	}
}

// if there is a hash in location, navigate to it
function dealWithHash() {

	var key;
	var anchor;

	if (location.hash) {

		key = location.hash.replace('#', '');
		anchor = getAnchorByKey(key);
		anchor.get(0).scrollIntoView();
		expandDrawerByAnchor(anchor);
	}
}

function getAnchorByKey(key) {
	return $('a[name="' + key + '"]');
}

function expandDrawerByAnchor(anchor) {

	var match = anchor.parents('li');

	// if this drawer is collapsed, expand it
	if (!match.hasClass('expanded')) {
		$('.shaybrawn', match).click();
	}
}

window.loadedTsarnaevTrial = function(json) {

	// Parse incoming JSON feed into something useful.
	var data = prepareData(json);

	// Create several convenience arrays and dictionaries.
	var witnessesArray = _.values(data.witnesses);
	var witnessesDict = data.witnesses;
	var evidenceArray = _.values(data.evidences);
	var evidenceDict = data.evidences;
	var witnessCategories = ['All'].concat(getCategories(witnessesArray));
	var evidenceCategories = ['All'].concat(getCategories(evidenceArray));

	// Create convenience jQuery variables.
	var $witnesses = $('section.witnesses', master);
	var $evidence = $('section.evidence', master);

	// Create the witness category buttons and wire them up.
	$('ul.categories', $witnesses)
		.html(_.templates.categories({
			categories: witnessCategories
		}))
		.on('click', 'button', handleCategoryClick);

	// Create the evidence category buttons and wire them up.
	$('ul.categories', $evidence)
		.html(_.templates.categories({
			categories: evidenceCategories
		}))
		.on('click', 'button', handleCategoryClick);

	// Wire up the drawer chevrons.
	$('section', master).on('click', '.shaybrawn', handleShayBrawnClick);

	// Wire up the drawers (if collapsed, clicking should open it).
	$('section').on('click', '.wrapper', handleDrawerClick);

	// Create the witness list.
	$('ul.list', $witnesses).html(_.templates.witnesses({
		witnesses: witnessesArray,
		evidences: evidenceDict,
		categories: witnessCategories
	}));

	// Create the evidence list.
	$('ul.list', $evidence).html(_.templates.evidence({
		evidences: evidenceArray,
		witnesses: witnessesDict,
		categories: evidenceCategories
	}));

	// Click the first category buttons (All).
	$('section ul.categories li:eq(0) button', master).click();

	// Wire up the associated links.
	$('section', master).on('click', '.associated a', function(e) {

		e.preventDefault();

		var key = $(this).attr('href').replace('#', '');

		var anchor = getAnchorByKey(key);
		var drawer = anchor.parents('li');
		var category;

		// if the drawer isn't visible,
		if (!drawer.is(':visible')) {

			// the user has hidden it via a category button.
			// so find the category button, click it, then do the rest.

			// is this witness?
{'fraction_non_alphanumeric': 0.1714498299319728, 'fraction_numerical': 0.003720238095238095, 'mean_word_length': 4.11636759108211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2987048', 'n_tokens_mistral': 3275, 'n_tokens_neox': 2925, 'n_words': 751}