1 OSM.Note = function (map) {
2 var content = $("#sidebar_content"),
8 iconUrl: OSM.NEW_NOTE_MARKER,
13 iconUrl: OSM.OPEN_NOTE_MARKER,
18 iconUrl: OSM.CLOSED_NOTE_MARKER,
24 function updateNote(form, method, url) {
25 $(form).find("input[type=submit]").prop("disabled", true);
31 data: { text: $(form.text).val() },
32 success: function () {
33 OSM.loadSidebarContent(window.location.pathname, page.load);
38 page.pushstate = page.popstate = function (path) {
39 OSM.loadSidebarContent(path, function () {
40 initialize(function () {
41 var data = $(".details").data(),
42 latLng = L.latLng(data.coordinates.split(","));
43 if (!map.getBounds().contains(latLng)) moveToNote();
48 page.load = function () {
49 initialize(moveToNote);
52 function initialize(callback) {
53 content.find("input[type=submit]").on("click", function (e) {
55 var data = $(e.target).data();
56 updateNote(e.target.form, data.method, data.url);
59 content.find("textarea").on("input", function (e) {
60 var form = e.target.form;
62 if ($(e.target).val() === "") {
63 $(form.close).val(I18n.t("javascripts.notes.show.resolve"));
64 $(form.comment).prop("disabled", true);
66 $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve"));
67 $(form.comment).prop("disabled", false);
71 content.find("textarea").val("").trigger("input");
73 var data = $(".details").data(),
74 latLng = L.latLng(data.coordinates.split(","));
76 if (!halo || !map.hasLayer(halo)) {
77 halo = L.circleMarker(latLng, {
86 if (currentNote && map.hasLayer(currentNote)) map.removeLayer(currentNote);
88 currentNote = L.marker(latLng, {
89 icon: noteIcons[data.status],
94 map.addLayer(currentNote);
96 if (callback) callback();
99 function moveToNote() {
100 var data = $(".details").data(),
101 latLng = L.latLng(data.coordinates.split(","));
103 if (!window.location.hash || window.location.hash.match(/^#?c[0-9]+$/)) {
104 OSM.router.withoutMoveListener(function () {
105 map.setView(latLng, 15, { reset: true });
110 page.unload = function () {
111 if (map.hasLayer(halo)) map.removeLayer(halo);
112 if (map.hasLayer(currentNote)) map.removeLayer(currentNote);