Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor: 💡 improve image zoom
Jin47a363be0f94
diff --git a/src/public/app/services/content_renderer.ts b/src/public/app/services/content_renderer.tsindex 7afdc76d04..0bf7bca281 100644--- a/src/public/app/services/content_renderer.ts+++ b/src/public/app/services/content_renderer.ts@@ -150,7 +150,7 @@ function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery<HTMLE$renderedContent.append($img);if (options.imageHasZoom) {- setTimeout(() => {+ const initZoom = async () => {const element = document.querySelector(`#${$img.attr("id")}`);if (element) {WheelZoom.create(`#${$img.attr("id")}`, {@@ -158,8 +158,11 @@ function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery<HTMLEspeed: 1.3,zoomOnClick: false});+ } else {+ requestAnimationFrame(initZoom);}- }, 0);+ };+ initZoom();}imageContextMenuService.setupContextMenu($img);diff --git a/src/public/app/widgets/type_widgets/image.ts b/src/public/app/widgets/type_widgets/image.tsindex a14af8af8c..e082fd0037 100644--- a/src/public/app/widgets/type_widgets/image.ts+++ b/src/public/app/widgets/type_widgets/image.ts@@ -54,7 +54,7 @@ class ImageTypeWidget extends TypeWidget {this.$imageWrapper = this.$widget.find(".note-detail-image-wrapper");this.$imageView = this.$widget.find(".note-detail-image-view").attr("id", `image-view-${utils.randomString(10)}`);- setTimeout(() => {+ const initZoom = async () => {const element = document.querySelector(`#${this.$imageView.attr("id")}`);if (element) {WheelZoom.create(`#${this.$imageView.attr("id")}`, {@@ -62,8 +62,11 @@ class ImageTypeWidget extends TypeWidget {speed: 1.3,zoomOnClick: false});+ } else {+ requestAnimationFrame(initZoom);}- }, 0);+ };+ initZoom();imageContextMenuService.setupContextMenu(this.$imageView);