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")) {
55 var zoom = map.getZoom(),
56 precision = OSM.zoomPrecision(zoom),
57 location = e.latlng.wrap();
59 $("#home_lat").val(location.lat.toFixed(precision));
60 $("#home_lon").val(location.lng.toFixed(precision));
62 respondToHomeUpdate();
66 $("#home_lat, #home_lon").on("input", respondToHomeUpdate);
68 $("#home_show").click(function () {
69 var lat = $("#home_lat").val(),
70 lon = $("#home_lon").val();
72 map.panTo([lat, lon]);
75 $("[data-user]").each(function () {
76 var user = $(this).data("user");
77 if (user.lon && user.lat) {
78 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
79 .bindPopup(user.description);
85 function respondToHomeUpdate() {
86 var lat = $("#home_lat").val(),
87 lon = $("#home_lon").val(),
88 has_home = !!(lat && lon);
90 $("#home_message").toggleClass("invisible", has_home);
91 $("#home_show").prop("hidden", !has_home);
92 $("#home_delete").prop("hidden", !has_home);
93 $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon));
95 marker.setLatLng([lat, lon]);
97 map.panTo([lat, lon]);
99 marker.removeFrom(map);
103 function updateAuthUID() {
104 var provider = $("select#user_auth_provider").val();
106 if (provider === "openid") {
107 $("input#user_auth_uid").show().prop("disabled", false);
109 $("input#user_auth_uid").hide().prop("disabled", true);
115 $("select#user_auth_provider").on("change", updateAuthUID);
117 $("input#user_avatar").on("change", function () {
118 $("#user_avatar_action_new").prop("checked", true);
121 function enableAuth() {
122 $("#auth_prompt").hide();
123 $("#auth_field").show();
124 $("#user_auth_uid").prop("disabled", false);
127 function disableAuth() {
128 $("#auth_prompt").show();
129 $("#auth_field").hide();
130 $("#user_auth_uid").prop("disabled", true);
133 $("#auth_enable").click(enableAuth);
135 if ($("select#user_auth_provider").val() === "") {
141 $("#user_all").change(function () {
142 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
145 $("#content.user_confirm").each(function () {
147 $(this).find("#confirm").submit();
150 $("input[name=legale]").change(function () {
151 var url = $(this).data("url");
153 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
154 $("#contributorTerms").load(url);
157 $("#read_ct").on("click", function () {
158 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
161 $("#read_tou").on("click", function () {
162 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));