mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Add sticky note support to obsidian
This commit is contained in:
@@ -67,8 +67,9 @@ export function onClick(element, action) {
|
||||
* @param {HTMLElement|null} element The element to detect drag events on
|
||||
* @param {boolean} [parent] Whether to move the parent element when the child is dragged
|
||||
* @param {(top: number, left: number) => void} [callback] Callback for when element is moved
|
||||
* @param {HTMLElement} [pageElement] The page element to constrain movement within
|
||||
*/
|
||||
export function makeDraggable(element, parent = true, callback = () => { }) {
|
||||
export function makeDraggable(element, parent = true, callback = () => { }, pageElement) {
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
@@ -114,9 +115,12 @@ export function makeDraggable(element, parent = true, callback = () => { }) {
|
||||
});
|
||||
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
const page = pageElement || document.documentElement;
|
||||
const maxX = page.scrollWidth - elementToMove.clientWidth;
|
||||
const maxY = page.scrollHeight - elementToMove.clientHeight;
|
||||
if (isMouseDown) {
|
||||
elementToMove.style.left = `${Math.max(0, e.clientX - offsetX)}px`;
|
||||
elementToMove.style.top = `${Math.max(0, e.clientY - offsetY)}px`;
|
||||
elementToMove.style.left = `${Math.max(0, Math.min(maxX, e.clientX - offsetX))}px`;
|
||||
elementToMove.style.top = `${Math.max(0, Math.min(maxY, e.clientY - offsetY))}px`;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user