Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,14 @@ $(function () {
};

page.load = function () {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction() {
const params = new URLSearchParams(location.search);
if (params.has("query")) {
$("#sidebar .search_form input[name=query]").value(params.get("query"));
}
return map.getState();
} // end originalLoadFunction

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
const params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
const params = new URLSearchParams(location.search);
if (params.has("query")) {
$("#sidebar .search_form input[name=query]").value(params.get("query"));
}

addOpenHistoricalMapTimeSlider(map);

return map.getState();
};

return page;
Expand Down
37 changes: 13 additions & 24 deletions app/assets/javascripts/index/changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,21 @@ OSM.Changeset = function (map) {
};

page.load = function () {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction () {
const changesetData = content.find("[data-changeset]").data("changeset");
changesetData.type = "changeset";
const changesetData = content.find("[data-changeset]").data("changeset");
changesetData.type = "changeset";

const hashParams = OSM.parseHash();
initialize();
map.addObject(changesetData, function (bounds) {
if (!hashParams.center && bounds.isValid()) {
OSM.router.withoutMoveListener(function () {
map.fitBounds(bounds);
});
}
})
$(".numbered_pagination").trigger("numbered_pagination:enable");
}// end originalLoadFunction
const hashParams = OSM.parseHash();
initialize();
map.addObject(changesetData, function (bounds) {
if (!hashParams.center && bounds.isValid()) {
OSM.router.withoutMoveListener(function () {
map.fitBounds(bounds);
});
}
});
$(".numbered_pagination").trigger("numbered_pagination:enable");

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
const params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
addOpenHistoricalMapTimeSlider(map);
};

function updateChangeset(method, url, include_data) {
Expand Down
17 changes: 1 addition & 16 deletions app/assets/javascripts/index/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,8 @@ OSM.Directions = function (map) {
sidebarLoaded().then(enableListeners);

map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng);
};

page.load = function() {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction () {
page.pushstate();
} // end originalLoadFunction

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
var params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
addOpenHistoricalMapTimeSlider(map);
};

page.unload = function () {
Expand Down
4 changes: 1 addition & 3 deletions app/assets/javascripts/index/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
}
});

if (!map.timeslider) {
addOpenHistoricalMapTimeSlider(map, hashParams);
}
addOpenHistoricalMapTimeSlider(map);
addOpenHistoricalMapInspector();
};

Expand Down
58 changes: 24 additions & 34 deletions app/assets/javascripts/index/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,30 @@ OSM.Export = function (map) {
};

page.load = function () {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction () {
map
.addLayer(locationFilter)
.on("moveend", update);

$("#maxlat, #minlon, #maxlon, #minlat").change(boundsChanged);
$("#drag_box").click(enableFilter);
$(".export_form").on("submit", checkSubmit);

document.querySelector(".export_form")
.addEventListener("turbo:submit-end", OSM.getTurboBlobHandler("map.osm"));

document.querySelector(".export_form")
.addEventListener("turbo:before-fetch-response", OSM.turboHtmlResponseHandler);

document.querySelector(".export_form")
.addEventListener("turbo:before-fetch-request", function (event) {
event.detail.fetchOptions.headers.Accept = "application/xml";
});

update();
return map.getState();
} // end originalLoadFunction

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
var params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
map
.addLayer(locationFilter)
.on("moveend", update);

$("#maxlat, #minlon, #maxlon, #minlat").change(boundsChanged);
$("#drag_box").click(enableFilter);
$(".export_form").on("submit", checkSubmit);

document.querySelector(".export_form")
.addEventListener("turbo:submit-end", OSM.getTurboBlobHandler("map.osm"));

document.querySelector(".export_form")
.addEventListener("turbo:before-fetch-response", OSM.turboHtmlResponseHandler);

document.querySelector(".export_form")
.addEventListener("turbo:before-fetch-request", function (event) {
event.detail.fetchOptions.headers.Accept = "application/xml";
});

update();

addOpenHistoricalMapTimeSlider(map);

return map.getState();
};

page.unload = function () {
Expand Down
21 changes: 5 additions & 16 deletions app/assets/javascripts/index/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,12 @@ OSM.History = function (map) {
};

page.load = function () {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction () {
map.addLayer(changesetsLayer);
map.on("moveend", moveEndListener);
map.on("zoomend", zoomEndListener);
loadFirstChangesets();
} // end originalLoadFunction
map.addLayer(changesetsLayer);
map.on("moveend", moveEndListener);
map.on("zoomend", zoomEndListener);
loadFirstChangesets();

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
var params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
addOpenHistoricalMapTimeSlider(map);
};

page.unload = function () {
Expand Down
97 changes: 43 additions & 54 deletions app/assets/javascripts/index/new_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,69 +110,58 @@ OSM.NewNote = function (map) {
};

page.load = function (path) {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction () {
control.addClass("active");
control.addClass("active");

map.addLayer(noteLayer);
map.addLayer(noteLayer);

const params = new URLSearchParams(path.substring(path.indexOf("?")));
let markerLatlng;
const params = new URLSearchParams(path.substring(path.indexOf("?")));
let markerLatlng;

if (params.has("lat") && params.has("lon")) {
markerLatlng = L.latLng(params.get("lat"), params.get("lon"));
} else {
markerLatlng = map.getCenter();
}
if (params.has("lat") && params.has("lon")) {
markerLatlng = L.latLng(params.get("lat"), params.get("lon"));
} else {
markerLatlng = map.getCenter();
}

map.panInside(markerLatlng, {
padding: [50, 50]
});
map.panInside(markerLatlng, {
padding: [50, 50]
});

addNewNoteMarker(markerLatlng);

content.find("textarea")
.on("input", updateControls)
.attr("readonly", "readonly") // avoid virtual keyboard popping up on focus
.trigger("focus")
.removeAttr("readonly");

content.find("input[type=submit]").on("click", function (e) {
const location = newNoteMarker.getLatLng().wrap();
const text = content.find("textarea").val();

e.preventDefault();
$(this).prop("disabled", true);
newNoteMarker.options.draggable = false;
newNoteMarker.dragging.disable();

createNote(location, text, (feature) => {
if (typeof OSM.user === "undefined") {
const anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" });
}
content.find("textarea").val("");
addCreatedNoteMarker(feature);
OSM.router.route("/note/" + feature.properties.id);
});
addNewNoteMarker(markerLatlng);

content.find("textarea")
.on("input", updateControls)
.attr("readonly", "readonly") // avoid virtual keyboard popping up on focus
.trigger("focus")
.removeAttr("readonly");

content.find("input[type=submit]").on("click", function (e) {
const location = newNoteMarker.getLatLng().wrap();
const text = content.find("textarea").val();

e.preventDefault();
$(this).prop("disabled", true);
newNoteMarker.options.draggable = false;
newNoteMarker.dragging.disable();

createNote(location, text, (feature) => {
if (typeof OSM.user === "undefined") {
const anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" });
}
content.find("textarea").val("");
addCreatedNoteMarker(feature);
OSM.router.route("/note/" + feature.properties.id);
});
});

map.on("click", moveNewNoteMarkerToClick);
addNoteButton.on("disabled enabled", updateControls);
updateControls();
map.on("click", moveNewNoteMarkerToClick);
addNoteButton.on("disabled enabled", updateControls);
updateControls();

return map.getState();
} // end originalLoadFunction
addOpenHistoricalMapTimeSlider(map);

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
const params = querystring.parse(location.hash ? location.hash.substring(1) : location.search.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
return map.getState();
};

page.unload = function () {
Expand Down
15 changes: 2 additions & 13 deletions app/assets/javascripts/index/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@ OSM.Note = function (map) {
};

page.load = function (path, id) {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction(path, id) {
initialize(path, id);
} // end originalLoadFunction

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
} else {
var params = querystring.parse(location.hash.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
}
initialize(path, id);
addOpenHistoricalMapTimeSlider(map);
};

function initialize(path, id, skipMoveToNote) {
Expand Down
31 changes: 10 additions & 21 deletions app/assets/javascripts/index/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,29 +442,18 @@ OSM.Query = function (map) {
};

page.load = function (path, noCentre) {
// the original page.load content is the function below, and is used when one visits this page, be it first load OR later routing change
// below, we wrap "if map.timeslider" so we only try to add the timeslider if we don't already have it
function originalLoadFunction() {
const params = new URLSearchParams(path.substring(path.indexOf("?"))),
latlng = L.latLng(params.get("lat"), params.get("lon"));

if (!location.hash && !noCentre && !map.getBounds().contains(latlng)) {
OSM.router.withoutMoveListener(function () {
map.setView(latlng, 15);
});
}

queryOverpass([params.get("lat"), params.get("lon")]);
} // end originalLoadFunction
const params = new URLSearchParams(path.substring(path.indexOf("?"))),
latlng = L.latLng(params.get("lat"), params.get("lon"));

// "if map.timeslider" only try to add the timeslider if we don't already have it
if (map.timeslider) {
originalLoadFunction();
}
else {
let params = querystring.parse(location.hash.substring(1));
addOpenHistoricalMapTimeSlider(map, params, originalLoadFunction);
if (!location.hash && !noCentre && !map.getBounds().contains(latlng)) {
OSM.router.withoutMoveListener(function () {
map.setView(latlng, 15);
});
}

queryOverpass([params.get("lat"), params.get("lon")]);

addOpenHistoricalMapTimeSlider(map);
};

page.unload = function (sameController) {
Expand Down
Loading
Loading