]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Use fixed small/compact nav breakpoint width
[rails.git] / app / assets / javascripts / application.js
index e8662e5cff4d45ffe47f9432cf4b13b939b27fb0..c6d7c4fe3b8aafdaf12498e191fcc5c60c0e01f5 100644 (file)
@@ -48,11 +48,9 @@ window.updateLinks = function (loc, zoom, layers, object) {
     const queryArgs = new URLSearchParams(link.search),
           editlink = $(link).hasClass("editlink");
 
     const queryArgs = new URLSearchParams(link.search),
           editlink = $(link).hasClass("editlink");
 
-    queryArgs.delete("node");
-    queryArgs.delete("way");
-    queryArgs.delete("relation");
-    queryArgs.delete("changeset");
-    queryArgs.delete("note");
+    for (const arg of ["node", "way", "relation", "changeset", "note"]) {
+      queryArgs.delete(arg);
+    }
 
     if (object && editlink) {
       queryArgs.set(object.type, object.id);
 
     if (object && editlink) {
       queryArgs.set(object.type, object.id);
@@ -92,21 +90,47 @@ $(document).ready(function () {
   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
   Turbo.session.drive = false;
 
   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
   Turbo.session.drive = false;
 
-  var headerWidth = 0,
-      compactWidth = 0;
+  let headerWidth = 0;
+  const breakpointWidth = 768;
 
   function updateHeader() {
     var windowWidth = $(window).width();
 
 
   function updateHeader() {
     var windowWidth = $(window).width();
 
-    if (windowWidth < compactWidth) {
-      $("body").removeClass("compact-nav").addClass("small-nav");
+    if (windowWidth < breakpointWidth) {
+      $("body").addClass("small-nav");
+      expandSecondaryMenu();
     } else if (windowWidth < headerWidth) {
     } else if (windowWidth < headerWidth) {
-      $("body").addClass("compact-nav").removeClass("small-nav");
+      $("body").removeClass("small-nav");
+      collapseSecondaryMenu();
     } else {
     } else {
-      $("body").removeClass("compact-nav").removeClass("small-nav");
+      $("body").removeClass("small-nav");
+      expandSecondaryMenu();
     }
   }
 
     }
   }
 
+  function expandSecondaryMenu() {
+    $("#compact-secondary-nav > ul").find("li").children("a")
+      .removeClass("dropdown-item")
+      .addClass("nav-link")
+      .addClass(function () {
+        return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary";
+      });
+    $("#compact-secondary-nav > ul").find("li")
+      .addClass("nav-item")
+      .prependTo("header nav.secondary > ul");
+    $("#compact-secondary-nav").hide();
+  }
+
+  function collapseSecondaryMenu() {
+    $("header nav.secondary > ul").find("li:not(#compact-secondary-nav)").children("a")
+      .addClass("dropdown-item")
+      .removeClass("nav-link text-secondary text-secondary-emphasis");
+    $("header nav.secondary > ul").find("li:not(#compact-secondary-nav)")
+      .removeClass("nav-item")
+      .prependTo("#compact-secondary-nav > ul");
+    $("#compact-secondary-nav").show();
+  }
+
   /*
    * Chrome 60 and later seem to fire the "ready" callback
    * before the DOM is fully ready causing us to measure the
   /*
    * Chrome 60 and later seem to fire the "ready" callback
    * before the DOM is fully ready causing us to measure the
@@ -115,17 +139,9 @@ $(document).ready(function () {
    */
   setTimeout(function () {
     $("header").children(":visible").each(function (i, e) {
    */
   setTimeout(function () {
     $("header").children(":visible").each(function (i, e) {
-      headerWidth = headerWidth + $(e).outerWidth();
+      headerWidth += $(e).outerWidth();
     });
 
     });
 
-    $("body").addClass("compact-nav");
-
-    $("header").children(":visible").each(function (i, e) {
-      compactWidth = compactWidth + $(e).outerWidth();
-    });
-
-    $("body").removeClass("compact-nav");
-
     $("header").removeClass("text-nowrap");
     $("header nav.secondary > ul").removeClass("flex-nowrap");
 
     $("header").removeClass("text-nowrap");
     $("header nav.secondary > ul").removeClass("flex-nowrap");