Fix the handling of external links in the mobile main menu
authorAlexander Ebert <ebert@woltlab.com>
Mon, 13 Mar 2023 11:27:47 +0000 (12:27 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 13 Mar 2023 11:27:47 +0000 (12:27 +0100)
See https://www.woltlab.com/community/thread/299236-externe-hauptmen%C3%BC-links-werden-trotz-einstellung-im-acp-mobil-nicht-in-neuem-tab/

ts/WoltLabSuite/Core/Ui/Page/Menu/Main.ts
ts/WoltLabSuite/Core/Ui/Page/Menu/Main/Frontend.ts
ts/WoltLabSuite/Core/Ui/Page/Menu/Main/Provider.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Page/Menu/Main.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Page/Menu/Main/Frontend.js

index 5691ab8840c2f478beb7f77c0514edff1b869940..358fc46a2e8e4b7cee97482b387a9242b4352e05 100644 (file)
@@ -277,6 +277,9 @@ export class PageMenuMain implements PageMenuProvider {
       if (menuItem.identifier) {
         link.dataset.identifier = menuItem.identifier;
       }
+      if (menuItem.openInNewWindow) {
+        link.target = "_blank";
+      }
 
       if (menuItem.counter > 0) {
         const counter = document.createElement("span");
index 3409ca7501bb6afa06cfc2820a712c11e18bc0b5..4a4002c42363b58bd31aafc098aadc3f946ed50b 100644 (file)
@@ -35,8 +35,13 @@ function normalizeMenuItem(menuItem: HTMLElement, depth: MenuItemDepth): MenuIte
   // `link.href` represents the computed link, not the raw value.
   const href = anchor.getAttribute("href");
   let link: string | undefined = undefined;
+  let openInNewWindow: boolean | undefined = undefined;
   if (href && href !== "#") {
     link = anchor.href;
+
+    if (anchor.target === "_blank") {
+      openInNewWindow = true;
+    }
   }
 
   const active = menuItem.classList.contains("active");
@@ -50,6 +55,7 @@ function normalizeMenuItem(menuItem: HTMLElement, depth: MenuItemDepth): MenuIte
     depth,
     identifier,
     link,
+    openInNewWindow,
     title,
   };
 }
index bf2954222519efc8a9e6bac844db97574fa24005..dd7bde42c469c32e119d231d6234463ffbf53e0f 100644 (file)
@@ -18,6 +18,7 @@ export type MenuItem = {
   depth: MenuItemDepth;
   identifier: string | null;
   link?: string;
+  openInNewWindow?: boolean;
   title: string;
 };
 
index 792796a84cb461b8712a30bedfcdb1424fbd4440..d8bbe623168def2c8b54fdf8f5d614a01126aa5d 100644 (file)
@@ -216,6 +216,9 @@ define(["require", "exports", "tslib", "./Container", "../../../Language", "../.
                 if (menuItem.identifier) {
                     link.dataset.identifier = menuItem.identifier;
                 }
+                if (menuItem.openInNewWindow) {
+                    link.target = "_blank";
+                }
                 if (menuItem.counter > 0) {
                     const counter = document.createElement("span");
                     counter.classList.add("pageMenuMainItemCounter", "badge", "badgeUpdate");
index 3ca79e3e7f31ce4d11084a7fb7460be2ffd12ab7..bee5221d55c455db1a49b04d3e997615e590696a 100644 (file)
@@ -32,8 +32,12 @@ define(["require", "exports"], function (require, exports) {
         // `link.href` represents the computed link, not the raw value.
         const href = anchor.getAttribute("href");
         let link = undefined;
+        let openInNewWindow = undefined;
         if (href && href !== "#") {
             link = anchor.href;
+            if (anchor.target === "_blank") {
+                openInNewWindow = true;
+            }
         }
         const active = menuItem.classList.contains("active");
         const identifier = anchor.parentElement.dataset.identifier;
@@ -44,6 +48,7 @@ define(["require", "exports"], function (require, exports) {
             depth,
             identifier,
             link,
+            openInNewWindow,
             title,
         };
     }