1 OSM.Changeset = function (map) {
3 content = $("#sidebar_content"),
6 page.pushstate = page.popstate = function (path, id) {
7 OSM.loadSidebarContent(path, function () {
12 page.load = function (path, id) {
13 if (id) currentChangesetId = id;
15 addChangeset(currentChangesetId);
18 function addChangeset(id) {
19 map.addObject({ type: "changeset", id: parseInt(id, 10) }, function (bounds) {
20 if (!window.location.hash && bounds.isValid()) {
21 OSM.router.withoutMoveListener(function () {
22 map.fitBounds(bounds);
28 function updateChangeset(method, url, include_data) {
31 content.find("#comment-error").prop("hidden", true);
32 content.find("button[data-method][data-url]").prop("disabled", true);
35 data = { text: content.find("textarea").val() };
45 success: function () {
46 OSM.loadSidebarContent(window.location.pathname, page.load);
48 error: function (xhr) {
49 content.find("button[data-method][data-url]").prop("disabled", false);
50 content.find("#comment-error")
51 .text(xhr.responseText)
52 .prop("hidden", false)
53 .get(0).scrollIntoView({ block: "nearest" });
58 function initialize() {
59 content.find("button[data-method][data-url]").on("click", function (e) {
61 var data = $(e.target).data();
62 var include_data = e.target.name === "comment";
63 updateChangeset(data.method, data.url, include_data);
66 content.find("textarea").on("input", function (e) {
67 var form = e.target.form;
69 if ($(e.target).val() === "") {
70 $(form.comment).prop("disabled", true);
72 $(form.comment).prop("disabled", false);
76 content.find("textarea").val("").trigger("input");
79 page.unload = function () {