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 (!map.hasLayer(halo)) {
77 halo = L.circleMarker(latLng, {
86 if (map.hasLayer(currentNote)) map.removeLayer(currentNote);
87 currentNote = L.marker(latLng, {
88 icon: noteIcons[data.status],
93 map.addLayer(currentNote);
95 if (callback) callback();
98 function moveToNote() {
99 var data = $('.details').data(),
100 latLng = L.latLng(data.coordinates.split(','));
102 if (!window.location.hash || window.location.hash.match(/^#?c[0-9]+$/)) {
103 OSM.router.withoutMoveListener(function () {
104 map.setView(latLng, 15, {reset: true});
109 page.unload = function () {
110 if (map.hasLayer(halo)) map.removeLayer(halo);
111 if (map.hasLayer(currentNote)) map.removeLayer(currentNote);