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("#comment-error").text(xhr.responseText);
51 content.find("#comment-error").prop("hidden", false);
52 content.find("button[data-method][data-url]").prop("disabled", false);
57 function initialize() {
58 content.find("button[data-method][data-url]").on("click", function (e) {
60 var data = $(e.target).data();
61 var include_data = e.target.name === "comment";
62 updateChangeset(data.method, data.url, include_data);
65 content.find("textarea").on("input", function (e) {
66 var form = e.target.form;
68 if ($(e.target).val() === "") {
69 $(form.comment).prop("disabled", true);
71 $(form.comment).prop("disabled", false);
75 content.find("textarea").val("").trigger("input");
78 page.unload = function () {