<commit_before>// Playlist functions
/* jshint esversion: 6 */
var searchString;
var searchablePlaylistInfo;
var sortable;
var dontSet = true;
//const soundInfoManager = require("./soundInfoManager");

/**
 *	@desc:	Makes the playlist sortable - should probably make this also populate it
 *	@param:	soundInfo: The soundInfo object
 */
function buildPlaylist() {
	var el = document.getElementById('playlist-songs');
	sortable = Sortable.create(el, {
		animation: 50,
		onSort: function (evt) {
			var first = true;
			var sounds = $('.playlistSound');
			// Go through each sound from first to where the dragged item was moved to
			for(i = 0; i < evt.newIndex + 2; i++){
				if(sounds[i] === undefined){return;}
				var style = window.getComputedStyle(sounds[i]);
				if(style.display !== 'none'){
					if(first){
						$(sounds[i]).css('background-color', 'var(--aM)');
						first = false;
					} else {
						$(sounds[i]).css('background-color', 'var(--bgL)');
					}
				}
			}
    	},
		store: {
			/**
			 * Get the order of elements. Called once during initialization.
			 * @param   {Sortable}  sortable
			 * @returns {Array}
			 */
			get: function (sortable) {
				var order = settingsInfo.playlist.order;
				console.log(order);
				return order ? order.split('|') : [];
			},

			/**
			 * Save the order of elements. Called onEnd (when the item is dropped).
			 * @param {Sortable}  sortable
			 */
			set: function (sortable) {
				if(dontSet){return;}
				var order = sortable.toArray();
				settingsInfo.playlist.order = order.join('|');
				storage.storeObj('settings', settingsInfo);
			}
		}
	});

}


$(document).ready(function() {

	// Disable search function until it stops giving errors, then allow it
	$('#playlist-search').prop('disabled', true);
	searchablePlaylistInfo = util.cloneObj(playlistInfo);
	searchString = '//*[contains(name, \"'+ 'poop' + '\")]';
	var testSearchInterval = setInterval(function(){
		try {
			var search = JSON.search(searchablePlaylistInfo, searchString);
		} catch (e) {
			return;
		}
		$('#playlist-search').prop('disabled', false);
		clearInterval(testSearchInterval);
	}, 200);

});

$('.search').on('keyup paste', function(e){
	/*if(keyboardMap[e.which] === 'SPACE'){
		var firstPlaylistSound = getFirstPlaylistItem();
		sounds.playSound(playlistInfo[firstPlaylistSound]);
		searchString = $('.search').val();
		$('.search').val(searchString.substring(0,searchString.length-1)).blur();

		return false;
	}*/
	if(keyboardMap[e.which] === 'ENTER'){
			$('.search').blur();
			return false;
	}
	if($('.search').val().length < 1){
		$('.playlistSound').show();
		return;
	}
	if($('.search').val().length > 1){
		searchablePlaylistInfo = util.cloneObj(playlistInfo);
		Object.keys(searchablePlaylistInfo).map(function(prop, index) {
			delete searchablePlaylistInfo[prop].howl;
		});
	}
	searchString = '//*[contains(name, \"'+ $('.search').val() + '\")]';
	var search = JSON.search(searchablePlaylistInfo, searchString);
	$('.playlistSound').each(function(){
		$(this).hide();
		$(this).css('background-color', 'var(--bgL)');
	});
	if(search.length > 0){
		for(i = 0; i < search.length; i++){
			$('#' + search[i].id).show();
			if(i === 0){
				$('#' + search[i].id).css('background-color', 'var(--aM)');
			}
		}
	}
});

function getFirstPlaylistItem(){
	var playlist = $('.playlistSound');
	for(var i = 0; i < playlist.length; i++){
		var style = window.getComputedStyle(playlist[i]);
		if(style.display !== 'none'){
			return playlist[i].id;
		}
	}
	return 'no sounds!'; // Returns this if no results
}

function registerPlaylistItems(){
	Object.keys(playlistInfo).map(function(id, index) {
		// Ensure all parameters are up to date
		storage.checkAgainstDefault(playlistInfo[id], 'soundInfo');
		view.createPlaylistItem(playlistInfo[id]);
		$("#" + playlistInfo[id].id).find('.audioName').text(playlistInfo[id].name);
		sounds.register(playlistInfo[id]);
	});

	// Set Sortable list
	setOrder();
}

function empty(){
	$('#confirm-empty-modal').modal('open');
    $('#confirm-empty-modal-Okay').click(function(){
		storage.emptyObj('playlistInfo', playlistInfo);
		$('#playlist-songs').empty();
	});
}

function saveOrder(){
	dontSet = false;
	sortable.save();
	dontSet = true;
	$('.btn-playlist-actions').dropdown('close');
}

function setOrder(){
	sortable.sort(sortable.options.store.get(sortable));
	var first = true;
	var sounds = $('.playlistSound');
	// Reset colors properly
	for(i = 0; i < sounds.length; i++){
		if(sounds[i] === undefined){return;}
		var style = window.getComputedStyle(sounds[i]);
		if(style.display !== 'none'){
			if(first){
				$(sounds[i]).css('background-color', 'var(--aM)');
				first = false;
			} else {
				$(sounds[i]).css('background-color', 'var(--bgL)');
			}
		}
	}

}


module.exports = {<commit_msg>close dropdown on playlist order reset<commit_after>// Playlist functions
/* jshint esversion: 6 */
var searchString;
var searchablePlaylistInfo;
var sortable;
var dontSet = true;
//const soundInfoManager = require("./soundInfoManager");

/**
 *	@desc:	Makes the playlist sortable - should probably make this also populate it
 *	@param:	soundInfo: The soundInfo object
 */
function buildPlaylist() {
	var el = document.getElementById('playlist-songs');
	sortable = Sortable.create(el, {
		animation: 50,
		onSort: function (evt) {
			var first = true;
			var sounds = $('.playlistSound');
			// Go through each sound from first to where the dragged item was moved to
			for(i = 0; i < evt.newIndex + 2; i++){
				if(sounds[i] === undefined){return;}
				var style = window.getComputedStyle(sounds[i]);
				if(style.display !== 'none'){
					if(first){
						$(sounds[i]).css('background-color', 'var(--aM)');
						first = false;
					} else {
						$(sounds[i]).css('background-color', 'var(--bgL)');
					}
				}
			}
    	},
		store: {
			/**
			 * Get the order of elements. Called once during initialization.
			 * @param   {Sortable}  sortable
			 * @returns {Array}
			 */
			get: function (sortable) {
				var order = settingsInfo.playlist.order;
				console.log(order);
				return order ? order.split('|') : [];
			},

			/**
			 * Save the order of elements. Called onEnd (when the item is dropped).
			 * @param {Sortable}  sortable
			 */
			set: function (sortable) {
				if(dontSet){return;}
				var order = sortable.toArray();
				settingsInfo.playlist.order = order.join('|');
				storage.storeObj('settings', settingsInfo);
			}
		}
	});

}


$(document).ready(function() {

	// Disable search function until it stops giving errors, then allow it
	$('#playlist-search').prop('disabled', true);
	searchablePlaylistInfo = util.cloneObj(playlistInfo);
	searchString = '//*[contains(name, \"'+ 'poop' + '\")]';
	var testSearchInterval = setInterval(function(){
		try {
			var search = JSON.search(searchablePlaylistInfo, searchString);
		} catch (e) {
			return;
		}
		$('#playlist-search').prop('disabled', false);
		clearInterval(testSearchInterval);
	}, 200);

});

$('.search').on('keyup paste', function(e){
	/*if(keyboardMap[e.which] === 'SPACE'){
		var firstPlaylistSound = getFirstPlaylistItem();
		sounds.playSound(playlistInfo[firstPlaylistSound]);
		searchString = $('.search').val();
		$('.search').val(searchString.substring(0,searchString.length-1)).blur();

		return false;
	}*/
	if(keyboardMap[e.which] === 'ENTER'){
			$('.search').blur();
			return false;
	}
	if($('.search').val().length < 1){
		$('.playlistSound').show();
		return;
	}
	if($('.search').val().length > 1){
		searchablePlaylistInfo = util.cloneObj(playlistInfo);
		Object.keys(searchablePlaylistInfo).map(function(prop, index) {
			delete searchablePlaylistInfo[prop].howl;
		});
	}
	searchString = '//*[contains(name, \"'+ $('.search').val() + '\")]';
	var search = JSON.search(searchablePlaylistInfo, searchString);
	$('.playlistSound').each(function(){
		$(this).hide();
		$(this).css('background-color', 'var(--bgL)');
	});
	if(search.length > 0){
		for(i = 0; i < search.length; i++){
			$('#' + search[i].id).show();
			if(i === 0){
				$('#' + search[i].id).css('background-color', 'var(--aM)');
			}
		}
	}
});

function getFirstPlaylistItem(){
	var playlist = $('.playlistSound');
	for(var i = 0; i < playlist.length; i++){
		var style = window.getComputedStyle(playlist[i]);
		if(style.display !== 'none'){
			return playlist[i].id;
		}
	}
	return 'no sounds!'; // Returns this if no results
}

function registerPlaylistItems(){
	Object.keys(playlistInfo).map(function(id, index) {
		// Ensure all parameters are up to date
		storage.checkAgainstDefault(playlistInfo[id], 'soundInfo');
		view.createPlaylistItem(playlistInfo[id]);
		$("#" + playlistInfo[id].id).find('.audioName').text(playlistInfo[id].name);
		sounds.register(playlistInfo[id]);
	});

	// Set Sortable list
	setOrder();
}

function empty(){
	$('#confirm-empty-modal').modal('open');
    $('#confirm-empty-modal-Okay').click(function(){
		storage.emptyObj('playlistInfo', playlistInfo);
		$('#playlist-songs').empty();
	});
}

function saveOrder(){
	dontSet = false;
	sortable.save();
	dontSet = true;
	$('.btn-playlist-actions').dropdown('close');
}

function setOrder(){
	sortable.sort(sortable.options.store.get(sortable));
	var first = true;
	var sounds = $('.playlistSound');
	// Reset colors properly
	for(i = 0; i < sounds.length; i++){
		if(sounds[i] === undefined){return;}
		var style = window.getComputedStyle(sounds[i]);
		if(style.display !== 'none'){
			if(first){
				$(sounds[i]).css('background-color', 'var(--aM)');
				first = false;
			} else {
				$(sounds[i]).css('background-color', 'var(--bgL)');
			}
		}
	}
	$('.btn-playlist-actions').dropdown('close');

}


module.exports = {
{'fraction_non_alphanumeric': 0.19743907476249484, 'fraction_numerical': 0.003510945890128046, 'mean_word_length': 3.9974200206398347, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '321309', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3263, 'n_words': 648}