1 //= require leaflet.locatecontrol/dist/L.Control.Locate.umd
2 //= require leaflet.locate
5 $(document).on("change", "#user_all", function () {
6 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
11 const defaultHomeZoom = 12;
12 let map, marker, deleted_lat, deleted_lon;
14 if ($("#map").length) {
16 attributionControl: false,
18 }).addLayer(new L.OSM.Mapnik());
20 const position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
22 L.OSM.zoom({ position: position })
25 L.OSM.locate({ position }).addTo(map);
28 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
30 map.setView([0, 0], 0);
33 if ($("#map").hasClass("set_location")) {
34 marker = L.marker([0, 0], {
35 icon: OSM.getMarker({}),
41 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
45 map.on("click", function (e) {
46 if (!$("#updatehome").is(":checked")) return;
48 const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
50 $("#home_lat").val(lat);
51 $("#home_lon").val(lon);
55 respondToHomeUpdate();
56 }).on("moveend", function () {
57 const lat = $("#home_lat").val().trim(),
58 lon = $("#home_lon").val().trim();
63 location = L.latLng(lat, lon);
66 // keep location undefined
69 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
72 $("#home_lat, #home_lon").on("input", function () {
75 respondToHomeUpdate();
78 $("#home_show").click(function () {
79 const lat = $("#home_lat").val(),
80 lon = $("#home_lon").val();
82 map.setView([lat, lon], defaultHomeZoom);
85 $("#home_delete").click(function () {
86 const lat = $("#home_lat").val(),
87 lon = $("#home_lon").val();
89 $("#home_lat, #home_lon").val("");
92 respondToHomeUpdate();
93 $("#home_undelete").trigger("focus");
96 $("#home_undelete").click(function () {
97 $("#home_lat").val(deleted_lat);
98 $("#home_lon").val(deleted_lon);
101 respondToHomeUpdate();
102 $("#home_delete").trigger("focus");
105 $("[data-user]").each(function () {
106 const user = $(this).data("user");
107 if (user.lon && user.lat) {
108 L.marker([user.lat, user.lon], { icon: OSM.getMarker({ icon: user.icon }) }).addTo(map)
109 .bindPopup(user.description, { minWidth: 200 });
115 function respondToHomeUpdate() {
116 const lat = $("#home_lat").val().trim(),
117 lon = $("#home_lon").val().trim();
122 location = L.latLng(lat, lon);
124 $("#home_lat, #home_lon").removeClass("is-invalid");
126 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
127 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
130 $("#home_message").toggleClass("invisible", Boolean(location));
131 $("#home_show").prop("hidden", !location);
132 $("#home_delete").prop("hidden", !location);
133 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
135 marker.setLatLng([lat, lon]);
137 map.panTo([lat, lon]);
139 marker.removeFrom(map);
143 function isCloseEnoughToMapCenter(location) {
144 const inputPt = map.latLngToContainerPoint(location),
145 centerPt = map.latLngToContainerPoint(map.getCenter());
147 return centerPt.distanceTo(inputPt) < 10;
150 function updateAuthUID() {
151 const provider = $("select#user_auth_provider").val();
153 if (provider === "openid") {
154 $("input#user_auth_uid").show().prop("disabled", false);
156 $("input#user_auth_uid").hide().prop("disabled", true);
162 $("select#user_auth_provider").on("change", updateAuthUID);
164 $("input#user_avatar").on("change", function () {
165 $("#user_avatar_action_new").prop("checked", true);
168 function enableAuth() {
169 $("#auth_prompt").hide();
170 $("#auth_field").show();
171 $("#user_auth_uid").prop("disabled", false);
174 function disableAuth() {
175 $("#auth_prompt").show();
176 $("#auth_field").hide();
177 $("#user_auth_uid").prop("disabled", true);
180 $("#auth_enable").click(enableAuth);
182 if ($("select#user_auth_provider").val() === "") {
188 $("#content.user_confirm").each(function () {
190 $(this).find("#confirm").submit();
193 $("input[name=legale]").change(function () {
194 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + OSM.i18n.t("browse.start_rjs.loading") + "</span></div>");
195 fetch($(this).data("url"))
197 .then(html => { $("#contributorTerms").html(html); });
200 $("#read_ct").on("click", function () {
201 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
204 $("#read_tou").on("click", function () {
205 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));