Add sidebar loading indicator
This commit is contained in:
parent
e8c02b49e4
commit
853dc286b9
8 changed files with 66 additions and 86 deletions
|
@ -14,6 +14,39 @@
|
|||
//= 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();
|
||||
|
||||
|
@ -159,25 +192,17 @@ $(document).ready(function () {
|
|||
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});
|
||||
loadContent(path);
|
||||
OSM.loadSidebarContent(path);
|
||||
};
|
||||
|
||||
page.popstate = function(path) {
|
||||
$("#content").addClass("overlay-sidebar");
|
||||
map.invalidateSize({pan: false});
|
||||
loadContent(path);
|
||||
OSM.loadSidebarContent(path);
|
||||
};
|
||||
|
||||
page.unload = function() {
|
||||
|
@ -193,10 +218,7 @@ $(document).ready(function () {
|
|||
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);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -51,12 +51,7 @@ OSM.Export = function(map) {
|
|||
|
||||
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() {
|
||||
|
|
|
@ -99,12 +99,7 @@ OSM.History = function(map) {
|
|||
|
||||
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() {
|
||||
|
|
|
@ -23,10 +23,6 @@ OSM.NewNote = function(map) {
|
|||
})
|
||||
};
|
||||
|
||||
page.pushstate = page.popstate = function () {
|
||||
page.load();
|
||||
};
|
||||
|
||||
addNoteButton.on("click", function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
@ -67,7 +63,7 @@ OSM.NewNote = function(map) {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -77,7 +73,11 @@ OSM.NewNote = function(map) {
|
|||
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;
|
||||
|
||||
|
@ -124,15 +124,6 @@ OSM.NewNote = function(map) {
|
|||
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 () {
|
||||
|
|
|
@ -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();
|
||||
|
@ -63,34 +67,18 @@ OSM.Note = function (map) {
|
|||
});
|
||||
|
||||
content.find("textarea").val('').trigger("input");
|
||||
}
|
||||
|
||||
page.pushstate = page.popstate = function () {
|
||||
page.load();
|
||||
};
|
||||
var data = $('.details').data();
|
||||
if (!noteState) map.addLayer(noteLayer);
|
||||
if (window.location.hash == "") map.panTo(data.coordinates.split(','));
|
||||
|
||||
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(','));
|
||||
|
||||
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 () {
|
||||
|
@ -98,15 +86,5 @@ OSM.Note = function (map) {
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
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() {
|
||||
|
|
|
@ -866,7 +866,8 @@ nav.secondary {
|
|||
}
|
||||
}
|
||||
|
||||
#sidebar_content {
|
||||
#sidebar {
|
||||
#sidebar_loader,
|
||||
.loader,
|
||||
.load_more {
|
||||
text-align: center;
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
|
||||
<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 %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue