| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | import {UIElement} from "../UIElement"; | 
					
						
							| 
									
										
										
										
											2020-08-17 17:23:15 +02:00
										 |  |  | import {LicenseInfo, Wikimedia} from "../../Logic/Web/Wikimedia"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import Link from "../Base/Link"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  | import Attribution from "./Attribution"; | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							|  |  |  | import Img from "../Base/Img"; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class WikimediaImage extends UIElement { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |     static allLicenseInfos: any = {}; | 
					
						
							| 
									
										
										
										
											2020-09-10 19:33:06 +02:00
										 |  |  |     private readonly _imageMeta: UIEventSource<LicenseInfo>; | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |     private readonly _imageLocation: string; | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(source: string) { | 
					
						
							|  |  |  |         super(undefined) | 
					
						
							|  |  |  |         this._imageLocation = source; | 
					
						
							|  |  |  |         if (WikimediaImage.allLicenseInfos[source] !== undefined) { | 
					
						
							|  |  |  |             this._imageMeta = WikimediaImage.allLicenseInfos[source]; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this._imageMeta = new UIEventSource<LicenseInfo>(new LicenseInfo()); | 
					
						
							|  |  |  |             WikimediaImage.allLicenseInfos[source] = this._imageMeta; | 
					
						
							| 
									
										
										
										
											2020-07-08 15:09:34 +02:00
										 |  |  |             const self = this; | 
					
						
							|  |  |  |             Wikimedia.LicenseData(source, (info) => { | 
					
						
							|  |  |  |                 self._imageMeta.setData(info); | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.ListenTo(this._imageMeta); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |     InnerRender(): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |         const url = Wikimedia.ImageNameToUrl(this._imageLocation, 500, 400) | 
					
						
							|  |  |  |             .replace(/'/g, '%27'); | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |         const image = new Img(url) | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |         const meta = this._imageMeta?.data; | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |         if (!meta) { | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |             return image; | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         new Link(Svg.wikimedia_commons_white_img, | 
					
						
							| 
									
										
										
										
											2020-11-06 01:58:26 +01:00
										 |  |  |             `https://commons.wikimedia.org/wiki/${this._imageLocation}`, true) | 
					
						
							|  |  |  |             .SetStyle("width:2em;height: 2em"); | 
					
						
							| 
									
										
										
										
											2021-03-17 14:33:22 +01:00
										 |  |  |          | 
					
						
							|  |  |  |         return new Combine([ | 
					
						
							|  |  |  |             image, | 
					
						
							|  |  |  |             new Attribution(meta.artist, meta.license, Svg.wikimedia_commons_white_svg()) | 
					
						
							| 
									
										
										
										
											2021-06-11 22:51:45 +02:00
										 |  |  |         ]).SetClass("relative block") | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |