import {UIEventSource} from "../UIEventSource"; import {UIElement} from "../UIElement"; import {LicenseInfo, Wikimedia} from "../../Logic/Wikimedia"; export class WikimediaImage extends UIElement { static allLicenseInfos: any = {}; private _imageMeta: UIEventSource; private _imageLocation : string; constructor(source: string) { super(undefined) this._imageLocation = source; if (WikimediaImage.allLicenseInfos[source] !== undefined) { this._imageMeta = WikimediaImage.allLicenseInfos[source]; } else { this._imageMeta = new UIEventSource(new LicenseInfo()); WikimediaImage.allLicenseInfos[source] = this._imageMeta; const self = this; Wikimedia.LicenseData(source, (info) => { self._imageMeta.setData(info); }) } this.ListenTo(this._imageMeta); } protected InnerRender(): string { let url = Wikimedia.ImageNameToUrl(this._imageLocation, 500, 400); url = url.replace(/'/g, '%27'); const wikimediaLink = "" + "Wikimedia Commons Logo" + " "; const attribution = "" + (this._imageMeta.data.artist ?? "") + "" + " " + (this._imageMeta.data.licenseShortName ?? "") + ""; const image = ""; return "
" + image + "
" + wikimediaLink + attribution + "
" + "
"; } }