1 //= require leaflet.locate
4 $(document).on("change", "#user_all", function () {
5 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
10 const defaultHomeZoom = 12;
11 let map, marker, deleted_lat, deleted_lon;
13 if ($("#map").length) {
15 attributionControl: false,
17 }).addLayer(new L.OSM.Mapnik());
19 const position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
21 L.OSM.zoom({ position: position })
24 L.OSM.locate({ position }).addTo(map);
27 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
29 map.setView([0, 0], 0);
32 if ($("#map").hasClass("set_location")) {
33 marker = L.marker([0, 0], {
34 icon: OSM.getMarker({}),
40 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
44 map.on("click", function (e) {
45 if (!$("#updatehome").is(":checked")) return;
47 const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
49 $("#home_lat").val(lat);
50 $("#home_lon").val(lon);
54 respondToHomeUpdate();
55 }).on("moveend", function () {
56 const lat = $("#home_lat").val().trim(),
57 lon = $("#home_lon").val().trim();
62 location = L.latLng(lat, lon);
65 // keep location undefined
68 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
71 $("#home_lat, #home_lon").on("input", function () {
74 respondToHomeUpdate();
77 $("#home_show").click(function () {
78 const lat = $("#home_lat").val(),
79 lon = $("#home_lon").val();
81 map.setView([lat, lon], defaultHomeZoom);
84 $("#home_delete").click(function () {
85 const lat = $("#home_lat").val(),
86 lon = $("#home_lon").val();
88 $("#home_lat, #home_lon").val("");
91 respondToHomeUpdate();
92 $("#home_undelete").trigger("focus");
95 $("#home_undelete").click(function () {
96 $("#home_lat").val(deleted_lat);
97 $("#home_lon").val(deleted_lon);
100 respondToHomeUpdate();
101 $("#home_delete").trigger("focus");
104 $("[data-user]").each(function () {
105 const user = $(this).data("user");
106 if (user.lon && user.lat) {
107 L.marker([user.lat, user.lon], { icon: OSM.getMarker({ icon: user.icon }) }).addTo(map)
108 .bindPopup(user.description, { minWidth: 200 });
114 function respondToHomeUpdate() {
115 const lat = $("#home_lat").val().trim(),
116 lon = $("#home_lon").val().trim();
121 location = L.latLng(lat, lon);
123 $("#home_lat, #home_lon").removeClass("is-invalid");
125 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
126 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
129 $("#home_message").toggleClass("invisible", Boolean(location));
130 $("#home_show").prop("hidden", !location);
131 $("#home_delete").prop("hidden", !location);
132 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
134 marker.setLatLng([lat, lon]);
136 map.panTo([lat, lon]);
138 marker.removeFrom(map);
142 function isCloseEnoughToMapCenter(location) {
143 const inputPt = map.latLngToContainerPoint(location),
144 centerPt = map.latLngToContainerPoint(map.getCenter());
146 return centerPt.distanceTo(inputPt) < 10;
149 function updateAuthUID() {
150 const provider = $("select#user_auth_provider").val();
152 if (provider === "openid") {
153 $("input#user_auth_uid").show().prop("disabled", false);
155 $("input#user_auth_uid").hide().prop("disabled", true);
161 $("select#user_auth_provider").on("change", updateAuthUID);
163 $("input#user_avatar").on("change", function () {
164 $("#user_avatar_action_new").prop("checked", true);
167 function enableAuth() {
168 $("#auth_prompt").hide();
169 $("#auth_field").show();
170 $("#user_auth_uid").prop("disabled", false);
173 function disableAuth() {
174 $("#auth_prompt").show();
175 $("#auth_field").hide();
176 $("#user_auth_uid").prop("disabled", true);
179 $("#auth_enable").click(enableAuth);
181 if ($("select#user_auth_provider").val() === "") {
187 $("#content.user_confirm").each(function () {
189 $(this).find("#confirm").submit();
192 $("input[name=legale]").change(function () {
193 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + OSM.i18n.t("browse.start_rjs.loading") + "</span></div>");
194 fetch($(this).data("url"))
196 .then(html => { $("#contributorTerms").html(html); });
199 $("#read_ct").on("click", function () {
200 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
203 $("#read_tou").on("click", function () {
204 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));