1 //= require leaflet.locatecontrol/src/L.Control.Locate
3 $(document).ready(function () {
4 var defaultHomeZoom = 12;
5 var map, marker, deleted_lat, deleted_lon;
7 if ($("#map").length) {
9 attributionControl: false,
11 }).addLayer(new L.OSM.Mapnik());
13 var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
15 L.OSM.zoom({ position: position })
18 var locate = L.control.locate({
20 icon: "icon geolocate",
21 iconLoading: "icon geolocate",
23 title: I18n.t("javascripts.map.locate.title"),
24 popup: function (options) {
25 return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
30 var locateContainer = locate.getContainer();
33 .removeClass("leaflet-control-locate leaflet-bar")
34 .addClass("control-locate")
37 .removeClass("leaflet-bar-part leaflet-bar-part-single")
38 .addClass("control-button");
41 map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
43 map.setView([0, 0], 0);
46 if ($("#map").hasClass("set_location")) {
47 marker = L.marker([0, 0], {
48 icon: OSM.getUserIcon(),
54 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
58 map.on("click", function (e) {
59 if (!$("#updatehome").is(":checked")) return;
61 var zoom = map.getZoom(),
62 precision = OSM.zoomPrecision(zoom),
63 location = e.latlng.wrap();
65 $("#home_lat").val(location.lat.toFixed(precision));
66 $("#home_lon").val(location.lng.toFixed(precision));
70 respondToHomeUpdate();
71 }).on("moveend", function () {
72 var lat = $("#home_lat").val().trim(),
73 lon = $("#home_lon").val().trim(),
78 location = L.latLng(lat, lon);
81 // keep location undefined
84 $("#home_show").prop("disabled", !location || isCloseEnoughToMapCenter(location));
87 $("#home_lat, #home_lon").on("input", function () {
90 respondToHomeUpdate();
93 $("#home_show").click(function () {
94 var lat = $("#home_lat").val(),
95 lon = $("#home_lon").val();
97 map.setView([lat, lon], defaultHomeZoom);
100 $("#home_delete").click(function () {
101 var lat = $("#home_lat").val(),
102 lon = $("#home_lon").val();
104 $("#home_lat, #home_lon").val("");
107 respondToHomeUpdate();
108 $("#home_undelete").trigger("focus");
111 $("#home_undelete").click(function () {
112 $("#home_lat").val(deleted_lat);
113 $("#home_lon").val(deleted_lon);
116 respondToHomeUpdate();
117 $("#home_delete").trigger("focus");
120 $("[data-user]").each(function () {
121 var user = $(this).data("user");
122 if (user.lon && user.lat) {
123 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
124 .bindPopup(user.description, { minWidth: 200 });
130 function respondToHomeUpdate() {
131 var lat = $("#home_lat").val().trim(),
132 lon = $("#home_lon").val().trim(),
137 location = L.latLng(lat, lon);
139 $("#home_lat, #home_lon").removeClass("is-invalid");
141 if (lat && isNaN(lat)) $("#home_lat").addClass("is-invalid");
142 if (lon && isNaN(lon)) $("#home_lon").addClass("is-invalid");
145 $("#home_message").toggleClass("invisible", Boolean(location));
146 $("#home_show").prop("hidden", !location);
147 $("#home_delete").prop("hidden", !location);
148 $("#home_undelete").prop("hidden", !(!location && deleted_lat && deleted_lon));
150 marker.setLatLng([lat, lon]);
152 map.panTo([lat, lon]);
154 marker.removeFrom(map);
158 function isCloseEnoughToMapCenter(location) {
159 var inputPt = map.latLngToContainerPoint(location),
160 centerPt = map.latLngToContainerPoint(map.getCenter());
162 return centerPt.distanceTo(inputPt) < 10;
165 function updateAuthUID() {
166 var provider = $("select#user_auth_provider").val();
168 if (provider === "openid") {
169 $("input#user_auth_uid").show().prop("disabled", false);
171 $("input#user_auth_uid").hide().prop("disabled", true);
177 $("select#user_auth_provider").on("change", updateAuthUID);
179 $("input#user_avatar").on("change", function () {
180 $("#user_avatar_action_new").prop("checked", true);
183 function enableAuth() {
184 $("#auth_prompt").hide();
185 $("#auth_field").show();
186 $("#user_auth_uid").prop("disabled", false);
189 function disableAuth() {
190 $("#auth_prompt").show();
191 $("#auth_field").hide();
192 $("#user_auth_uid").prop("disabled", true);
195 $("#auth_enable").click(enableAuth);
197 if ($("select#user_auth_provider").val() === "") {
203 $("#user_all").change(function () {
204 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
207 $("#content.user_confirm").each(function () {
209 $(this).find("#confirm").submit();
212 $("input[name=legale]").change(function () {
213 var url = $(this).data("url");
215 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
216 $("#contributorTerms").load(url);
219 $("#read_ct").on("click", function () {
220 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
223 $("#read_tou").on("click", function () {
224 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));