import {UIEventSource} from "../UIEventSource"; import {UIElement} from "../UIElement"; import {LicenseInfo} from "../../Logic/Wikimedia"; import {Imgur} from "../../Logic/Imgur"; export class ImgurImage extends UIElement { /*** * Dictionary from url to alreayd known license info */ static allLicenseInfos: any = {}; private _imageMeta: UIEventSource; private _imageLocation: string; constructor(source: string) { super(undefined) this._imageLocation = source; if (ImgurImage.allLicenseInfos[source] !== undefined) { this._imageMeta = ImgurImage.allLicenseInfos[source]; } else { this._imageMeta = new UIEventSource(null); ImgurImage.allLicenseInfos[source] = this._imageMeta; const self = this; Imgur.getDescriptionOfImage(source, (license) => { self._imageMeta.setData(license) }) } this.ListenTo(this._imageMeta); } protected InnerRender(): string { const image = ""; if(this._imageMeta.data === null){ return image; } const attribution = "" + (this._imageMeta.data.artist ?? "") + "" + " " + (this._imageMeta.data.licenseShortName ?? "") + ""; return "
" + image + "
" + attribution + "
" + "
"; } }