1 OSM.Changeset = function (map) {
3 content = $("#sidebar_content");
5 page.pushstate = page.popstate = function (path) {
6 OSM.loadSidebarContent(path, function () {
11 page.load = function () {
12 const changesetData = content.find("[data-changeset]").data("changeset");
13 changesetData.type = "changeset";
15 var hashParams = OSM.parseHash(window.location.hash);
17 map.addObject(changesetData, function (bounds) {
18 if (!hashParams.center && bounds.isValid()) {
19 OSM.router.withoutMoveListener(function () {
20 map.fitBounds(bounds);
26 function updateChangeset(method, url, include_data) {
27 const data = new URLSearchParams();
29 content.find("#comment-error").prop("hidden", true);
30 content.find("button[data-method][data-url]").prop("disabled", true);
33 data.set("text", content.find("textarea").val());
38 headers: { ...OSM.oauth },
42 if (response.ok) return response;
43 return response.text().then(text => {
44 throw new Error(text);
48 OSM.loadSidebarContent(window.location.pathname, page.load);
51 content.find("button[data-method][data-url]").prop("disabled", false);
52 content.find("#comment-error")
54 .prop("hidden", false)
55 .get(0).scrollIntoView({ block: "nearest" });
59 function initialize() {
60 content.find("button[data-method][data-url]").on("click", function (e) {
62 var data = $(e.target).data();
63 var include_data = e.target.name === "comment";
64 updateChangeset(data.method, data.url, include_data);
67 content.find("textarea").on("input", function (e) {
68 const form = e.target.form,
69 disabled = $(e.target).val() === "";
70 form.comment.disabled = disabled;
73 content.find("textarea").val("").trigger("input");
76 page.unload = function () {