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, true);
18 function addChangeset(id, center) {
19 map.addObject({ type: "changeset", id: parseInt(id, 10) }, function (bounds) {
20 if (!window.location.hash && bounds.isValid() &&
21 (center || !map.getBounds().contains(bounds))) {
22 OSM.router.withoutMoveListener(function () {
23 map.fitBounds(bounds);
29 function updateChangeset(method, url, include_data) {
32 content.find("#comment-error").prop("hidden", true);
33 content.find("button[data-method][data-url]").prop("disabled", true);
36 data = { text: content.find("textarea").val() };
46 success: function () {
47 OSM.loadSidebarContent(window.location.pathname, page.load);
49 error: function (xhr) {
50 content.find("button[data-method][data-url]").prop("disabled", false);
51 content.find("#comment-error")
52 .text(xhr.responseText)
53 .prop("hidden", false)
54 .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 var form = e.target.form;
70 if ($(e.target).val() === "") {
71 $(form.comment).prop("disabled", true);
73 $(form.comment).prop("disabled", false);
77 content.find("textarea").val("").trigger("input");
80 page.unload = function () {