]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/user.js
Set border=0 on that img
[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       .removeClass('leaflet-bar-part leaflet-bar-part-single')
32       .addClass('control-button');
33
34     if (OSM.home) {
35       map.setView([OSM.home.lat, OSM.home.lon], 12);
36     } else {
37       map.setView([0, 0], 0);
38     }
39
40     if ($("#map").hasClass("set_location")) {
41       var marker = L.marker([0, 0], {icon: OSM.getUserIcon()});
42
43       if (OSM.home) {
44         marker.setLatLng([OSM.home.lat, OSM.home.lon]);
45         marker.addTo(map);
46       }
47
48       map.on("click", function (e) {
49         if ($('#updatehome').is(':checked')) {
50           var zoom = map.getZoom(),
51               precision = OSM.zoomPrecision(zoom),
52               location = e.latlng.wrap();
53
54           $('#homerow').removeClass();
55           $('#home_lat').val(location.lat.toFixed(precision));
56           $('#home_lon').val(location.lng.toFixed(precision));
57
58           marker.setLatLng(e.latlng);
59           marker.addTo(map);
60         }
61       });
62     } else {
63       $("[data-user]").each(function () {
64         var user = $(this).data('user');
65         if (user.lon && user.lat) {
66           L.marker([user.lat, user.lon], {icon: OSM.getUserIcon(user.icon)}).addTo(map)
67             .bindPopup(user.description);
68         }
69       });
70     }
71   }
72
73   function updateAuthUID() {
74     var provider = $("select#user_auth_provider").val();
75
76     if (provider === "openid") {
77       $("input#user_auth_uid").show().prop("disabled", false);
78     } else {
79       $("input#user_auth_uid").hide().prop("disabled", true);
80     }
81   }
82
83   updateAuthUID();
84
85   $("select#user_auth_provider").on("change", updateAuthUID);
86
87   function enableAuth() {
88     $("#auth_prompt").hide();
89     $("#auth_field").show();
90     $("#user_auth_uid").prop("disabled", false);
91   }
92
93   function disableAuth() {
94     $("#auth_prompt").show();
95     $("#auth_field").hide();
96     $("#user_auth_uid").prop("disabled", true);
97   }
98
99   $("#auth_enable").click(enableAuth);
100
101   if ($("select#user_auth_provider").val() === "") {
102     disableAuth();
103   } else {
104     enableAuth();
105   }
106 });