1 OSM.Note = function (map) {
2 var content = $("#sidebar_content"),
7 iconUrl: OSM.NEW_NOTE_MARKER,
12 iconUrl: OSM.OPEN_NOTE_MARKER,
17 iconUrl: OSM.CLOSED_NOTE_MARKER,
23 page.pushstate = page.popstate = function (path, id) {
24 OSM.loadSidebarContent(path, function () {
27 var data = $(".details").data();
29 var latLng = L.latLng(data.coordinates.split(","));
30 if (!map.getBounds().contains(latLng)) moveToNote();
34 page.load = function (path, id) {
39 function initialize(path, id) {
40 content.find("button[type=submit]").on("click", function (e) {
42 var data = $(e.target).data();
43 var form = e.target.form;
45 $(form).find("button[type=submit]").prop("disabled", true);
51 data: { text: $(form.text).val() },
52 success: function () {
53 OSM.loadSidebarContent(path, function () {
58 error: function (xhr) {
59 $(form).find("#comment-error")
60 .text(xhr.responseText)
61 .prop("hidden", false);
67 content.find("textarea").on("input", function (e) {
68 updateButtons(e.target.form);
71 content.find("textarea").val("").trigger("input");
73 var data = $(".details").data();
79 latLng: L.latLng(data.coordinates.split(",")),
80 icon: noteIcons[data.status]
85 function updateButtons(form) {
86 $(form).find("button[type=submit]").prop("disabled", false);
87 if ($(form.text).val() === "") {
88 $(form.close).text($(form.close).data("defaultActionText"));
89 $(form.comment).prop("disabled", true);
91 $(form.close).text($(form.close).data("commentActionText"));
92 $(form.comment).prop("disabled", false);
96 function moveToNote() {
97 var data = $(".details").data();
99 var latLng = L.latLng(data.coordinates.split(","));
101 if (!window.location.hash || window.location.hash.match(/^#?c[0-9]+$/)) {
102 OSM.router.withoutMoveListener(function () {
103 map.setView(latLng, 15, { reset: true });
108 page.unload = function () {