mapcomplete/UI/ShareButton.ts
Pieter Vander Vennet 4d2e8b6f24 Fix share button
2020-11-23 12:54:10 +01:00

39 lines
No EOL
1.2 KiB
TypeScript

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 `<button type="button" class="share-button" id="${this.id}">${this._embedded.Render()}</button>`
}
protected InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
const self= this;
htmlElement.addEventListener('click', () => {
alert("URL:" + self._shareData.url)
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');
}
});
}
}