//= 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();
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() {
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.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.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.pushstate = page.popstate = function () {
- page.load();
- };
-
addNoteButton.on("click", function (e) {
e.preventDefault();
e.stopPropagation();
}
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
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;
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 () {
});
}
- 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("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 () {
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;
};
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() {
}
}
-#sidebar_content {
+#sidebar {
+ #sidebar_loader,
.loader,
.load_more {
text-align: center;
<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 %>