]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Fix order of initialization
[rails.git] / app / assets / javascripts / index.js
index c6295cb10bb8dfc08e9cf97ac328a1c3d8a5d995..816bb4e8fccad6a7d6272a2d2274ea5aab3b957f 100644 (file)
@@ -24,15 +24,20 @@ $(document).ready(function () {
 
   map.hash = L.hash(map);
 
-  $(window).on('popstate', function() {
-    map.hash.update();
+  $(window).on('popstate', function(e) {
+    // popstate is triggered when the hash changes as well as on actual navigation
+    // events. We want to update the hash on the latter and not the former.
+    if (e.originalEvent.state) {
+      map.hash.update();
+    }
   });
 
   var copyright = I18n.t('javascripts.map.copyright', {copyright_url: '/copyright'});
+  var donate = I18n.t('javascripts.map.donate_link_text', {donate_url: 'http://donate.openstreetmap.org'});
 
   var layers = [
     new L.OSM.Mapnik({
-      attribution: copyright,
+      attribution: copyright + " ♥ " + donate,
       code: "M",
       keyid: "mapnik",
       name: I18n.t("javascripts.map.base.standard")
@@ -97,16 +102,6 @@ $(document).ready(function () {
   map.dataLayer = new L.OSM.DataLayer(null);
   map.dataLayer.options.code = 'D';
 
-  if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
-    if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
-      map.addLayer(map.noteLayer);
-    }
-
-    if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
-      map.addLayer(map.dataLayer);
-    }
-  }
-
   var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
 
   L.OSM.zoom({position: position})
@@ -148,6 +143,18 @@ $(document).ready(function () {
   L.control.scale()
     .addTo(map);
 
+  if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
+    initializeNotes(map);
+    if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
+      map.addLayer(map.noteLayer);
+    }
+
+    initializeBrowse(map);
+    if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
+      map.addLayer(map.dataLayer);
+    }
+  }
+
   $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
 
   map.on('moveend layeradd layerremove', function() {
@@ -222,31 +229,20 @@ $(document).ready(function () {
     });
   }
 
-  initializeBrowse(map);
-  initializeNotes(map);
-
   OSM.Index = function(map) {
-    var page = {}, minimized = false;
+    var page = {};
 
     page.pushstate = page.popstate = function(path) {
-      if (minimized) $("#sidebar").addClass("minimized");
+      $("#content").addClass("overlay-sidebar");
       map.invalidateSize();
-      $("#view_tab").addClass("current");
       $('#sidebar_content').load(path);
     };
 
     page.unload = function() {
-      $("#view_tab").removeClass("current");
-    };
-
-    page.minimizeSidebar = function() {
-      $("#sidebar").addClass("minimized");
+      $("#content").removeClass("overlay-sidebar");
       map.invalidateSize();
-      minimized = true;
     };
 
-    $(document).on("click", "#sidebar_content .close", page.minimizeSidebar);
-
     return page;
   };
 
@@ -254,8 +250,6 @@ $(document).ready(function () {
     var page = {};
 
     page.pushstate = page.popstate = function(path, type, id) {
-      $("#sidebar").removeClass("minimized");
-      map.invalidateSize();
       $('#sidebar_content').load(path, function() {
         page.load(path, type, id);
       });
@@ -308,5 +302,4 @@ $(document).ready(function () {
       map.getCenter().lat.toFixed(precision) + "," +
       map.getCenter().lng.toFixed(precision)));
   });
-
 });