forked from MapComplete/MapComplete
		
	Experimenting with a share button...
This commit is contained in:
		
							parent
							
								
									d953dd4aa6
								
							
						
					
					
						commit
						e10f9b61e2
					
				
					 2 changed files with 40 additions and 2 deletions
				
			
		
							
								
								
									
										38
									
								
								UI/ShareButton.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								UI/ShareButton.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 `<button type="button" id="${this.id}">${this._embedded.Render()}</button>` | ||||
|     } | ||||
| 
 | ||||
|     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'); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -196,8 +196,8 @@ export default class SpecialVisualizations { | |||
|                     } | ||||
|                 ], | ||||
|                 constr: (tagSource: UIEventSource<any>, 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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue