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 }).addTo(map);
23 L.OSM.locate({ position }).addTo(map);
26 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
28 map.setView([0, 0], 0);
31 if ($("#map").hasClass("set_location")) {
32 marker = L.marker([0, 0], {
33 icon: OSM.getMarker({}),
39 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
43 map.on("click", function (e) {
44 if (!$("#updatehome").is(":checked")) return;
46 const [lat, lon] = OSM.cropLocation(e.latlng, map.getZoom());
48 $("#home_lat").val(lat);
49 $("#home_lon").val(lon);
53 respondToHomeUpdate();
54 }).on("moveend", function () {
55 const lat = $("#home_lat").val().trim(),
56 lon = $("#home_lon").val().trim();
61 location = L.latLng(lat, lon);
64 // keep location undefined
67 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
70 $("#home_lat, #home_lon").on("input", function () {
73 respondToHomeUpdate();
76 $("#home_show").click(function () {
77 const lat = $("#home_lat").val(),
78 lon = $("#home_lon").val();
80 map.setView([lat, lon], defaultHomeZoom);
83 $("#home_delete").click(function () {
84 const lat = $("#home_lat").val(),
85 lon = $("#home_lon").val();
87 $("#home_lat, #home_lon").val("");
90 respondToHomeUpdate();
91 $("#home_undelete").trigger("focus");
94 $("#home_undelete").click(function () {
95 $("#home_lat").val(deleted_lat);
96 $("#home_lon").val(deleted_lon);
99 respondToHomeUpdate();
100 $("#home_delete").trigger("focus");
103 $("[data-user]").each(function () {
104 const user = $(this).data("user");
105 if (user.lon && user.lat) {
106 L.marker([user.lat, user.lon], { icon: OSM.getMarker({ icon: user.icon }) }).addTo(map)
107 .bindPopup(user.description, { minWidth: 200 });
113 function respondToHomeUpdate() {
114 const lat = $("#home_lat").val().trim(),
115 lon = $("#home_lon").val().trim();
120 location = L.latLng(lat, lon);
122 $("#home_lat, #home_lon").removeClass("is-invalid");
124 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
125 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
128 $("#home_message").toggleClass("invisible", Boolean(location));
129 $("#home_show").prop("hidden", !location);
130 $("#home_delete").prop("hidden", !location);
131 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
133 marker.setLatLng([lat, lon]);
135 map.panTo([lat, lon]);
137 marker.removeFrom(map);
141 function isCloseEnoughToMapCenter(location) {
142 const inputPt = map.latLngToContainerPoint(location),
143 centerPt = map.latLngToContainerPoint(map.getCenter());
145 return centerPt.distanceTo(inputPt) < 10;
148 function updateAuthUID() {
149 const provider = $("select#user_auth_provider").val();
151 if (provider === "openid") {
152 $("input#user_auth_uid").show().prop("disabled", false);
154 $("input#user_auth_uid").hide().prop("disabled", true);
160 $("select#user_auth_provider").on("change", updateAuthUID);
162 $("input#user_avatar").on("change", function () {
163 $("#user_avatar_action_new").prop("checked", true);
166 function enableAuth() {
167 $("#auth_prompt").hide();
168 $("#auth_field").show();
169 $("#user_auth_uid").prop("disabled", false);
172 function disableAuth() {
173 $("#auth_prompt").show();
174 $("#auth_field").hide();
175 $("#user_auth_uid").prop("disabled", true);
178 $("#auth_enable").click(enableAuth);
180 if ($("select#user_auth_provider").val() === "") {
186 $("#content.user_confirm").each(function () {
188 $(this).find("#confirm").submit();
191 $("input[name=legale]").change(function () {
192 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + OSM.i18n.t("browse.start_rjs.loading") + "</span></div>");
193 fetch($(this).data("url"))
195 .then(html => { $("#contributorTerms").html(html); });
198 $("#read_ct").on("click", function () {
199 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
202 $("#read_tou").on("click", function () {
203 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));