Add missing url attribute for message share buttons' container
authorMatthias Schmidt <gravatronics@live.com>
Sun, 11 Apr 2021 10:57:21 +0000 (12:57 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 11 Apr 2021 10:57:21 +0000 (12:57 +0200)
See #4108

ts/WoltLabSuite/Core/Ui/Message/Share/Dialog.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/Share/Dialog.js

index 16e2f7734c862edc3668422e54052e651dfa0d38..e62eb19ebb2583cf895a53f25a5204b55a1f1e78 100644 (file)
@@ -37,17 +37,11 @@ async function copy(event: Event): Promise<void> {
 /**
  * Returns all of the dialog elements shown in the dialog.
  */
-function getDialogElements(shareButton: HTMLElement): string {
-  let dialogOptions = "";
+function getDialogElements(shareButton: HTMLAnchorElement): string {
+  const permalink = shareButton.href;
 
-  let permalink = "";
-  if (shareButton instanceof HTMLAnchorElement && shareButton.href) {
-    permalink = shareButton.href;
-  }
+  let dialogOptions = getDialogElement("wcf.message.share.permalink", permalink);
 
-  if (permalink) {
-    dialogOptions += getDialogElement("wcf.message.share.permalink", permalink);
-  }
   if (shareButton.dataset.bbcode) {
     dialogOptions += getDialogElement("wcf.message.share.permalink.bbcode", shareButton.dataset.bbcode);
   }
@@ -116,14 +110,14 @@ function getProviderButtons(): string {
 function openDialog(event: MouseEvent): void {
   event.preventDefault();
 
-  const target = event.currentTarget as HTMLElement;
+  const target = event.currentTarget as HTMLAnchorElement;
   const dialogId = `shareContentDialog_${DomUtil.identify(target)}`;
   if (!UiDialog.getDialog(dialogId)) {
     const providerButtons = getProviderButtons();
     let providerElement = "";
     if (providerButtons) {
       providerElement = `
-        <dl class="messageShareButtons jsMessageShareButtons">
+        <dl class="messageShareButtons jsMessageShareButtons" data-url="${StringUtil.escapeHTML(target.href)}">
           <dt>${Language.get("wcf.message.share.socialMedia")}</dt>
           <dd>${providerButtons}</dd>
         </dl>
@@ -142,7 +136,7 @@ function openDialog(event: MouseEvent): void {
     });
 
     dialogData.content.style.maxWidth = "600px";
-    dialogData.dialog
+    dialogData.content
       .querySelectorAll(".shareDialogCopyButton")
       .forEach((el) => el.addEventListener("click", (ev) => copy(ev)));
 
@@ -155,7 +149,7 @@ function openDialog(event: MouseEvent): void {
 }
 
 function registerButtons(): void {
-  document.querySelectorAll(".shareButton").forEach((shareButton: HTMLElement) => {
+  document.querySelectorAll("a.shareButton").forEach((shareButton: HTMLElement) => {
     if (!shareButtons.has(shareButton)) {
       shareButton.addEventListener("click", (ev) => openDialog(ev));
 
index d70c839f7d48711fa3b1e4f7454f335b741498bc..3c76010fd2d8b6abf3c8a7e64fd3e3d6c0c192a2 100644 (file)
@@ -35,14 +35,8 @@ define(["require", "exports", "tslib", "../../Dialog", "../../../Dom/Util", "../
      * Returns all of the dialog elements shown in the dialog.
      */
     function getDialogElements(shareButton) {
-        let dialogOptions = "";
-        let permalink = "";
-        if (shareButton instanceof HTMLAnchorElement && shareButton.href) {
-            permalink = shareButton.href;
-        }
-        if (permalink) {
-            dialogOptions += getDialogElement("wcf.message.share.permalink", permalink);
-        }
+        const permalink = shareButton.href;
+        let dialogOptions = getDialogElement("wcf.message.share.permalink", permalink);
         if (shareButton.dataset.bbcode) {
             dialogOptions += getDialogElement("wcf.message.share.permalink.bbcode", shareButton.dataset.bbcode);
         }
@@ -101,7 +95,7 @@ define(["require", "exports", "tslib", "../../Dialog", "../../../Dom/Util", "../
             let providerElement = "";
             if (providerButtons) {
                 providerElement = `
-        <dl class="messageShareButtons jsMessageShareButtons">
+        <dl class="messageShareButtons jsMessageShareButtons" data-url="${StringUtil.escapeHTML(target.href)}">
           <dt>${Language.get("wcf.message.share.socialMedia")}</dt>
           <dd>${providerButtons}</dd>
         </dl>
@@ -117,7 +111,7 @@ define(["require", "exports", "tslib", "../../Dialog", "../../../Dom/Util", "../
                 title: Language.get("wcf.message.share"),
             });
             dialogData.content.style.maxWidth = "600px";
-            dialogData.dialog
+            dialogData.content
                 .querySelectorAll(".shareDialogCopyButton")
                 .forEach((el) => el.addEventListener("click", (ev) => copy(ev)));
             if (providerButtons) {
@@ -129,7 +123,7 @@ define(["require", "exports", "tslib", "../../Dialog", "../../../Dom/Util", "../
         }
     }
     function registerButtons() {
-        document.querySelectorAll(".shareButton").forEach((shareButton) => {
+        document.querySelectorAll("a.shareButton").forEach((shareButton) => {
             if (!shareButtons.has(shareButton)) {
                 shareButton.addEventListener("click", (ev) => openDialog(ev));
                 shareButtons.add(shareButton);