-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- hold Ctrl (or Cmd), move mouse over the image, move mouse wheel up and down to resize the image - double click on the image to restore its original size
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { dispatchNoteEdited } from "notes/events"; | ||
|
||
const MIN_ZOOM = 0.1; | ||
const ZOOM_STEP = 0.003; | ||
|
||
/* eslint-disable no-param-reassign */ | ||
const makeImgZoomable = (img: HTMLImageElement) => { | ||
img.onmouseleave = () => document.body.classList.remove("with-hovered-img"); | ||
img.onmouseenter = () => document.body.classList.add("with-hovered-img"); | ||
img.onwheel = (event) => { // Saved on keyup, see keyboard-shortcuts.ts | ||
if (!document.body.classList.contains("with-control")) { | ||
return; | ||
} | ||
|
||
document.body.classList.add("resizing-img"); | ||
|
||
const zoomChange = ZOOM_STEP * event.deltaY; | ||
// @ts-ignore | ||
const parsedZoom = parseFloat(img.style.zoom); | ||
// @ts-ignore | ||
img.style.zoom = Math.max(MIN_ZOOM, (Number.isNaN(parsedZoom) ? 1 : parsedZoom) + zoomChange); | ||
}; | ||
img.ondblclick = () => { // Saved immediately | ||
// @ts-ignore | ||
img.style.zoom = ""; | ||
dispatchNoteEdited(); | ||
}; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const initImgs = () => { | ||
document.body.classList.remove("with-hovered-img"); | ||
|
||
const imgs = document.querySelectorAll<HTMLImageElement>("body > #content-container > #content img"); | ||
imgs.forEach(makeImgZoomable); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters