<commit_before>var socket;

var room_num;

$(".sit").click(function(){
	if(this.className.indexOf('selected') != -1){
		$(".selected").removeClass("selected");
		$("#sitno").val('');
		$("#nickname").val('');
	} else {
		$(".selected").removeClass("selected");
		this.className = "selected " + this.className;
		$("#sitno").val(this.id);
		if(this.title === '空') {
			$("#nickname").val('');
		} else {
			$("#nickname").val(this.title);
		}
	}
});

$('.display-gra-btn').click(function() {
	if($('.display-gra-btn').hasClass('g-btn-move')) {
		
		$('.display-gra-btn').html('頭像設定');
		$('.display-gra-btn').removeClass('g-btn-move');
		$('.gravatar-regist').removeClass('g-move');
		
	} else {
		$('.display-gra-btn').addClass('g-btn-move');
		$('.gravatar-regist').addClass('g-move');
		$('.display-gra-btn').html('關閉');
	}
	
});


function modifySit () {
	var sn = $("#sitno").val();
	// sn = sn.substring(4); // cut "seat"
	var nick = $("#nickname").val();
	if(nick === '') {
		$(".selected").removeClass("selected");
		$(".selected").removeClass("black-sit");
		return;
	}

	if(sn === '') {
		return;
	}

	$.post('/modify', 
		{sitno:sn, nickname:nick, room:room_num}, 
		function(data){
		
			if(data.msg === 'success') {
				// if($("a[title='" + nick + "']").length != 0) {
				// 	var _id = $("a[title='" + nick + "']").attr('id');
				// 	clearSitWithSitno(_id);
				// }

				$("#"+sn).removeClass();
				$("#"+sn).addClass('sit');
				$("#"+sn).addClass('sitted');
				$("#"+sn).attr('title', nick);

				// socket.emit('modify_sit', {sitno:sn, nickname:nick, room:room_num});
				loadBlackList();
				loadGravatar();
			}
		}, 
		'json');
}

function clearSitWithSitno(sn){
	$.post('/modify', 
		{sitno:sn, nickname:'', room:room_num}, 
		function(data){
			if(data.msg === 'success') {
				// socket.emit('clear_sit', {sitno:sn, nickname:null, room:room_num});
			}
		}, 
		'json');
}

function clearSit() {
	var sn = $("#sitno").val();
	// sn = sn.substring(4); // cut "seat"
	if(sn === '') {
		return;
	}

	$.post('/modify', 
		{sitno:sn, nickname:'', room:room_num}, 
		function(data){
		
			if(data.msg === 'success') {
				$("#"+sn).attr('style', '');
				$("#"+sn).removeClass();
				$("#"+sn).addClass('sit');
				$("#"+sn).attr('title', '空');	
			} else {

			}
		}, 
		'json');

	// socket.emit('clear_sit', {sitno:sn, nickname:null, room:room_num});
	
}

function init() {
	room_num = $('#room').val();
	console.log("get room : " + room_num);

	loadSits();
	initSocketIO();
	setTimeout(function(){
		loadBlackList();
		loadGravatar();
	}, 4000);
	
	setTimeout(function(){
		$(".dark-cover").remove();
		console.log("ok");
	}, 3000);
}

function loadSits() {
	
	$.get('/list/?room=' + room_num, function(data) {
		if(data.msg === 'success') {
			for(var k in data.seats) {
				var seat = data.seats[k];
				$('#' + seat.no).attr('title', seat.name);
				$('#' + seat.no).addClass('sitted');
			}
		}
	}, 'json');
}

function loadBlackList() {

	$.get('/black-list', function(data) {
		var list = data.list;
		console.log(list);
		for(k in list) {
			$("a[title='"+list[k].name+"']").addClass('black-sit');
		}
	}, 'json');
}

function initSocketIO() {
	console.log('init socket.io');

	socket = io.connect('http://'+location.hostname+':'+location.port);

	socket.on('sit_md', function (data) {

		if(data.room === room_num) {
			var sn = data.sitno;
			var nick = data.nickname;
			var oldSeat = data.oldSeat;
			console.log('old ' + oldSeat);

			if(oldSeat != undefined) {
				clearSitWithSitno(oldSeat);
			}

			console.log(data);
			$("#"+sn).removeClass("selected");
			$("#"+sn).addClass("sitted");
			$("#"+sn).attr("title", nick);
		}

		
	});

	socket.on('sit_clr', function (data) {
		if(data.room === room_num) {
			var sn = data.sitno;
			$("#"+sn).removeClass();
			$("#"+sn).addClass('sit');
			$("#"+sn).attr('title', '空');
		}
	});
	<commit_msg>fix clear seat gravatar bug<commit_after>var socket;

var room_num;

$(".sit").click(function(){
	if(this.className.indexOf('selected') != -1){
		$(".selected").removeClass("selected");
		$("#sitno").val('');
		$("#nickname").val('');
	} else {
		$(".selected").removeClass("selected");
		this.className = "selected " + this.className;
		$("#sitno").val(this.id);
		if(this.title === '空') {
			$("#nickname").val('');
		} else {
			$("#nickname").val(this.title);
		}
	}
});

$('.display-gra-btn').click(function() {
	if($('.display-gra-btn').hasClass('g-btn-move')) {
		
		$('.display-gra-btn').html('頭像設定');
		$('.display-gra-btn').removeClass('g-btn-move');
		$('.gravatar-regist').removeClass('g-move');
		
	} else {
		$('.display-gra-btn').addClass('g-btn-move');
		$('.gravatar-regist').addClass('g-move');
		$('.display-gra-btn').html('關閉');
	}
	
});


function modifySit () {
	var sn = $("#sitno").val();
	// sn = sn.substring(4); // cut "seat"
	var nick = $("#nickname").val();
	if(nick === '') {
		$(".selected").removeClass("selected");
		$(".selected").removeClass("black-sit");
		return;
	}

	if(sn === '') {
		return;
	}

	$.post('/modify', 
		{sitno:sn, nickname:nick, room:room_num}, 
		function(data){
		
			if(data.msg === 'success') {
				$("#"+sn).removeClass();
				$("#"+sn).addClass('sit');
				$("#"+sn).addClass('sitted');
				$("#"+sn).attr('title', nick);
				loadBlackList();
				loadGravatar();
			}
		}, 
		'json');
}

function clearSitWithSitno(sn){
	$.post('/modify', 
		{sitno:sn, nickname:'', room:room_num}, 
		function(data){
			if(data.msg === 'success') {
				$("#"+sn).attr('style', '');
			}
		}, 
		'json');
}

function clearSit() {
	var sn = $("#sitno").val();
	// sn = sn.substring(4); // cut "seat"
	if(sn === '') {
		return;
	}

	$.post('/modify', 
		{sitno:sn, nickname:'', room:room_num}, 
		function(data){
		
			if(data.msg === 'success') {
				$("#"+sn).attr('style', '');
				$("#"+sn).removeClass();
				$("#"+sn).addClass('sit');
				$("#"+sn).attr('title', '空');	
			} else {

			}
		}, 
		'json');

	// socket.emit('clear_sit', {sitno:sn, nickname:null, room:room_num});
	
}

function init() {
	room_num = $('#room').val();
	console.log("get room : " + room_num);

	loadSits();
	initSocketIO();
	setTimeout(function(){
		loadBlackList();
		loadGravatar();
	}, 4000);
	
	setTimeout(function(){
		$(".dark-cover").remove();
		console.log("ok");
	}, 3000);
}

function loadSits() {
	
	$.get('/list/?room=' + room_num, function(data) {
		if(data.msg === 'success') {
			for(var k in data.seats) {
				var seat = data.seats[k];
				$('#' + seat.no).attr('title', seat.name);
				$('#' + seat.no).addClass('sitted');
			}
		}
	}, 'json');
}

function loadBlackList() {

	$.get('/black-list', function(data) {
		var list = data.list;
		console.log(list);
		for(k in list) {
			$("a[title='"+list[k].name+"']").addClass('black-sit');
		}
	}, 'json');
}

function initSocketIO() {
	console.log('init socket.io');

	socket = io.connect('http://'+location.hostname+':'+location.port);

	socket.on('sit_md', function (data) {

		if(data.room === room_num) {
			var sn = data.sitno;
			var nick = data.nickname;
			var oldSeat = data.oldSeat;
			console.log('old ' + oldSeat);

			if(oldSeat != undefined) {
				clearSitWithSitno(oldSeat);
			}

			console.log(data);
			$("#"+sn).removeClass("selected");
			$("#"+sn).addClass("sitted");
			$("#"+sn).attr("title", nick);
		}

		
	});

	socket.on('sit_clr', function (data) {
		if(data.room === room_num) {
			var sn = data.sitno;
			$("#"+sn).attr('style', '');
			$("#"+sn).removeClass();
			$("#"+sn).addClass('sit');
			$("#"+sn).attr('title', '空');
		}
	});
	
{'fraction_non_alphanumeric': 0.2793688676743569, 'fraction_numerical': 0.003049588968443384, 'mean_word_length': 3.605006105006105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '628799', 'n_tokens_mistral': 3274, 'n_tokens_neox': 2866, 'n_words': 408}