mapcomplete/UI/Base/Img.ts

33 lines
843 B
TypeScript
Raw Normal View History

2021-01-06 02:21:50 +01:00
import {Utils} from "../../Utils";
2021-06-10 01:36:20 +02:00
import BaseUIElement from "../BaseUIElement";
2021-01-06 02:21:50 +01:00
2021-06-10 01:36:20 +02:00
export default class Img extends BaseUIElement {
private _src: string;
2021-06-10 01:36:20 +02:00
constructor(src: string) {
super();
this._src = src;
}
2021-06-10 01:36:20 +02:00
static AsData(source: string) {
if (Utils.runningFromConsole) {
return source;
}
return `data:image/svg+xml;base64,${(btoa(source))}`;
}
2021-06-10 01:36:20 +02:00
static AsImageElement(source: string, css_class: string = "", style = ""): string {
2021-02-20 03:29:55 +01:00
return `<img class="${css_class}" style="${style}" alt="" src="${Img.AsData(source)}">`;
2020-11-05 12:28:02 +01:00
}
2021-06-10 01:36:20 +02:00
protected InnerConstructElement(): HTMLElement {
const el = document.createElement("img")
el.src = this._src;
2021-06-12 02:58:32 +02:00
el.onload = () => {
el.style.opacity = "1"
}
2021-06-10 01:36:20 +02:00
return el;
}
}