]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Merge map.js.erb and leaflet.extend.js.erb
[rails.git] / app / assets / javascripts / index.js
index 7ed89681e01749c7483652bba5b1629baa04cf27..e01ff3cb90008f61dcb37596750d1ddadd59d590 100644 (file)
 //= require index/export
 //= require index/notes
 //= require index/history
+//= require index/note
 //= require router
 
 $(document).ready(function () {
   var params = OSM.mapParams();
 
-  var map = L.map("map", {
+  var map = new L.OSM.Map("map", {
     zoomControl: false,
     layerControl: false
   });
@@ -37,7 +38,7 @@ $(document).ready(function () {
 
   var layers = [
     new L.OSM.Mapnik({
-      attribution: copyright+" – "+donate,
+      attribution: copyright + " ♥ " + donate,
       code: "M",
       keyid: "mapnik",
       name: I18n.t("javascripts.map.base.standard")
@@ -102,16 +103,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})
@@ -153,6 +144,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() {
@@ -227,16 +230,22 @@ $(document).ready(function () {
     });
   }
 
-  initializeBrowse(map);
-  initializeNotes(map);
-
   OSM.Index = function(map) {
-    var page = {}, minimized = $('#sidebar').hasClass('minimized');
+    var page = {};
 
     page.pushstate = page.popstate = function(path) {
-      if (minimized) $("#sidebar").addClass("minimized");
+      $("#content").addClass("overlay-sidebar");
+      map.invalidateSize();
+      $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
+        if (xhr.getResponseHeader('X-Page-Title')) {
+          document.title = xhr.getResponseHeader('X-Page-Title');
+        }
+      });
+    };
+
+    page.unload = function() {
+      $("#content").removeClass("overlay-sidebar");
       map.invalidateSize();
-      $('#sidebar_content').load(path);
     };
 
     return page;
@@ -246,16 +255,15 @@ $(document).ready(function () {
     var page = {};
 
     page.pushstate = page.popstate = function(path, type, id) {
-      $("#sidebar").removeClass("minimized");
-      map.invalidateSize();
-      $('#sidebar_content').load(path, function() {
+      $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
+        if (xhr.getResponseHeader('X-Page-Title')) {
+          document.title = xhr.getResponseHeader('X-Page-Title');
+        }
         page.load(path, type, id);
       });
     };
 
     page.load = function(path, type, id) {
-      $("#sidebar").removeClass("minimized");
-
       if (OSM.STATUS === 'api_offline' || OSM.STATUS === 'database_offline') return;
 
       if (type === 'note') {
@@ -272,7 +280,8 @@ $(document).ready(function () {
     return page;
   };
 
-  var history = OSM.History(map);
+  var history = OSM.History(map),
+    note = OSM.Note(map);
 
   OSM.route = OSM.Router({
     "/":                           OSM.Index(map),
@@ -282,6 +291,7 @@ $(document).ready(function () {
     "/user/:display_name/edits":   history,
     "/browse/friends":             history,
     "/browse/nearby":              history,
+    "/browse/note/:id":            note,
     "/browse/:type/:id(/history)": OSM.Browse(map)
   });
 
@@ -290,29 +300,17 @@ $(document).ready(function () {
     if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
   });
 
-  $("#search_form").on("submit", function(e) {
+  $(".search_form").on("submit", function(e) {
     e.preventDefault();
-    OSM.route("/search?query=" + encodeURIComponent($("#query").val()) + OSM.formatHash(map));
+    $("header").addClass("closed");
+    OSM.route("/search?query=" + encodeURIComponent($(this).find("input[name=query]").val()) + OSM.formatHash(map));
   });
 
-  $("#describe_location").on("click", function(e) {
+  $(".describe_location").on("click", function(e) {
     e.preventDefault();
     var precision = zoomPrecision(map.getZoom());
     OSM.route("/search?query=" + encodeURIComponent(
       map.getCenter().lat.toFixed(precision) + "," +
       map.getCenter().lng.toFixed(precision)));
   });
-
-  function removeSidebar() {
-    if ($(window).width() < 721) {
-      $('#sidebar').addClass("minimized");
-    }
-  }
-
-  $(window).resize(function() {
-    removeSidebar();
-  });
-
-  removeSidebar();
-
 });