<commit_before>var coords, map, marker, stop, updater;

const fadeTime = 250;
const updateTime = 2000;
const zoomLevel = 16;
const flyTime = 1;

function getParameter(name) {
	return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

// Functions (Bookmarks)

function addBookmark() {
	
	swal({
		type: 'input',
		title: 'Sisesta nimi',
		confirmButtonText: 'Lisa',
		cancelButtonText: 'Tagasi',
		showCancelButton: true,
		inputPlaceholder: 'Minu kodu',
		animation: 'slide-from-top'
	}, function(input) {
		if (!input) return;
		
		var bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
		
		if (input.trim() !== '') bookmarks.push({
			name: input,
			lat:  map.getCenter().lat,
			lng:  map.getCenter().lng,
			zoom: map.getZoom()
		});
		
		localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
		
		hideBookmarks();
		
	});
	
}

function deleteBookmark(el) {hideBookmarks();
	
	swal({
		title: 'Kustuta?',
		text: el.text(),
		confirmButtonText: 'Jah',
		cancelButtonText: 'Ei',
		showCancelButton: true,
		animation: 'slide-from-bottom'
	}, function(isConfirm) {
		if (!isConfirm) return;
		
		var bookmarks = JSON.parse(localStorage.getItem('bookmarks'));
		
		for (var i = 0; i < bookmarks.length; i++) {
			var bookmark = bookmarks[i];
			
			if (bookmark.lat !== el.data('lat') || bookmark.lng !== el.data('lng')) continue;
			
			bookmarks.splice(i, 1);
			el.remove();
			
			break;
			
		}
		
		localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
		
	});
	
}

function showBookmarks() {
	
	var bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
	var content = '<div id="bookmarks-add"><NAME></div>';
	
	for (var i = 0; i < bookmarks.length; i++) {
		var bookmark = bookmarks[i];
		
		content += '<div class="bookmark" data-lat="' + bookmark.lat + '" data-lng="' + bookmark.lng + '" data-zoom="' + bookmark.zoom + '">' + bookmark.name + '</div>';
		
	}
	
	$('#bookmarks').html(content);
	
	$('.bookmark').each(function() {
		$(this).hammer().on('swiperight press', function() {
			deleteBookmark($(this));
		});
	});
	
	$('#bookmarks').animate({ left: '0px' }, fadeTime);
	
}

function hideBookmarks() {
	$('#bookmarks').animate({ left: '-240px' }, fadeTime);
}

// Functions (Stops)

function showStops() {
	
	if (map.getZoom() <= 15) return map.eachLayer(function(layer) {
		if (layer._icon) if (layer._icon.currentSrc.indexOf('stop') !== -1) map.removeLayer(layer);
	});
	
	var bounds = map.getBounds();
	$.get('/getstops?lat_min=' + bounds._northEast.lat + '&lng_min=' + bounds._northEast.lng + '&lat_max=' + bounds._southWest.lat + '&lng_max=' + bounds._southWest.lng, function(stops) {
	
		for (var i = 0; i < stops.length; i++) {
		
			(function() {
				var stop = stops[i];
				
				L.marker([ stop.lat, stop.lng ], {
					icon: L.icon({
						iconUrl: 'assets/stop_' + stop.type + '.png',
						iconSize: [ 24, 24 ]
					})
				}).addTo(map).on('click', function() {
					
					if (updater) return;
					
					showStop(stop.id, { panMap: false, fadeIn: true });
					updater = setInterval(function() {
						showStop(stop.id, { panMap: false, fadeIn: false });
					}, updateTime);
					
				});
				
			})();
			
		}<commit_msg>Improve code<commit_after>var coords, map, marker, stop, updater;

const fadeTime = 250;
const updateTime = 2000;
const zoomLevel = 16;
const flyTime = 1;

function getParameter(name) {
	return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

// Functions (Bookmarks)

function addBookmark() {
	
	swal({
		type: 'input',
		title: 'Sisesta nimi',
		confirmButtonText: 'Lisa',
		cancelButtonText: 'Tagasi',
		showCancelButton: true,
		inputPlaceholder: 'Minu kodu',
		animation: 'slide-from-top'
	}, function(input) {
		if (!input) return;
		
		var bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
		
		if (input.trim() !== '') bookmarks.push({
			name: input,
			lat:  map.getCenter().lat,
			lng:  map.getCenter().lng,
			zoom: map.getZoom()
		});
		
		localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
		
		hideBookmarks();
		
	});
	
}

function deleteBookmark(el) {hideBookmarks();
	
	swal({
		title: 'Kustuta?',
		text: el.text(),
		confirmButtonText: 'Jah',
		cancelButtonText: 'Ei',
		showCancelButton: true,
		animation: 'slide-from-bottom'
	}, function(isConfirm) {
		if (!isConfirm) return;
		
		var bookmarks = JSON.parse(localStorage.getItem('bookmarks'));
		
		for (var i = 0; i < bookmarks.length; i++) {
			var bookmark = bookmarks[i];
			
			if (bookmark.lat !== el.data('lat') || bookmark.lng !== el.data('lng')) continue;
			
			bookmarks.splice(i, 1);
			el.remove();
			
			break;
			
		}
		
		localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
		
	});
	
}

function showBookmarks() {
	
	var bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];
	var content = '<div id="bookmarks-add"><NAME></div>';
	
	for (var i = 0; i < bookmarks.length; i++) {
		var bookmark = bookmarks[i];
		
		content += '<div class="bookmark" data-lat="' + bookmark.lat + '" data-lng="' + bookmark.lng + '" data-zoom="' + bookmark.zoom + '">' + bookmark.name + '</div>';
		
	}
	
	$('#bookmarks').html(content);
	
	$('.bookmark').each(function() {
		$(this).hammer().on('swiperight press', function() {
			deleteBookmark($(this));
		});
	});
	
	$('#bookmarks').animate({ left: '0px' }, fadeTime);
	
}

function hideBookmarks() {
	$('#bookmarks').animate({ left: '-240px' }, fadeTime);
}

// Functions (Stops)

function showStops() {
	
	if (map.getZoom() <= 15) return map.eachLayer(function(layer) {
		if (layer._icon) if (layer._icon.currentSrc.indexOf('stop') !== -1) map.removeLayer(layer);
	});
	
	var bounds = map.getBounds();
	$.get('/getstops?lat_min=' + bounds._northEast.lat + '&lng_min=' + bounds._northEast.lng + '&lat_max=' + bounds._southWest.lat + '&lng_max=' + bounds._southWest.lng).done(function(stops) {
	
		for (var i = 0; i < stops.length; i++) {
		
			(function() {
				var stop = stops[i];
				
				L.marker([ stop.lat, stop.lng ], {
					icon: L.icon({
						iconUrl: 'assets/stop_' + stop.type + '.png',
						iconSize: [ 24, 24 ]
					})
				}).addTo(map).on('click', function() {
					
					if (updater) return;
					
					showStop(stop.id, { panMap: false, fadeIn: true });
					updater = setInterval(function() {
						showStop(stop.id, { panMap: false, fadeIn: false });
					}, updateTime);
					
				});
				
			})();
			
		}
{'fraction_non_alphanumeric': 0.2049105789633222, 'fraction_numerical': 0.008487420430433464, 'mean_word_length': 3.53228021978022, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, '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': '7082655', 'n_tokens_mistral': 2788, 'n_tokens_neox': 2331, 'n_words': 460}