+
+ map.on("click", function (e) {
+ if (!$("#updatehome").is(":checked")) return;
+
+ var zoom = map.getZoom(),
+ precision = OSM.zoomPrecision(zoom),
+ location = e.latlng.wrap();
+
+ $("#home_lat").val(location.lat.toFixed(precision));
+ $("#home_lon").val(location.lng.toFixed(precision));
+
+ deleted_lat = null;
+ deleted_lon = null;
+ respondToHomeUpdate();
+ }).on("moveend", function () {
+ var lat = $("#home_lat").val().trim(),
+ lon = $("#home_lon").val().trim(),
+ location;
+
+ try {
+ if (lat && lon) {
+ location = L.latLng(lat, lon);
+ }
+ } catch (error) {
+ // keep location undefined
+ }
+
+ $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
+ });
+
+ $("#home_lat, #home_lon").on("input", function () {
+ deleted_lat = null;
+ deleted_lon = null;
+ respondToHomeUpdate();
+ });
+
+ $("#home_show").click(function () {
+ var lat = $("#home_lat").val(),
+ lon = $("#home_lon").val();
+
+ map.setView([lat, lon], defaultHomeZoom);
+ });
+
+ $("#home_delete").click(function () {
+ var lat = $("#home_lat").val(),
+ lon = $("#home_lon").val();
+
+ $("#home_lat, #home_lon").val("");
+ deleted_lat = lat;
+ deleted_lon = lon;
+ respondToHomeUpdate();
+ $("#home_undelete").trigger("focus");
+ });
+
+ $("#home_undelete").click(function () {
+ $("#home_lat").val(deleted_lat);
+ $("#home_lon").val(deleted_lon);
+ deleted_lat = null;
+ deleted_lon = null;
+ respondToHomeUpdate();
+ $("#home_delete").trigger("focus");
+ });
+ } else {
+ $("[data-user]").each(function () {
+ var user = $(this).data("user");
+ if (user.lon && user.lat) {
+ L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
+ .bindPopup(user.description, { minWidth: 200 });
+ }
+ });
+ }
+ }
+
+ function respondToHomeUpdate() {
+ var lat = $("#home_lat").val().trim(),
+ lon = $("#home_lon").val().trim(),
+ location;
+
+ try {
+ if (lat && lon) {
+ location = L.latLng(lat, lon);