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 () {
25 initialize(path, id, function () {
26 var data = $(".details").data();
28 var latLng = L.latLng(data.coordinates.split(","));
29 if (!map.getBounds().contains(latLng)) moveToNote();
34 page.load = function (path, id) {
35 initialize(path, id, moveToNote);
38 function initialize(path, id, callback) {
39 content.find("input[type=submit]").on("click", function (e) {
41 var data = $(e.target).data();
42 var form = e.target.form;
44 $(form).find("input[type=submit]").prop("disabled", true);
50 data: { text: $(form.text).val() },
51 success: function () {
52 OSM.loadSidebarContent(path, function () {
53 initialize(path, id, moveToNote);
56 error: function (xhr) {
57 $(form).find("#comment-error")
58 .text(xhr.responseText)
59 .prop("hidden", false);
65 content.find("textarea").on("input", function (e) {
66 updateButtons(e.target.form);
69 content.find("textarea").val("").trigger("input");
71 var data = $(".details").data();
77 latLng: L.latLng(data.coordinates.split(",")),
78 icon: noteIcons[data.status]
82 if (callback) callback();
85 function updateButtons(form) {
86 $(form).find("input[type=submit]").prop("disabled", false);
87 if ($(form.text).val() === "") {
88 $(form.close).val($(form.close).data("defaultActionText"));
89 $(form.comment).prop("disabled", true);
91 $(form.close).val($(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 () {