1 OSM.Note = function (map) {
2 var noteLayer = map.noteLayer,
3 content = $('#sidebar_content'),
9 iconUrl: "<%= image_path('new_note_marker.png') %>",
14 iconUrl: "<%= image_path('open_note_marker.png') %>",
19 iconUrl: "<%= image_path('closed_note_marker.png') %>",
25 function updateNote(form, method, url) {
26 $(form).find("input[type=submit]").prop("disabled", true);
32 data: {text: $(form.text).val()},
33 success: function () {
34 OSM.loadSidebarContent(window.location.pathname, page.load);
39 page.pushstate = page.popstate = function (path) {
40 OSM.loadSidebarContent(path, function() {
41 initialize(function() {
42 var data = $('.details').data(),
43 latLng = L.latLng(data.coordinates.split(','));
44 if (!map.getBounds().contains(latLng)) moveToNote();
49 page.load = function() {
50 initialize(moveToNote);
53 function initialize(callback) {
54 content.find("input[type=submit]").on("click", function (e) {
56 var data = $(e.target).data();
57 updateNote(e.target.form, data.method, data.url);
60 content.find("textarea").on("input", function (e) {
61 var form = e.target.form;
63 if ($(e.target).val() == "") {
64 $(form.close).val(I18n.t("javascripts.notes.show.resolve"));
65 $(form.comment).prop("disabled", true);
67 $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve"));
68 $(form.comment).prop("disabled", false);
72 content.find("textarea").val('').trigger("input");
74 var data = $('.details').data(),
75 latLng = L.latLng(data.coordinates.split(','));
77 if (!map.hasLayer(halo)) {
78 halo = L.circleMarker(latLng, {
87 if (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.moveListenerOff();
105 map.once('moveend', OSM.router.moveListenerOn);
106 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);