]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/welcome.js
Fix padding
[rails.git] / app / assets / javascripts / welcome.js
1 $(document).ready(function() {
2   var params = OSM.params();
3
4   if (params.lat && params.lon) {
5     $('.edit-located').show();
6
7     $.ajax({
8       url: "http://nominatim.openstreetmap.org/reverse",
9       data: {
10         lat: params.lat,
11         lon: params.lon,
12         zoom: 10
13       },
14       success: function(xml) {
15         var result = $(xml).find('result');
16         if (result.length) {
17           $('.edit-located').hide();
18           $('.edit-geocoded').show();
19           $('.edit-geocoded-location').text(result.text());
20         }
21       }
22     });
23
24     params = {
25       lat: params.lat,
26       lon: params.lon,
27       zoom: params.zoom || 17,
28       editor: params.editor
29     };
30
31     $('.start-mapping').attr('href', '/edit?' + $.param(params));
32
33   } else if (navigator.geolocation) {
34     $('.edit-geolocated').show();
35
36     function geoSuccess(position) {
37       window.location = '/edit?zoom=17&lat=' + position.coords.latitude + '&lon=' + position.coords.longitude;
38     }
39
40     function geoError() {
41       $('.start-mapping')
42         .removeClass('loading')
43         .addClass('error');
44     }
45
46     $('.start-mapping').on('click', function(e) {
47       e.preventDefault();
48
49       $('.start-mapping')
50         .addClass('loading');
51
52       // handle firefox's weird implementation
53       // https://bugzilla.mozilla.org/show_bug.cgi?id=675533
54       window.setTimeout(geoError, 4000);
55
56       navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
57     });
58   }
59 });