Fixes #368
This commit is contained in:
@@ -16,14 +16,29 @@ class InlineImageWidget extends WidgetType {
|
||||
readonly space: Space,
|
||||
) {
|
||||
super();
|
||||
// console.log("Creating widget", url);
|
||||
}
|
||||
|
||||
eq(other: InlineImageWidget) {
|
||||
return other.url === this.url && other.title === this.title;
|
||||
}
|
||||
|
||||
get estimatedHeight(): number {
|
||||
const cachedHeight = this.space.getCachedImageHeight(this.url);
|
||||
// console.log("Estimated height requested", this.url, cachedHeight);
|
||||
return cachedHeight;
|
||||
}
|
||||
|
||||
toDOM() {
|
||||
const img = document.createElement("img");
|
||||
// console.log("Creating DOM", this.url);
|
||||
const cachedImageHeight = this.space.getCachedImageHeight(this.url);
|
||||
img.onload = () => {
|
||||
// console.log("Loaded", this.url, "with height", img.height);
|
||||
if (img.height !== cachedImageHeight) {
|
||||
this.space.setCachedImageHeight(this.url, img.height);
|
||||
}
|
||||
};
|
||||
if (this.url.startsWith("http")) {
|
||||
img.src = this.url;
|
||||
} else {
|
||||
@@ -35,6 +50,9 @@ class InlineImageWidget extends WidgetType {
|
||||
img.title = this.title;
|
||||
img.style.display = "block";
|
||||
img.className = "sb-inline-img";
|
||||
if (cachedImageHeight > 0) {
|
||||
img.height = cachedImageHeight;
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user