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(),
73 lon = $("#home_lon").val();
75 $("#home_show").prop("disabled", isCloseEnoughToMapCenter(lat, lon));
78 $("#home_lat, #home_lon").on("input", function () {
81 respondToHomeUpdate();
84 $("#home_show").click(function () {
85 var lat = $("#home_lat").val(),
86 lon = $("#home_lon").val();
88 map.setView([lat, lon], defaultHomeZoom);
91 $("#home_delete").click(function () {
92 var lat = $("#home_lat").val(),
93 lon = $("#home_lon").val();
95 $("#home_lat, #home_lon").val("");
98 respondToHomeUpdate();
99 $("#home_undelete").trigger("focus");
102 $("#home_undelete").click(function () {
103 $("#home_lat").val(deleted_lat);
104 $("#home_lon").val(deleted_lon);
107 respondToHomeUpdate();
108 $("#home_delete").trigger("focus");
111 $("[data-user]").each(function () {
112 var user = $(this).data("user");
113 if (user.lon && user.lat) {
114 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
115 .bindPopup(user.description);
121 function respondToHomeUpdate() {
122 var lat = $("#home_lat").val(),
123 lon = $("#home_lon").val(),
124 has_home = !!(lat && lon);
126 $("#home_message").toggleClass("invisible", has_home);
127 $("#home_show").prop("hidden", !has_home);
128 $("#home_delete").prop("hidden", !has_home);
129 $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon));
131 marker.setLatLng([lat, lon]);
133 map.panTo([lat, lon]);
135 marker.removeFrom(map);
139 function isCloseEnoughToMapCenter(lat, lon) {
140 var inputPt = map.latLngToContainerPoint([lat, lon]),
141 centerPt = map.latLngToContainerPoint(map.getCenter());
143 return centerPt.distanceTo(inputPt) < 10;
146 function updateAuthUID() {
147 var provider = $("select#user_auth_provider").val();
149 if (provider === "openid") {
150 $("input#user_auth_uid").show().prop("disabled", false);
152 $("input#user_auth_uid").hide().prop("disabled", true);
158 $("select#user_auth_provider").on("change", updateAuthUID);
160 $("input#user_avatar").on("change", function () {
161 $("#user_avatar_action_new").prop("checked", true);
164 function enableAuth() {
165 $("#auth_prompt").hide();
166 $("#auth_field").show();
167 $("#user_auth_uid").prop("disabled", false);
170 function disableAuth() {
171 $("#auth_prompt").show();
172 $("#auth_field").hide();
173 $("#user_auth_uid").prop("disabled", true);
176 $("#auth_enable").click(enableAuth);
178 if ($("select#user_auth_provider").val() === "") {
184 $("#user_all").change(function () {
185 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
188 $("#content.user_confirm").each(function () {
190 $(this).find("#confirm").submit();
193 $("input[name=legale]").change(function () {
194 var url = $(this).data("url");
196 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
197 $("#contributorTerms").load(url);
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")));