]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/user.js
Move link to ToU to attribution footer
[rails.git] / app / assets / javascripts / user.js
1 //= require leaflet.locate
2
3 $(document).ready(function () {
4   if ($("#map").length) {
5     var map = L.map("map", {
6       attributionControl: false,
7       zoomControl: false
8     }).addLayer(new L.OSM.Mapnik());
9
10     var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
11
12     L.OSM.zoom({ position: position })
13       .addTo(map);
14
15     var locate = L.control.locate({
16       position: position,
17       icon: "icon geolocate",
18       iconLoading: "icon geolocate",
19       strings: {
20         title: I18n.t("javascripts.map.locate.title"),
21         popup: I18n.t("javascripts.map.locate.popup")
22       }
23     }).addTo(map);
24
25     var locateContainer = locate.getContainer();
26
27     $(locateContainer)
28       .removeClass("leaflet-control-locate leaflet-bar")
29       .addClass("control-locate")
30       .children("a")
31       .attr("href", "#")
32       .removeClass("leaflet-bar-part leaflet-bar-part-single")
33       .addClass("control-button");
34
35     if (OSM.home) {
36       map.setView([OSM.home.lat, OSM.home.lon], 12);
37     } else {
38       map.setView([0, 0], 0);
39     }
40
41     if ($("#map").hasClass("set_location")) {
42       var marker = L.marker([0, 0], { icon: OSM.getUserIcon() });
43
44       if (OSM.home) {
45         marker.setLatLng([OSM.home.lat, OSM.home.lon]);
46         marker.addTo(map);
47       }
48
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();
54
55           $("#homerow").removeClass();
56           $("#home_lat").val(location.lat.toFixed(precision));
57           $("#home_lon").val(location.lng.toFixed(precision));
58
59           marker.setLatLng(e.latlng);
60           marker.addTo(map);
61         }
62       });
63     } else {
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);
69         }
70       });
71     }
72   }
73
74   function updateAuthUID() {
75     var provider = $("select#user_auth_provider").val();
76
77     if (provider === "openid") {
78       $("input#user_auth_uid").show().prop("disabled", false);
79     } else {
80       $("input#user_auth_uid").hide().prop("disabled", true);
81     }
82   }
83
84   updateAuthUID();
85
86   $("select#user_auth_provider").on("change", updateAuthUID);
87
88   $("input#user_image").on("change", function () {
89     $("#image_action_new").prop("checked", true);
90   });
91
92   function enableAuth() {
93     $("#auth_prompt").hide();
94     $("#auth_field").show();
95     $("#user_auth_uid").prop("disabled", false);
96   }
97
98   function disableAuth() {
99     $("#auth_prompt").show();
100     $("#auth_field").hide();
101     $("#user_auth_uid").prop("disabled", true);
102   }
103
104   $("#auth_enable").click(enableAuth);
105
106   if ($("select#user_auth_provider").val() === "") {
107     disableAuth();
108   } else {
109     enableAuth();
110   }
111
112   $("#user_all").change(function () {
113     $("#user_list input[type=checkbox]").prop("checked", $("#user_all").prop("checked"));
114   });
115
116   $("#content.user_confirm").each(function () {
117     $(this).hide();
118     $(this).find("#confirm").submit();
119   });
120
121   $("input[name=legale]").change(function () {
122     var url = $(this).data("url");
123
124     $("#contributorTerms").html("<img src='" + OSM.SEARCHING + "' />");
125     $("#contributorTerms").load(url);
126   });
127
128   $("#read_tou").on("click", function () { 
129     var agreebtn = document.getElementById('agree');
130     agreebtn.disabled=!this.checked;
131   });
132 });