1 //= require leaflet.locatecontrol/src/L.Control.Locate
3 $(document).ready(function () {
4 var map, marker, deleted_lat, deleted_lon;
6 if ($("#map").length) {
8 attributionControl: false,
10 }).addLayer(new L.OSM.Mapnik());
12 var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
14 L.OSM.zoom({ position: position })
17 var locate = L.control.locate({
19 icon: "icon geolocate",
20 iconLoading: "icon geolocate",
22 title: I18n.t("javascripts.map.locate.title"),
23 popup: function (options) {
24 return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
29 var locateContainer = locate.getContainer();
32 .removeClass("leaflet-control-locate leaflet-bar")
33 .addClass("control-locate")
36 .removeClass("leaflet-bar-part leaflet-bar-part-single")
37 .addClass("control-button");
40 map.setView([OSM.home.lat, OSM.home.lon], 12);
42 map.setView([0, 0], 0);
45 if ($("#map").hasClass("set_location")) {
46 marker = L.marker([0, 0], { icon: OSM.getUserIcon() });
49 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
53 map.on("click", function (e) {
54 if (!$("#updatehome").is(":checked")) return;
56 var zoom = map.getZoom(),
57 precision = OSM.zoomPrecision(zoom),
58 location = e.latlng.wrap();
60 $("#home_lat").val(location.lat.toFixed(precision));
61 $("#home_lon").val(location.lng.toFixed(precision));
65 respondToHomeUpdate();
68 $("#home_lat, #home_lon").on("input", function () {
71 respondToHomeUpdate();
74 $("#home_show").click(function () {
75 var lat = $("#home_lat").val(),
76 lon = $("#home_lon").val();
78 map.panTo([lat, lon]);
81 $("#home_delete").click(function () {
82 var lat = $("#home_lat").val(),
83 lon = $("#home_lon").val();
85 $("#home_lat, #home_lon").val("");
88 respondToHomeUpdate();
91 $("#home_undelete").click(function () {
92 $("#home_lat").val(deleted_lat);
93 $("#home_lon").val(deleted_lon);
96 respondToHomeUpdate();
99 $("[data-user]").each(function () {
100 var user = $(this).data("user");
101 if (user.lon && user.lat) {
102 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
103 .bindPopup(user.description);
109 function respondToHomeUpdate() {
110 var lat = $("#home_lat").val(),
111 lon = $("#home_lon").val(),
112 has_home = !!(lat && lon);
114 $("#home_message").toggleClass("invisible", has_home);
115 $("#home_show").prop("hidden", !has_home);
116 $("#home_delete").prop("hidden", !has_home);
117 $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon));
119 marker.setLatLng([lat, lon]);
121 map.panTo([lat, lon]);
123 marker.removeFrom(map);
127 function updateAuthUID() {
128 var provider = $("select#user_auth_provider").val();
130 if (provider === "openid") {
131 $("input#user_auth_uid").show().prop("disabled", false);
133 $("input#user_auth_uid").hide().prop("disabled", true);
139 $("select#user_auth_provider").on("change", updateAuthUID);
141 $("input#user_avatar").on("change", function () {
142 $("#user_avatar_action_new").prop("checked", true);
145 function enableAuth() {
146 $("#auth_prompt").hide();
147 $("#auth_field").show();
148 $("#user_auth_uid").prop("disabled", false);
151 function disableAuth() {
152 $("#auth_prompt").show();
153 $("#auth_field").hide();
154 $("#user_auth_uid").prop("disabled", true);
157 $("#auth_enable").click(enableAuth);
159 if ($("select#user_auth_provider").val() === "") {
165 $("#user_all").change(function () {
166 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
169 $("#content.user_confirm").each(function () {
171 $(this).find("#confirm").submit();
174 $("input[name=legale]").change(function () {
175 var url = $(this).data("url");
177 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
178 $("#contributorTerms").load(url);
181 $("#read_ct").on("click", function () {
182 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
185 $("#read_tou").on("click", function () {
186 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));