]> git.openstreetmap.org Git - rails.git/commitdiff
Add sidebar loading indicator
authorJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 13 Nov 2013 00:58:34 +0000 (16:58 -0800)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 13 Nov 2013 01:01:47 +0000 (17:01 -0800)
app/assets/javascripts/index.js
app/assets/javascripts/index/export.js
app/assets/javascripts/index/history.js
app/assets/javascripts/index/new_note.js.erb
app/assets/javascripts/index/note.js.erb
app/assets/javascripts/index/search.js
app/assets/stylesheets/common.css.scss
app/views/layouts/map.html.erb

index 15b45d31c34e407bb456e4ac39cad936ebd35b0b..2d397b812840467e33994a05b2f816d7ada678dd 100644 (file)
 //= require index/new_note
 //= require router
 
 //= require index/new_note
 //= require router
 
+(function() {
+  var loaderTimeout;
+
+  OSM.loadSidebarContent = function(path, callback) {
+    clearTimeout(loaderTimeout);
+
+    loaderTimeout = setTimeout(function() {
+      $('#sidebar_loader').show();
+    }, 200);
+
+    // IE<10 doesn't respect Vary: X-Requested-With header, so
+    // prevent caching the XHR response as a full-page URL.
+    if (path.indexOf('?') >= 0) {
+      path += '&xhr=1'
+    } else {
+      path += '?xhr=1'
+    }
+
+    $('#sidebar_content')
+      .empty()
+      .load(path, function(a, b, xhr) {
+        clearTimeout(loaderTimeout);
+        $('#sidebar_loader').hide();
+        if (xhr.getResponseHeader('X-Page-Title')) {
+          document.title = xhr.getResponseHeader('X-Page-Title');
+        }
+        if (callback) {
+          callback();
+        }
+      });
+  };
+})();
+
 $(document).ready(function () {
   var params = OSM.mapParams();
 
 $(document).ready(function () {
   var params = OSM.mapParams();
 
@@ -159,25 +192,17 @@ $(document).ready(function () {
   OSM.Index = function(map) {
     var page = {};
 
   OSM.Index = function(map) {
     var page = {};
 
-    function loadContent(path) {
-      $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
-        if (xhr.getResponseHeader('X-Page-Title')) {
-          document.title = xhr.getResponseHeader('X-Page-Title');
-        }
-      });
-    }
-
     page.pushstate = function(path) {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false})
         .panBy([-300, 0], {animate: false});
     page.pushstate = function(path) {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false})
         .panBy([-300, 0], {animate: false});
-      loadContent(path);
+      OSM.loadSidebarContent(path);
     };
 
     page.popstate = function(path) {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false});
     };
 
     page.popstate = function(path) {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false});
-      loadContent(path);
+      OSM.loadSidebarContent(path);
     };
 
     page.unload = function() {
     };
 
     page.unload = function() {
@@ -193,10 +218,7 @@ $(document).ready(function () {
     var page = {};
 
     page.pushstate = page.popstate = function(path, type, id) {
     var page = {};
 
     page.pushstate = page.popstate = function(path, type, id) {
-      $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
-        if (xhr.getResponseHeader('X-Page-Title')) {
-          document.title = xhr.getResponseHeader('X-Page-Title');
-        }
+      OSM.loadSidebarContent(path, function() {
         page.load(path, type, id);
       });
     };
         page.load(path, type, id);
       });
     };
index a2d6c4f0738562130f4d800a55d85b198806f4f4..851dbb9aef522c7cddf9f67ca21997293ec55e96 100644 (file)
@@ -51,12 +51,7 @@ OSM.Export = function(map) {
 
   page.pushstate = page.popstate = function(path) {
     $("#export_tab").addClass("current");
 
   page.pushstate = page.popstate = function(path) {
     $("#export_tab").addClass("current");
-    $("#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();
-    });
+    OSM.loadSidebarContent(path, page.load);
   };
 
   page.load = function() {
   };
 
   page.load = function() {
index 29a3d1fb90a76bc59f0472f598433971dd845db4..afae6640f87b566d8ab210bacbe18f3d8ce6b58a 100644 (file)
@@ -99,12 +99,7 @@ OSM.History = function(map) {
 
   page.pushstate = page.popstate = function(path) {
     $("#history_tab").addClass("current");
 
   page.pushstate = page.popstate = function(path) {
     $("#history_tab").addClass("current");
-    $("#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();
-    });
+    OSM.loadSidebarContent(path, page.load);
   };
 
   page.load = function() {
   };
 
   page.load = function() {
index e544c1a93b4c55db4e16144c80dbf561261c05e2..c47cb563c9ffa91abc93e71ddb23d659ee93fafb 100644 (file)
@@ -23,10 +23,6 @@ OSM.NewNote = function(map) {
     })
   };
 
     })
   };
 
-  page.pushstate = page.popstate = function () {
-    page.load();
-  };
-
   addNoteButton.on("click", function (e) {
     e.preventDefault();
     e.stopPropagation();
   addNoteButton.on("click", function (e) {
     e.preventDefault();
     e.stopPropagation();
@@ -67,7 +63,7 @@ OSM.NewNote = function(map) {
   }
 
   function updateMarker(feature) {
   }
 
   function updateMarker(feature) {
-    marker = L.marker(feature.geometry.coordinates.reverse(), {
+    var marker = L.marker(feature.geometry.coordinates.reverse(), {
       icon: noteIcons[feature.properties.status],
       opacity: 0.9,
       clickable: true
       icon: noteIcons[feature.properties.status],
       opacity: 0.9,
       clickable: true
@@ -77,7 +73,11 @@ OSM.NewNote = function(map) {
     return marker;
   }
 
     return marker;
   }
 
-  function initialize() {
+  page.pushstate = page.popstate = function (path) {
+    OSM.loadSidebarContent(path, page.load);
+  };
+
+  page.load = function () {
     if (addNoteButton.hasClass("disabled")) return;
     if (addNoteButton.hasClass("active")) return;
 
     if (addNoteButton.hasClass("disabled")) return;
     if (addNoteButton.hasClass("active")) return;
 
@@ -124,15 +124,6 @@ OSM.NewNote = function(map) {
       e.preventDefault();
       createNote(newNote, e.target.form, '/api/0.6/notes.json');
     });
       e.preventDefault();
       createNote(newNote, e.target.form, '/api/0.6/notes.json');
     });
-  }
-
-  page.load = function () {
-    content.load(window.location.pathname + "?xhr=1", function (a, b, xhr) {
-      if (xhr.getResponseHeader('X-Page-Title')) {
-        document.title = xhr.getResponseHeader('X-Page-Title');
-      }
-      initialize();
-    });
   };
 
   page.unload = function () {
   };
 
   page.unload = function () {
index afc23006732a772f8bc66221a469ddd1c01f9bdb..2586f84c6d9af2f1082379bf3af21d726539086c 100644 (file)
@@ -43,7 +43,11 @@ OSM.Note = function (map) {
     });
   }
 
     });
   }
 
-  function bind() {
+  page.pushstate = page.popstate = function (path) {
+    OSM.loadSidebarContent(path, page.load);
+  };
+
+  page.load = function () {
     content.find("input[type=submit]").on("click", function (e) {
       e.preventDefault();
       var data = $(e.target).data();
     content.find("input[type=submit]").on("click", function (e) {
       e.preventDefault();
       var data = $(e.target).data();
@@ -63,34 +67,18 @@ OSM.Note = function (map) {
     });
 
     content.find("textarea").val('').trigger("input");
     });
 
     content.find("textarea").val('').trigger("input");
-  }
-
-  page.pushstate = page.popstate = function () {
-    page.load();
-  };
-
-  page.load = function () {
-    var loadTimer = setTimeout(setLoading, 250);
-    $('#sidebar_content').load(window.location.pathname + "?xhr=1", function (a, b, xhr) {
-      if (xhr.getResponseHeader('X-Page-Title')) {
-        document.title = xhr.getResponseHeader('X-Page-Title');
-      }
-      bind();
-      clearTimeout(loadTimer);
-      clearLoading();
 
 
-      var data = $('.details').data();
-      if (!noteState) map.addLayer(noteLayer);
-      if (window.location.hash == "") map.panTo(data.coordinates.split(','));
+    var data = $('.details').data();
+    if (!noteState) map.addLayer(noteLayer);
+    if (window.location.hash == "") map.panTo(data.coordinates.split(','));
 
 
-      if (!map.hasLayer(halo)) {
-          halo = L.circleMarker(data.coordinates.split(','), {
-            weight: 2.5,
-            radius: 20
-          });
-        map.addLayer(halo);
-      }
-  });
+    if (!map.hasLayer(halo)) {
+      halo = L.circleMarker(data.coordinates.split(','), {
+        weight: 2.5,
+        radius: 20
+      });
+      map.addLayer(halo);
+    }
   };
 
   page.unload = function () {
   };
 
   page.unload = function () {
@@ -98,15 +86,5 @@ OSM.Note = function (map) {
     if (!noteState) map.removeLayer(noteLayer);
   };
 
     if (!noteState) map.removeLayer(noteLayer);
   };
 
-  function setLoading() {
-    if ($('#browse_status').is(':empty')) {
-      $('#browse_status').append($('<p></p>').text(I18n.t('browse.start_rjs.loading')));
-    }
-  }
-
-  function clearLoading() {
-    $('#browse_status').empty();
-  }
-
   return page;
 };
   return page;
 };
index fde4c249947a81e6e0f40b7dfac458b18cd98bd6..43142959b074d6c9586c238ea0bafc953e80063b 100644 (file)
@@ -49,13 +49,7 @@ OSM.Search = function(map) {
   page.pushstate = page.popstate = function(path) {
     var params = querystring.parse(path.substring(path.indexOf('?') + 1));
     $(".search_form input[name=query]").val(params.query);
   page.pushstate = page.popstate = function(path) {
     var params = querystring.parse(path.substring(path.indexOf('?') + 1));
     $(".search_form input[name=query]").val(params.query);
-    map.invalidateSize();
-    $("#sidebar_content").load(path, function(a, b, xhr) {
-      if (xhr.getResponseHeader('X-Page-Title')) {
-        document.title = xhr.getResponseHeader('X-Page-Title');
-      }
-      page.load();
-    });
+    OSM.loadSidebarContent(path, page.load);
   };
 
   page.load = function() {
   };
 
   page.load = function() {
index 7d6b1acd498c97d1e3a23414dbb954c23a293256..ae0f4da3c51ae6d068e33a35cc662a26163acada 100644 (file)
@@ -866,7 +866,8 @@ nav.secondary {
   }
 }
 
   }
 }
 
-#sidebar_content {
+#sidebar {
+  #sidebar_loader,
   .loader,
   .load_more {
     text-align: center;
   .loader,
   .load_more {
     text-align: center;
index a7d00f53fb4e85852e7c63c2ad42071577523225..420d3933dbbc90dc94ccc68b5b00732122b0aa41 100644 (file)
 
     <div id="browse_status"></div>
 
 
     <div id="browse_status"></div>
 
+    <div id="sidebar_loader" style="display: none;">
+      <img alt="<%= t('browse.start_rjs.loading') %>" class="loader" src="<%= image_path("searching.gif") %>">
+    </div>
+
     <div id="sidebar_content">
       <%= render :partial => "layouts/flash" %>
       <%= yield %>
     <div id="sidebar_content">
       <%= render :partial => "layouts/flash" %>
       <%= yield %>