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();
101 $("#home_undelete").click(function () {
102 $("#home_lat").val(deleted_lat);
103 $("#home_lon").val(deleted_lon);
106 respondToHomeUpdate();
109 $("[data-user]").each(function () {
110 var user = $(this).data("user");
111 if (user.lon && user.lat) {
112 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
113 .bindPopup(user.description);
119 function respondToHomeUpdate() {
120 var lat = $("#home_lat").val(),
121 lon = $("#home_lon").val(),
122 has_home = !!(lat && lon);
124 $("#home_message").toggleClass("invisible", has_home);
125 $("#home_show").prop("hidden", !has_home);
126 $("#home_delete").prop("hidden", !has_home);
127 $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon));
129 marker.setLatLng([lat, lon]);
131 map.panTo([lat, lon]);
133 marker.removeFrom(map);
137 function isCloseEnoughToMapCenter(lat, lon) {
138 var inputPt = map.latLngToContainerPoint([lat, lon]),
139 centerPt = map.latLngToContainerPoint(map.getCenter());
141 return centerPt.distanceTo(inputPt) < 10;
144 function updateAuthUID() {
145 var provider = $("select#user_auth_provider").val();
147 if (provider === "openid") {
148 $("input#user_auth_uid").show().prop("disabled", false);
150 $("input#user_auth_uid").hide().prop("disabled", true);
156 $("select#user_auth_provider").on("change", updateAuthUID);
158 $("input#user_avatar").on("change", function () {
159 $("#user_avatar_action_new").prop("checked", true);
162 function enableAuth() {
163 $("#auth_prompt").hide();
164 $("#auth_field").show();
165 $("#user_auth_uid").prop("disabled", false);
168 function disableAuth() {
169 $("#auth_prompt").show();
170 $("#auth_field").hide();
171 $("#user_auth_uid").prop("disabled", true);
174 $("#auth_enable").click(enableAuth);
176 if ($("select#user_auth_provider").val() === "") {
182 $("#user_all").change(function () {
183 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
186 $("#content.user_confirm").each(function () {
188 $(this).find("#confirm").submit();
191 $("input[name=legale]").change(function () {
192 var url = $(this).data("url");
194 $("#contributorTerms").html("<div class='spinner-border' role='status'><span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span></div>");
195 $("#contributorTerms").load(url);
198 $("#read_ct").on("click", function () {
199 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
202 $("#read_tou").on("click", function () {
203 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));