1 //= require leaflet.locatecontrol/dist/L.Control.Locate.umd
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 }).addTo(map);
23 const locate = L.control.locate({
25 icon: "icon geolocate",
26 iconLoading: "icon geolocate",
28 title: OSM.i18n.t("javascripts.map.locate.title"),
29 popup: function (options) {
30 return OSM.i18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
35 const locateContainer = locate.getContainer();
38 .removeClass("leaflet-control-locate leaflet-bar")
39 .addClass("control-locate")
42 .removeClass("leaflet-bar-part leaflet-bar-part-single")
43 .addClass("control-button");
46 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
48 map.setView([0, 0], 0);
51 if ($("#map").hasClass("set_location")) {
52 marker = L.marker([0, 0], {
53 icon: OSM.getMarker({}),
59 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
63 map.on("click", function (e) {
64 if (!$("#updatehome").is(":checked")) return;
66 const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
68 $("#home_lat").val(lat);
69 $("#home_lon").val(lon);
73 respondToHomeUpdate();
74 }).on("moveend", function () {
75 const lat = $("#home_lat").val().trim(),
76 lon = $("#home_lon").val().trim();
81 location = L.latLng(lat, lon);
84 // keep location undefined
87 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
90 $("#home_lat, #home_lon").on("input", function () {
93 respondToHomeUpdate();
96 $("#home_show").click(function () {
97 const lat = $("#home_lat").val(),
98 lon = $("#home_lon").val();
100 map.setView([lat, lon], defaultHomeZoom);
103 $("#home_delete").click(function () {
104 const lat = $("#home_lat").val(),
105 lon = $("#home_lon").val();
107 $("#home_lat, #home_lon").val("");
110 respondToHomeUpdate();
111 $("#home_undelete").trigger("focus");
114 $("#home_undelete").click(function () {
115 $("#home_lat").val(deleted_lat);
116 $("#home_lon").val(deleted_lon);
119 respondToHomeUpdate();
120 $("#home_delete").trigger("focus");
123 $("[data-user]").each(function () {
124 const user = $(this).data("user");
125 if (user.lon && user.lat) {
126 L.marker([user.lat, user.lon], { icon: OSM.getMarker({ icon: user.icon }) }).addTo(map)
127 .bindPopup(user.description, { minWidth: 200 });
133 function respondToHomeUpdate() {
134 const lat = $("#home_lat").val().trim(),
135 lon = $("#home_lon").val().trim();
140 location = L.latLng(lat, lon);
142 $("#home_lat, #home_lon").removeClass("is-invalid");
144 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
145 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
148 $("#home_message").toggleClass("invisible", Boolean(location));
149 $("#home_show").prop("hidden", !location);
150 $("#home_delete").prop("hidden", !location);
151 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
153 marker.setLatLng([lat, lon]);
155 map.panTo([lat, lon]);
157 marker.removeFrom(map);
161 function isCloseEnoughToMapCenter(location) {
162 const inputPt = map.latLngToContainerPoint(location),
163 centerPt = map.latLngToContainerPoint(map.getCenter());
165 return centerPt.distanceTo(inputPt) < 10;
168 function updateAuthUID() {
169 const provider = $("select#user_auth_provider").val();
171 if (provider === "openid") {
172 $("input#user_auth_uid").show().prop("disabled", false);
174 $("input#user_auth_uid").hide().prop("disabled", true);
180 $("select#user_auth_provider").on("change", updateAuthUID);
182 $("input#user_avatar").on("change", function () {
183 $("#user_avatar_action_new").prop("checked", true);
186 function enableAuth() {
187 $("#auth_prompt").hide();
188 $("#auth_field").show();
189 $("#user_auth_uid").prop("disabled", false);
192 function disableAuth() {
193 $("#auth_prompt").show();
194 $("#auth_field").hide();
195 $("#user_auth_uid").prop("disabled", true);
198 $("#auth_enable").click(enableAuth);
200 if ($("select#user_auth_provider").val() === "") {
206 $("#content.user_confirm").each(function () {
208 $(this).find("#confirm").submit();
211 $("input[name=legale]").change(function () {
212 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + OSM.i18n.t("browse.start_rjs.loading") + "</span></div>");
213 fetch($(this).data("url"))
215 .then(html => { $("#contributorTerms").html(html); });
218 $("#read_ct").on("click", function () {
219 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
222 $("#read_tou").on("click", function () {
223 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));