1 //= require leaflet.locatecontrol/src/L.Control.Locate
4 $(document).on("change", "#user_all", function () {
5 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
9 $(document).ready(function () {
10 var defaultHomeZoom = 12;
11 var map, marker, deleted_lat, deleted_lon;
13 if ($("#map").length) {
15 attributionControl: false,
17 }).addLayer(new L.OSM.Mapnik());
19 var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
21 L.OSM.zoom({ position: position })
24 var locate = L.control.locate({
26 icon: "icon geolocate",
27 iconLoading: "icon geolocate",
29 title: I18n.t("javascripts.map.locate.title"),
30 popup: function (options) {
31 return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
36 var locateContainer = locate.getContainer();
39 .removeClass("leaflet-control-locate leaflet-bar")
40 .addClass("control-locate")
43 .removeClass("leaflet-bar-part leaflet-bar-part-single")
44 .addClass("control-button");
47 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
49 map.setView([0, 0], 0);
52 if ($("#map").hasClass("set_location")) {
53 marker = L.marker([0, 0], {
54 icon: OSM.getUserIcon(),
60 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
64 map.on("click", function (e) {
65 if (!$("#updatehome").is(":checked")) return;
67 var zoom = map.getZoom(),
68 precision = OSM.zoomPrecision(zoom),
69 location = e.latlng.wrap();
71 $("#home_lat").val(location.lat.toFixed(precision));
72 $("#home_lon").val(location.lng.toFixed(precision));
76 respondToHomeUpdate();
77 }).on("moveend", function () {
78 var lat = $("#home_lat").val().trim(),
79 lon = $("#home_lon").val().trim(),
84 location = L.latLng(lat, lon);
87 // keep location undefined
90 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
93 $("#home_lat, #home_lon").on("input", function () {
96 respondToHomeUpdate();
99 $("#home_show").click(function () {
100 var lat = $("#home_lat").val(),
101 lon = $("#home_lon").val();
103 map.setView([lat, lon], defaultHomeZoom);
106 $("#home_delete").click(function () {
107 var lat = $("#home_lat").val(),
108 lon = $("#home_lon").val();
110 $("#home_lat, #home_lon").val("");
113 respondToHomeUpdate();
114 $("#home_undelete").trigger("focus");
117 $("#home_undelete").click(function () {
118 $("#home_lat").val(deleted_lat);
119 $("#home_lon").val(deleted_lon);
122 respondToHomeUpdate();
123 $("#home_delete").trigger("focus");
126 $("[data-user]").each(function () {
127 var user = $(this).data("user");
128 if (user.lon && user.lat) {
129 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
130 .bindPopup(user.description, { minWidth: 200 });
136 function respondToHomeUpdate() {
137 var lat = $("#home_lat").val().trim(),
138 lon = $("#home_lon").val().trim(),
143 location = L.latLng(lat, lon);
145 $("#home_lat, #home_lon").removeClass("is-invalid");
147 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
148 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
151 $("#home_message").toggleClass("invisible", Boolean(location));
152 $("#home_show").prop("hidden", !location);
153 $("#home_delete").prop("hidden", !location);
154 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
156 marker.setLatLng([lat, lon]);
158 map.panTo([lat, lon]);
160 marker.removeFrom(map);
164 function isCloseEnoughToMapCenter(location) {
165 var inputPt = map.latLngToContainerPoint(location),
166 centerPt = map.latLngToContainerPoint(map.getCenter());
168 return centerPt.distanceTo(inputPt) < 10;
171 function updateAuthUID() {
172 var provider = $("select#user_auth_provider").val();
174 if (provider === "openid") {
175 $("input#user_auth_uid").show().prop("disabled", false);
177 $("input#user_auth_uid").hide().prop("disabled", true);
183 $("select#user_auth_provider").on("change", updateAuthUID);
185 $("input#user_avatar").on("change", function () {
186 $("#user_avatar_action_new").prop("checked", true);
189 function enableAuth() {
190 $("#auth_prompt").hide();
191 $("#auth_field").show();
192 $("#user_auth_uid").prop("disabled", false);
195 function disableAuth() {
196 $("#auth_prompt").show();
197 $("#auth_field").hide();
198 $("#user_auth_uid").prop("disabled", true);
201 $("#auth_enable").click(enableAuth);
203 if ($("select#user_auth_provider").val() === "") {
209 $("#content.user_confirm").each(function () {
211 $(this).find("#confirm").submit();
214 $("input[name=legale]").change(function () {
215 var url = $(this).data("url");
217 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
218 $("#contributorTerms").load(url);
221 $("#read_ct").on("click", function () {
222 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
225 $("#read_tou").on("click", function () {
226 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));