Vanessa 2023-11-17 21:57:08 +08:00
parent 7c1f49e862
commit aa208bb3fc
7 changed files with 113 additions and 113 deletions

View file

@ -65,12 +65,60 @@ export const initWindowEvent = (app: App) => {
globalClick(event);
});
if (isIPad()) {
let time = 0;
document.addEventListener("touchstart", () => {
time = new Date().getTime();
}, false);
document.addEventListener("touchend", (event) => {
let time = 0;
document.addEventListener("touchstart", (event) => {
time = new Date().getTime();
// https://github.com/siyuan-note/siyuan/issues/6328
const target = event.target as HTMLElement;
if (hasClosestByClassName(target, "protyle-icons") ||
hasClosestByClassName(target, "item") ||
target.classList.contains("protyle-background__icon")) {
return;
}
// 触摸屏背景和嵌入块按钮显示
const backgroundElement = hasClosestByClassName(target, "protyle-background")
if (backgroundElement) {
if (target.tagName === "IMG" && backgroundElement.firstElementChild.querySelector(".protyle-icons").classList.contains("fn__none")) {
// 文档背景位置调整
const contentElement = hasClosestByClassName(backgroundElement, "protyle-content");
if (!contentElement) {
return;
}
contentElement.style.overflow = "hidden"
const y = event.touches[0].clientY;
const documentSelf = document;
const height = (target as HTMLImageElement).naturalHeight * target.clientWidth / (target as HTMLImageElement).naturalWidth - target.clientHeight;
let originalPositionY = parseFloat(target.style.objectPosition.substring(7)) || 50;
if (target.style.objectPosition.endsWith("px")) {
originalPositionY = -parseInt(target.style.objectPosition.substring(7)) / height * 100;
}
documentSelf.ontouchmove = (moveEvent) => {
target.style.objectPosition = `center ${((y - moveEvent.touches[0].clientY) / height * 100 + originalPositionY).toFixed(2)}%`;
};
documentSelf.ontouchend = () => {
contentElement.style.overflow = ""
documentSelf.ontouchmove = null;
documentSelf.ontouchstart = null;
documentSelf.ondragstart = null;
documentSelf.onselectstart = null;
documentSelf.onselect = null;
};
} else {
backgroundElement.classList.toggle("protyle-background--mobileshow");
}
return;
}
const embedBlockElement = hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed");
if (embedBlockElement) {
embedBlockElement.firstElementChild.classList.toggle("protyle-icons--show");
return;
}
}, false);
document.addEventListener("touchend", (event) => {
if (isIPad()) {
// https://github.com/siyuan-note/siyuan/issues/9113
if (globalTouchEnd(event, undefined, time, app)) {
event.stopImmediatePropagation();
event.preventDefault();
@ -103,6 +151,6 @@ export const initWindowEvent = (app: App) => {
event.preventDefault();
return;
}
}, false);
}
}
}, false);
};