X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/283e7b975b5a80d3f3e8091ce83e8f89b33bb06c..00108bc9b7e9e03a47d89343e7f53eb924977ff8:/app/assets/javascripts/index/new_note.js?ds=sidebyside diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 4f38f8b55..b1457d10b 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -1,14 +1,12 @@ -//= require qs/dist/qs - OSM.NewNote = function (map) { - var noteLayer = map.noteLayer, - content = $("#sidebar_content"), - page = {}, - addNoteButton = $(".control-note .control-button"), - newNoteMarker, + const noteLayer = map.noteLayer, + content = $("#sidebar_content"), + page = {}, + addNoteButton = $(".control-note .control-button"); + let newNoteMarker, halo; - var noteIcons = { + const noteIcons = { "new": L.icon({ iconUrl: OSM.NEW_NOTE_MARKER, iconSize: [25, 40], @@ -36,21 +34,21 @@ OSM.NewNote = function (map) { }); function createNote(location, text, callback) { - $.ajax({ - url: "/api/0.6/notes.json", - type: "POST", - oauth: true, - data: { + fetch("/api/0.6/notes.json", { + method: "POST", + headers: { ...OSM.oauth }, + body: new URLSearchParams({ lat: location.lat, lon: location.lng, text - }, - success: callback - }); + }) + }) + .then(response => response.json()) + .then(callback); } function addCreatedNoteMarker(feature) { - var marker = L.marker(feature.geometry.coordinates.reverse(), { + const marker = L.marker(feature.geometry.coordinates.reverse(), { icon: noteIcons[feature.properties.status], opacity: 0.9, interactive: true @@ -133,11 +131,11 @@ OSM.NewNote = function (map) { map.addLayer(noteLayer); - var params = Qs.parse(path.substring(path.indexOf("?") + 1)); - var markerLatlng; + const params = new URLSearchParams(path.substring(path.indexOf("?"))); + let 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(); } @@ -163,7 +161,7 @@ OSM.NewNote = function (map) { createNote(location, text, (feature) => { if (typeof OSM.user === "undefined") { - var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0; + const 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("");