From e10f9b61e2f1738d079995096d14f80210d15533 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 22 Nov 2020 03:16:56 +0100 Subject: [PATCH] Experimenting with a share button... --- UI/ShareButton.ts | 38 +++++++++++++++++++++++++++++++++++++ UI/SpecialVisualizations.ts | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 UI/ShareButton.ts diff --git a/UI/ShareButton.ts b/UI/ShareButton.ts new file mode 100644 index 0000000..42bb0ab --- /dev/null +++ b/UI/ShareButton.ts @@ -0,0 +1,38 @@ +import {UIElement} from "./UIElement"; + +export default class ShareButton extends UIElement{ + private _embedded: UIElement; + private _shareData: { text: string; title: string; url: string }; + + constructor(embedded: UIElement, shareData: { + text: string, + title: string, + url: string + }) { + super(); + this._embedded = embedded; + this._shareData = shareData; + } + + InnerRender(): string { + return `` + } + + protected InnerUpdate(htmlElement: HTMLElement) { + super.InnerUpdate(htmlElement); + const self= this; + htmlElement.addEventListener('click', () => { + if (navigator.share) { + navigator.share(self._shareData).then(() => { + console.log('Thanks for sharing!'); + }) + .catch(err => { + console.log(`Couldn't share because of`, err.message); + }); + } else { + console.log('web share not supported'); + } + }); + } + +} \ No newline at end of file diff --git a/UI/SpecialVisualizations.ts b/UI/SpecialVisualizations.ts index b88cff2..2f65470 100644 --- a/UI/SpecialVisualizations.ts +++ b/UI/SpecialVisualizations.ts @@ -196,8 +196,8 @@ export default class SpecialVisualizations { } ], constr: (tagSource: UIEventSource, args) => { - if (navigator.share !== undefined) { - return new FixedUiElement("").onClick(() => { + if (navigator.share) { + return new FixedUiElement("Share").onClick(() => { let name = tagSource["name"] let title= State.state.layoutToUse.data.title.txt