<commit_before><div id="geolocation">
	<% if buildings.present? %>
		<table>
			<thead>
				<th>Nearest Buildings</th>
				<th>Distance</th>
			</thead>
			<tbody>
				<% buildings.each do |building| %>
					<tr>
						<td><%= link_to building.name, building %></td>
						<td><%= link_to print_distance_and_bearing(building), building %></td>
					</tr>
				<%end%>
			</tbody>
		</table>
	<% elsif !buildings.nil? and buildings.empty? %>
		<p class="warning">I can&rsquo;t find any buildings near you.</p>
	<% end %>
</div>


<script>
	var elementToUpdate = document.getElementById("geolocation");

	// On load (unless we've already searched), request geolocation and start searching.
	<%= "window.onload = getNearbyBuildings;" if buildings.nil? %>
	function getNearbyBuildings() {
		if ("geolocation" in navigator) {
			elementToUpdate.innerHTML="<p class=\"loading\">Trying to get location&hellip;</p>";
			navigator.geolocation.getCurrentPosition(findNearPosition, onError, {maximumAge: 30000});
		} else {
			elementToUpdate.innerHTML = "<p class=\"warning\">Your browser may not support geolocation.</p>";
		}
	}

	// Takes in a coordinate position and uses AJAX.
	function findNearPosition(position) {
		elementToUpdate.innerHTML = "<p class=\"loading\">Location found. Determining nearest toilets&hellip;</p>";

		var latitude = position.coords.latitude;
		var longitude = position.coords.longitude;
		var url = "<%= escape_javascript(near_me_buildings_path) %>?latitude=" + latitude + "&longitude=" + longitude;

		// Pass in authenticity token so the AJAX doesn't get blocked.
		var options = {
			headers: {
				"X-Requested-With": "XMLHttpRequest",
				"X-CSRF-Token": "<%= form_authenticity_token %>"
			},
			credentials: "same-origin"
		};

		fetch(url, options)
			.then(function (r) {return r.text();})
			.then(function (results) {
				elementToUpdate.outerHTML = results;
			})
      .catch(onError);
	}

	function onError(error) {
		if (error.code == 1)
			var message = "If you don&rsquo;t give us your location, we can&rsquo;t find a nearby restroom!";
		else {
			var message = "There was a problem finding your location.";
		}
		elementToUpdate.innerHTML = "<p class=\"warning\">" + message + "</p>";
	}
</script><commit_msg>Change event listener and fix spacing.<commit_after><div id="geolocation">
	<% if buildings.present? %>
		<table>
			<thead>
				<th>Nearest Buildings</th>
				<th>Distance</th>
			</thead>
			<tbody>
				<% buildings.each do |building| %>
					<tr>
						<td><%= link_to building.name, building %></td>
						<td><%= link_to print_distance_and_bearing(building), building %></td>
					</tr>
				<%end%>
			</tbody>
		</table>
	<% elsif !buildings.nil? and buildings.empty? %>
		<p class="warning">I can&rsquo;t find any buildings near you.</p>
	<% end %>
</div>


<script>
	var elementToUpdate = document.getElementById("geolocation");

	function getNearbyBuildings() {
		if ("geolocation" in navigator) {
			elementToUpdate.innerHTML="<p class=\"loading\">Trying to get location&hellip;</p>";
			navigator.geolocation.getCurrentPosition(findNearPosition, onError, {maximumAge: 30000});
		} else {
			elementToUpdate.innerHTML = "<p class=\"warning\">Your browser may not support geolocation.</p>";
		}
	}
	<% if buildings.nil? %>
		// On first load, request geolocation and start searching.
		window.addEventListener("DOMContentLoaded", getNearbyBuildings);
	<% end %>

	// Takes in a coordinate position and uses AJAX.
	function findNearPosition(position) {
		elementToUpdate.innerHTML = "<p class=\"loading\">Location found. Determining nearest toilets&hellip;</p>";

		var latitude = position.coords.latitude;
		var longitude = position.coords.longitude;
		var url = "<%= escape_javascript(near_me_buildings_path) %>?latitude=" + latitude + "&longitude=" + longitude;

		// Pass in authenticity token so the AJAX doesn't get blocked.
		var options = {
			headers: {
				"X-Requested-With": "XMLHttpRequest",
				"X-CSRF-Token": "<%= form_authenticity_token %>"
			},
			credentials: "same-origin"
		};

		fetch(url, options)
			.then(function (r) {return r.text();})
			.then(function (results) {
				elementToUpdate.outerHTML = results;
			})
			.catch(onError);
	}

	function onError(error) {
		if (error.code == 1)
			var message = "If you don&rsquo;t give us your location, we can&rsquo;t find a nearby restroom!";
		else {
			var message = "There was a problem finding your location.";
		}
		elementToUpdate.innerHTML = "<p class=\"warning\">" + message + "</p>";
	}
</script>
{'fraction_non_alphanumeric': 0.15718694885361553, 'fraction_numerical': 0.0026455026455026454, 'mean_word_length': 3.936887921653972, 'pattern_counts': {'":': 4, '<': 84, '<?xml version=': 0, '>': 84, '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': '6798954', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1445, 'n_words': 366}