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: I18n.t("javascripts.map.locate.popup")
25 var locateContainer = locate.getContainer();
28 .removeClass("leaflet-control-locate leaflet-bar")
29 .addClass("control-locate")
32 .removeClass("leaflet-bar-part leaflet-bar-part-single")
33 .addClass("control-button");
36 map.setView([OSM.home.lat, OSM.home.lon], 12);
38 map.setView([0, 0], 0);
41 if ($("#map").hasClass("set_location")) {
42 var marker = L.marker([0, 0], { icon: OSM.getUserIcon() });
45 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
49 map.on("click", function (e) {
50 if ($("#updatehome").is(":checked")) {
51 var zoom = map.getZoom(),
52 precision = OSM.zoomPrecision(zoom),
53 location = e.latlng.wrap();
55 $("#homerow").removeClass();
56 $("#home_lat").val(location.lat.toFixed(precision));
57 $("#home_lon").val(location.lng.toFixed(precision));
59 marker.setLatLng(e.latlng);
64 $("[data-user]").each(function () {
65 var user = $(this).data("user");
66 if (user.lon && user.lat) {
67 L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map)
68 .bindPopup(user.description);
74 function updateAuthUID() {
75 var provider = $("select#user_auth_provider").val();
77 if (provider === "openid") {
78 $("input#user_auth_uid").show().prop("disabled", false);
80 $("input#user_auth_uid").hide().prop("disabled", true);
86 $("select#user_auth_provider").on("change", updateAuthUID);
88 $("input#user_image").on("change", function () {
89 $("#image_action_new").prop("checked", true);
92 function enableAuth() {
93 $("#auth_prompt").hide();
94 $("#auth_field").show();
95 $("#user_auth_uid").prop("disabled", false);
98 function disableAuth() {
99 $("#auth_prompt").show();
100 $("#auth_field").hide();
101 $("#user_auth_uid").prop("disabled", true);
104 $("#auth_enable").click(enableAuth);
106 if ($("select#user_auth_provider").val() === "") {
112 $("#user_all").change(function () {
113 $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
116 $("#content.user_confirm").each(function () {
118 $(this).find("#confirm").submit();
121 $("input[name=legale]").change(function () {
122 var url = $(this).data("url");
124 $("#contributorTerms").html("<img src='" + OSM.SEARCHING + "' />");
125 $("#contributorTerms").load(url);
128 $("#read_tou").on("click", function () {
129 $("#agree").prop("disabled", !$(this).prop("checked"));