]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/heatmap.js
Create heatmap links using <a> elements
[rails.git] / app / assets / javascripts / heatmap.js
index 2958da3b88d99f9b65d475da722963a66cce334b..09013ae5a10303d7a0136ce13c04f7ffd5b8f713 100644 (file)
@@ -34,7 +34,7 @@ document.addEventListener("DOMContentLoaded", () => {
         type: "month",
         gutter: 4,
         label: {
-          text: (timestamp) => monthNames[new Date(timestamp).getMonth() + 1],
+          text: (timestamp) => monthNames[new Date(timestamp).getUTCMonth() + 1],
           position: "top",
           textAlign: "middle"
         },
@@ -70,17 +70,19 @@ document.addEventListener("DOMContentLoaded", () => {
       }]
     ]);
 
-    cal.on("mouseover", (event, _timestamp, value) => {
-      if (value) event.target.style.cursor = "pointer";
-    });
+    cal.on("mouseover", (event, timestamp, value) => {
+      if (!displayName || !value) return;
+      if (event.target.parentElement.nodeName === "a") return;
 
-    cal.on("click", (_event, timestamp) => {
-      if (!displayName) return;
       for (const { date, max_id } of heatmapData) {
         if (!max_id) continue;
         if (timestamp !== Date.parse(date)) continue;
+
         const params = new URLSearchParams([["before", max_id + 1]]);
-        location = `/user/${encodeURIComponent(displayName)}/history?${params}`;
+        const a = document.createElementNS("http://www.w3.org/2000/svg", "a");
+        a.setAttribute("href", `/user/${encodeURIComponent(displayName)}/history?${params}`);
+        $(event.target).wrap(a);
+        break;
       }
     });
   }