mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 01:50:12 +01:00
This commit is contained in:
parent
e837fc315a
commit
455bb1c050
2 changed files with 26 additions and 20 deletions
|
|
@ -34,28 +34,32 @@ export class Menu {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
itemElement.classList.add("b3-menu__item--show");
|
itemElement.classList.add("b3-menu__item--show");
|
||||||
const rect = subMenuElement.getBoundingClientRect();
|
this.showSubMenu(subMenuElement);
|
||||||
let style = "";
|
|
||||||
const leftPosition = rect.left - this.element.clientWidth - rect.width;
|
|
||||||
if (rect.right > window.innerWidth && (
|
|
||||||
leftPosition > 0 || Math.abs(leftPosition) < (rect.right - window.innerWidth))) {
|
|
||||||
if (leftPosition >= 0) {
|
|
||||||
style = "left:auto;right:100%;";
|
|
||||||
} else {
|
|
||||||
style = `z-index:1;mix-blend-mode: normal;left:-${this.element.style.left};`;
|
|
||||||
}
|
|
||||||
} else if (rect.right > window.innerWidth) {
|
|
||||||
style = `z-index:1;mix-blend-mode: normal;left:${window.innerWidth - rect.width - this.element.offsetLeft}px;`;
|
|
||||||
}
|
|
||||||
if (rect.bottom > window.innerHeight) {
|
|
||||||
style += `top: auto;bottom:-5px;max-height:${Math.min(rect.top, window.innerHeight * 0.4)}px`;
|
|
||||||
}
|
|
||||||
if (style) {
|
|
||||||
subMenuElement.setAttribute("style", style);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public showSubMenu(subMenuElement: Element) {
|
||||||
|
const rect = subMenuElement.getBoundingClientRect();
|
||||||
|
let style = "";
|
||||||
|
const leftPosition = rect.left - this.element.clientWidth - rect.width;
|
||||||
|
if (rect.right > window.innerWidth && (
|
||||||
|
leftPosition > 0 || Math.abs(leftPosition) < (rect.right - window.innerWidth))) {
|
||||||
|
if (leftPosition >= 0) {
|
||||||
|
style = "left:auto;right:100%;";
|
||||||
|
} else {
|
||||||
|
style = `z-index:1;mix-blend-mode: normal;left:-${this.element.style.left};`;
|
||||||
|
}
|
||||||
|
} else if (rect.right > window.innerWidth) {
|
||||||
|
style = `z-index:1;mix-blend-mode: normal;left:${window.innerWidth - rect.width - this.element.offsetLeft}px;`;
|
||||||
|
}
|
||||||
|
if (rect.bottom > window.innerHeight) {
|
||||||
|
style += `top: auto;bottom:-5px;max-height:${Math.min(rect.top, window.innerHeight * 0.4)}px`;
|
||||||
|
}
|
||||||
|
if (style) {
|
||||||
|
subMenuElement.setAttribute("style", style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private preventDefault(event: KeyboardEvent) {
|
private preventDefault(event: KeyboardEvent) {
|
||||||
if (!hasClosestByClassName(event.target as Element, "b3-menu")) {
|
if (!hasClosestByClassName(event.target as Element, "b3-menu")) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,9 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
x: rect.left,
|
x: rect.left,
|
||||||
y: rect.top
|
y: rect.top
|
||||||
}, true);
|
}, true);
|
||||||
window.siyuan.menus.menu.element.querySelector('[data-id="assetSubMenu"]').classList.add("b3-menu__item--show");
|
const itemElement = window.siyuan.menus.menu.element.querySelector('[data-id="assetSubMenu"]')
|
||||||
|
itemElement.classList.add("b3-menu__item--show");
|
||||||
|
window.siyuan.menus.menu.showSubMenu(itemElement.querySelector(".b3-menu__submenu"));
|
||||||
window.siyuan.menus.menu.element.querySelectorAll("input")[0].focus();
|
window.siyuan.menus.menu.element.querySelectorAll("input")[0].focus();
|
||||||
} else if (value === "---") {
|
} else if (value === "---") {
|
||||||
focusBlock(nodeElement);
|
focusBlock(nodeElement);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue