1 //= require leaflet.locate
3 $(document).ready(function () {
4 if ($("#map").length) {
5 var map = L.map("map", {
6 attributionControl: false,
8 }).addLayer(new L.OSM.Mapnik());
10 var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
12 L.OSM.zoom({ position: position })
15 var locate = L.control.locate({
17 icon: "icon geolocate",
18 iconLoading: "icon geolocate",
20 title: I18n.t("javascripts.map.locate.title"),
21 popup: function (options) {
22 return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance });
27 var locateContainer = locate.getContainer();
30 .removeClass("leaflet-control-locate leaflet-bar")
31 .addClass("control-locate")
34 .removeClass("leaflet-bar-part leaflet-bar-part-single")
35 .addClass("control-button");
38 map.setView([OSM.home.lat, OSM.home.lon], 12);
40 map.setView([0, 0], 0);
43 if ($("#map").hasClass("set_location")) {
44 var marker = L.marker([0, 0], { icon: OSM.getUserIcon() });
47 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
51 map.on("click", function (e) {
52 if ($("#updatehome").is(":checked")) {
53 var zoom = map.getZoom(),
54 precision = OSM.zoomPrecision(zoom),
55 location = e.latlng.wrap();
57 $("#homerow").removeClass();
58 $("#home_lat").val(location.lat.toFixed(precision));
59 $("#home_lon").val(location.lng.toFixed(precision));
61 marker.setLatLng(e.latlng);
66 $("[data-user]").each(function () {
67 var user = $(this).data("user");
68 if (user.lon && user.lat) {
69 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
70 .bindPopup(user.description);
76 function updateAuthUID() {
77 var provider = $("select#user_auth_provider").val();
79 if (provider === "openid") {
80 $("input#user_auth_uid").show().prop("disabled", false);
82 $("input#user_auth_uid").hide().prop("disabled", true);
88 $("select#user_auth_provider").on("change", updateAuthUID);
90 $("input#user_avatar").on("change", function () {
91 $("#avatar_action_new").prop("checked", true);
94 function enableAuth() {
95 $("#auth_prompt").hide();
96 $("#auth_field").show();
97 $("#user_auth_uid").prop("disabled", false);
100 function disableAuth() {
101 $("#auth_prompt").show();
102 $("#auth_field").hide();
103 $("#user_auth_uid").prop("disabled", true);
106 $("#auth_enable").click(enableAuth);
108 if ($("select#user_auth_provider").val() === "") {
114 $("#user_all").change(function () {
115 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
118 $("#content.user_confirm").each(function () {
120 $(this).find("#confirm").submit();
123 $("input[name=legale]").change(function () {
124 var url = $(this).data("url");
126 $("#contributorTerms").html("<img src='" + OSM.SEARCHING + "' />");
127 $("#contributorTerms").load(url);
130 $("#read_ct").on("click", function () {
131 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked")));
134 $("#read_tou").on("click", function () {
135 $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked")));