X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5603309026a8c7f81ea7fd91f164c8810437e9bc..7cf9bf0e553a141acab2afea53842f97eddd0a40:/app/assets/javascripts/index/new_note.js diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 76d134ce6..a1511a3bc 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -1,5 +1,3 @@ -//= require qs/dist/qs - OSM.NewNote = function (map) { var noteLayer = map.noteLayer, content = $("#sidebar_content"), @@ -107,6 +105,12 @@ OSM.NewNote = function (map) { newNoteMarker = null; } + function moveNewNotMarkerToClick(e) { + if (newNoteMarker) newNoteMarker.setLatLng(e.latlng); + if (halo) halo.setLatLng(e.latlng); + content.find("textarea").focus(); + } + function updateControls() { const zoomedOut = addNoteButton.hasClass("disabled"); const withoutText = content.find("textarea").val() === ""; @@ -127,11 +131,11 @@ OSM.NewNote = function (map) { map.addLayer(noteLayer); - var params = Qs.parse(path.substring(path.indexOf("?") + 1)); + const params = new URLSearchParams(path.substring(path.indexOf("?"))); var markerLatlng; - if (params.lat && params.lon) { - markerLatlng = L.latLng(params.lat, params.lon); + if (params.has("lat") && params.has("lon")) { + markerLatlng = L.latLng(params.get("lat"), params.get("lon")); } else { markerLatlng = map.getCenter(); } @@ -156,12 +160,17 @@ OSM.NewNote = function (map) { newNoteMarker.dragging.disable(); createNote(location, text, (feature) => { + if (typeof OSM.user === "undefined") { + var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0; + Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" }); + } content.find("textarea").val(""); addCreatedNoteMarker(feature); OSM.router.route("/note/" + feature.properties.id); }); }); + map.on("click", moveNewNotMarkerToClick); addNoteButton.on("disabled enabled", updateControls); updateControls(); @@ -169,6 +178,7 @@ OSM.NewNote = function (map) { }; page.unload = function () { + map.off("click", moveNewNotMarkerToClick); addNoteButton.off("disabled enabled", updateControls); removeNewNoteMarker(); addNoteButton.removeClass("active");