<commit_before>/* global clear_blocks */
/* global escapeHtml */
/* global new_block */
/* global formatDate */
/* global nDig */
/* global randStr */
/* global bag */
/* global $ */
var ws = {};
var user = {username: bag.setup.USER1};
var bgcolors = ["whitebg", "blackbg", "redbg", "greenbg", "bluebg", "purplebg", "pinkbg", "orangebg", "yellowbg"];

// =================================================================================
// On Load
// =================================================================================
$(document).on('ready', function() {
	connect_to_server();
	$("input[name='name']").val('r' + randStr(6));
	$("select option[value='" + bag.setup.USER1 + "']").attr('selected', true);
	
	// =================================================================================
	// jQuery UI Events
	// =================================================================================
	$("#submit").click(function(){
		var obj = 	{
						type: "create",
						name: $("input[name='name']").val().replace(" ", ""),
						color: $(".colorSelected").attr('color'),
						size: $("select[name='size']").val(),
						user: $("select[name='user']").val(),
						v: 2
					};
		if(obj.user && obj.name && obj.color){
			console.log('creating marble, sending', obj);
			ws.send(JSON.stringify(obj));
			$(".panel").hide();
			$("#homePanel").show();
			$(".colorValue").html('Color');											//reset
			for(var i in bgcolors) $(".createball").removeClass(bgcolors[i]);			//reset
			$(".createball").css("border", "2px dashed #fff");						//reset
		}
		return false;
	});

	$("#homeLink").click(function(){
		console.log('marbles:', bag.marbles);
	});
	
	$("#createLink").click(function(){
		$("input[name='name']").val('r' + randStr(6));
	});
	
	$("#tradeLink").click(function(){
		set_my_color_options(user.username);
		ws.send(JSON.stringify({type: "get_open_trades", v: 2}));
	});
	
	
	//marble color picker
	$(document).on("click", ".colorInput", function(){
		$('.colorOptionsWrap').hide();											//hide any others
		$(this).parent().find('.colorOptionsWrap').show();
	});
	$(document).on("click", ".colorOption", function(){
		var color = $(this).attr('color');
		var html = '<span class="fa fa-circle colorSelected ' + color + '" color="' + color +'"></span>';
		
		$(this).parent().parent().find('.colorValue').html(html);
		$(this).parent().hide();

		for(var i in bgcolors) $(".createball").removeClass(bgcolors[i]);		//remove prev color
		$(".createball").css("border", "0").addClass(color + 'bg');				//set new color
	});
	
	function move_back(dragged){
		console.log('move it back');
		$(dragged).remove();
		var name = $(dragged).attr('id');
		build_ball({name: name, user: bag.marbles[name].user, color:bag.marbles[name].color, size: bag.marbles[name].size});
		
		$("#whoAmI").addClass("flash");
		setTimeout(function(){$("#whoAmI").removeClass("flash");}, 1500);
	}
	
	//drag and drop marble
	$("#user2wrap, #user1wrap, #trashbin").sortable({connectWith: ".sortable"}).disableSelection();
	$("#user2wrap").droppable({drop:
		function( event, ui ) {
			var marble_user = $(ui.draggable).attr('user');
			if(marble_user.toLowerCase() != bag.setup.USER2){						//marble transfered users
				if(marble_user.toLowerCase() != user.username.toLowerCase()){		//do not let users steal marbles
					move_back(ui.draggable);
				}
				else{
					$(ui.draggable).addClass("invalid");
					transfer($(ui.draggable).attr('id'), bag.setup.USER2);
				}
			}
		}
	});
	$("#user1wrap").droppable({drop:
		function( event, ui ) {
			var marble_user = $(ui.draggable).attr('user');
			if(marble_user.toLowerCase() != bag.setup.USER1){						//marble transfered users
				if(marble_user.toLowerCase() != user.username.toLowerCase()){		//do not let users steal marbles
					move_back(ui.draggable);
				}
				else{
					$(ui.draggable).addClass("invalid");
					transfer($(ui.draggable).attr('id'), bag.setup.USER1);
				}
			}
			return false;
		}
	});
	$("#trashbin").droppable({drop:
		function( event, ui ) {
			var id = $(ui.draggable).attr('id');
			if(id){
				console.log('removing marble', id);
				var obj = 	{
								type: "remove",
								name: id,
								v: 2
							};
				ws.send(JSON.stringify(obj));
				$(ui.draggable).fadeOut();
				setTimeout(function(){
					$(ui.draggable).remove();
				}, 300);
			}
		}
	});
	
	
	//login events
	$("#whoAmI").click(function(){													//drop down for login
		if($("#userSelect").is(":visible")){
			$("#userSelect").fadeOut();
		}
		else{
			$("#userSelect").fadeIn();
		}
	});<commit_msg>- delete marble only works for user logged in<commit_after>/* global clear_blocks */
/* global escapeHtml */
/* global new_block */
/* global formatDate */
/* global nDig */
/* global randStr */
/* global bag */
/* global $ */
var ws = {};
var user = {username: bag.setup.USER1};
var bgcolors = ["whitebg", "blackbg", "redbg", "greenbg", "bluebg", "purplebg", "pinkbg", "orangebg", "yellowbg"];

// =================================================================================
// On Load
// =================================================================================
$(document).on('ready', function() {
	connect_to_server();
	$("input[name='name']").val('r' + randStr(6));
	$("select option[value='" + bag.setup.USER1 + "']").attr('selected', true);
	
	// =================================================================================
	// jQuery UI Events
	// =================================================================================
	$("#submit").click(function(){
		var obj = 	{
						type: "create",
						name: $("input[name='name']").val().replace(" ", ""),
						color: $(".colorSelected").attr('color'),
						size: $("select[name='size']").val(),
						user: $("select[name='user']").val(),
						v: 2
					};
		if(obj.user && obj.name && obj.color){
			console.log('creating marble, sending', obj);
			ws.send(JSON.stringify(obj));
			$(".panel").hide();
			$("#homePanel").show();
			$(".colorValue").html('Color');											//reset
			for(var i in bgcolors) $(".createball").removeClass(bgcolors[i]);			//reset
			$(".createball").css("border", "2px dashed #fff");						//reset
		}
		return false;
	});

	$("#homeLink").click(function(){
		console.log('marbles:', bag.marbles);
	});
	
	$("#createLink").click(function(){
		$("input[name='name']").val('r' + randStr(6));
	});
	
	$("#tradeLink").click(function(){
		set_my_color_options(user.username);
		ws.send(JSON.stringify({type: "get_open_trades", v: 2}));
	});
	
	
	//marble color picker
	$(document).on("click", ".colorInput", function(){
		$('.colorOptionsWrap').hide();											//hide any others
		$(this).parent().find('.colorOptionsWrap').show();
	});
	$(document).on("click", ".colorOption", function(){
		var color = $(this).attr('color');
		var html = '<span class="fa fa-circle colorSelected ' + color + '" color="' + color +'"></span>';
		
		$(this).parent().parent().find('.colorValue').html(html);
		$(this).parent().hide();

		for(var i in bgcolors) $(".createball").removeClass(bgcolors[i]);		//remove prev color
		$(".createball").css("border", "0").addClass(color + 'bg');				//set new color
	});
	
	//drag and drop marble
	$("#user2wrap, #user1wrap, #trashbin").sortable({connectWith: ".sortable"}).disableSelection();
	$("#user2wrap").droppable({drop:
		function( event, ui ) {
			var marble_user = $(ui.draggable).attr('user');
			if(marble_user.toLowerCase() != bag.setup.USER2){						//marble transfered users
				if(marble_user.toLowerCase() != user.username.toLowerCase()){		//do not let users steal marbles
					move_back(ui.draggable);
				}
				else{
					$(ui.draggable).addClass("invalid");
					transfer($(ui.draggable).attr('id'), bag.setup.USER2);
				}
			}
		}
	});
	$("#user1wrap").droppable({drop:
		function( event, ui ) {
			var marble_user = $(ui.draggable).attr('user');
			if(marble_user.toLowerCase() != bag.setup.USER1){						//marble transfered users
				if(marble_user.toLowerCase() != user.username.toLowerCase()){		//do not let users steal marbles
					move_back(ui.draggable);
				}
				else{
					$(ui.draggable).addClass("invalid");
					transfer($(ui.draggable).attr('id'), bag.setup.USER1);
				}
			}
			return false;
		}
	});
	$("#trashbin").droppable({drop:
		function( event, ui ) {
			var id = $(ui.draggable).attr('id');
			var marble_user = $(ui.draggable).attr('user');
			if(marble_user.toLowerCase() != user.username.toLowerCase()){			//do not let users delete other user's marbles
				move_back(ui.draggable);
			}
			else{
				if(id){
					console.log('removing marble', id);
					var obj = 	{
									type: "remove",
									name: id,
									v: 2
								};
					ws.send(JSON.stringify(obj));
					$(ui.draggable).fadeOut();
					setTimeout(function(){
						$(ui.draggable).remove();
					}, 300);
				}
			}
		}
	});
	function move_back(dragged){
		console.log('move it back');
		$(dragged).remove();
		var name = $(dragged).attr('id');
		build_ball({name: name, user: bag.marbles[name].user, color:bag.marbles[name].color, size: bag.marbles[name].size});
		
		$("#whoAmI").addClass("flash");
		setTimeout(function(){$("#whoAmI").removeClass("flash");}, 1500);
	}
	
	
	//login events
	$("#whoAmI").click(function(){													//drop down for login
		if($("#userSelect").is(":visible")){
			$("#userSelect").fadeOut();
		}
		else{
			$("#userSelect").fadeIn();
		}
	});
{'fraction_non_alphanumeric': 0.2868381883903891, 'fraction_numerical': 0.005103125664469487, 'mean_word_length': 3.8918356734269373, 'pattern_counts': {'":': 2, '<': 7, '<?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': '1311219', 'n_tokens_mistral': 3607, 'n_tokens_neox': 3037, 'n_words': 537}