2020-07-08 15:09:34 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import {LicenseInfo} from "../../Logic/Web/Wikimedia";
|
|
|
|
import {Imgur} from "../../Logic/Web/Imgur";
|
2021-01-29 03:23:53 +01:00
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import Attribution from "./Attribution";
|
|
|
|
import {SimpleImageElement} from "./SimpleImageElement";
|
2020-07-08 15:09:34 +02:00
|
|
|
|
|
|
|
|
2020-09-13 03:29:44 +02:00
|
|
|
export class ImgurImage extends UIElement {
|
2020-07-08 15:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Dictionary from url to alreayd known license info
|
|
|
|
*/
|
2020-10-17 00:37:45 +02:00
|
|
|
private static allLicenseInfos: any = {};
|
2020-09-10 19:33:06 +02:00
|
|
|
private readonly _imageMeta: UIEventSource<LicenseInfo>;
|
|
|
|
private readonly _imageLocation: string;
|
2020-07-08 15:09:34 +02:00
|
|
|
|
|
|
|
constructor(source: string) {
|
|
|
|
super(undefined)
|
|
|
|
this._imageLocation = source;
|
|
|
|
if (ImgurImage.allLicenseInfos[source] !== undefined) {
|
|
|
|
this._imageMeta = ImgurImage.allLicenseInfos[source];
|
|
|
|
} else {
|
|
|
|
this._imageMeta = new UIEventSource<LicenseInfo>(null);
|
|
|
|
ImgurImage.allLicenseInfos[source] = this._imageMeta;
|
|
|
|
const self = this;
|
|
|
|
Imgur.getDescriptionOfImage(source, (license) => {
|
|
|
|
self._imageMeta.setData(license)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ListenTo(this._imageMeta);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-26 02:01:34 +02:00
|
|
|
InnerRender(): string {
|
2021-01-29 03:23:53 +01:00
|
|
|
const image = new SimpleImageElement( new UIEventSource (this._imageLocation));
|
2020-07-08 15:09:34 +02:00
|
|
|
|
|
|
|
if(this._imageMeta.data === null){
|
2021-01-29 03:23:53 +01:00
|
|
|
return image.Render();
|
2020-07-08 15:09:34 +02:00
|
|
|
}
|
2021-01-29 03:23:53 +01:00
|
|
|
|
|
|
|
const meta = this._imageMeta.data;
|
|
|
|
return new Combine([
|
|
|
|
image,
|
|
|
|
new Attribution(meta.artist, meta.license, undefined),
|
|
|
|
|
|
|
|
]).SetClass('block relative')
|
|
|
|
.Render();
|
2020-07-08 15:09:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|