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], { icon: OSM.getUserIcon() });
50 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
54 map.on("click", function (e) {
55 if (!$("#updatehome").is(":checked")) return;
57 var zoom = map.getZoom(),
58 precision = OSM.zoomPrecision(zoom),
59 location = e.latlng.wrap();
61 $("#home_lat").val(location.lat.toFixed(precision));
62 $("#home_lon").val(location.lng.toFixed(precision));
66 respondToHomeUpdate();
67 }).on("moveend", function () {
68 var lat = $("#home_lat").val(),
69 lon = $("#home_lon").val();
71 $("#home_show").prop("disabled", isCloseEnoughToMapCenter(lat, lon));
74 $("#home_lat, #home_lon").on("input", function () {
77 respondToHomeUpdate();
80 $("#home_show").click(function () {
81 var lat = $("#home_lat").val(),
82 lon = $("#home_lon").val();
84 map.setView([lat, lon], defaultHomeZoom);
87 $("#home_delete").click(function () {
88 var lat = $("#home_lat").val(),
89 lon = $("#home_lon").val();
91 $("#home_lat, #home_lon").val("");
94 respondToHomeUpdate();
97 $("#home_undelete").click(function () {
98 $("#home_lat").val(deleted_lat);
99 $("#home_lon").val(deleted_lon);
102 respondToHomeUpdate();
105 $("[data-user]").each(function () {
106 var user = $(this).data("user");
107 if (user.lon && user.lat) {
108 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
109 .bindPopup(user.description);
115 function respondToHomeUpdate() {
116 var lat = $("#home_lat").val(),
117 lon = $("#home_lon").val(),
118 has_home = !!(lat && lon);
120 $("#home_message").toggleClass("invisible", has_home);
121 $("#home_show").prop("hidden", !has_home);
122 $("#home_delete").prop("hidden", !has_home);
123 $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon));
125 marker.setLatLng([lat, lon]);
127 map.panTo([lat, lon]);
129 marker.removeFrom(map);
133 function isCloseEnoughToMapCenter(lat, lon) {
134 var inputPt = map.latLngToContainerPoint([lat, lon]),
135 centerPt = map.latLngToContainerPoint(map.getCenter());
137 return centerPt.distanceTo(inputPt) < 10;
140 function updateAuthUID() {
141 var provider = $("select#user_auth_provider").val();
143 if (provider === "openid") {
144 $("input#user_auth_uid").show().prop("disabled", false);
146 $("input#user_auth_uid").hide().prop("disabled", true);
152 $("select#user_auth_provider").on("change", updateAuthUID);
154 $("input#user_avatar").on("change", function () {
155 $("#user_avatar_action_new").prop("checked", true);
158 function enableAuth() {
159 $("#auth_prompt").hide();
160 $("#auth_field").show();
161 $("#user_auth_uid").prop("disabled", false);
164 function disableAuth() {
165 $("#auth_prompt").show();
166 $("#auth_field").hide();
167 $("#user_auth_uid").prop("disabled", true);
170 $("#auth_enable").click(enableAuth);
172 if ($("select#user_auth_provider").val() === "") {
178 $("#user_all").change(function () {
179 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
182 $("#content.user_confirm").each(function () {
184 $(this).find("#confirm").submit();
187 $("input[name=legale]").change(function () {
188 var url = $(this).data("url");
190 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
191 $("#contributorTerms").load(url);
194 $("#read_ct").on("click", function () {
195 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
198 $("#read_tou").on("click", function () {
199 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));