This commit is contained in:
parent
74273ebc1c
commit
f49dfa8273
7 changed files with 53 additions and 70 deletions
|
@ -8,7 +8,7 @@ import {isLocalPath, movePathTo, pathPosix} from "../util/pathName";
|
|||
import {MenuItem} from "./Menu";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {saveExport} from "../protyle/export";
|
||||
import {writeText} from "../protyle/util/compatibility";
|
||||
import {openByMobile, writeText} from "../protyle/util/compatibility";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
import {hideMessage, showMessage} from "../dialog/message";
|
||||
import {Dialog} from "../dialog";
|
||||
|
@ -652,13 +652,7 @@ export const exportMd = (id: string) => {
|
|||
id,
|
||||
}, response => {
|
||||
hideMessage(msgId);
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = response.data.zip;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(response.data.zip);
|
||||
} else {
|
||||
window.open(response.data.zip);
|
||||
}
|
||||
openByMobile(response.data.zip);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
|
@ -670,13 +664,7 @@ export const exportMd = (id: string) => {
|
|||
id,
|
||||
}, response => {
|
||||
hideMessage(msgId);
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = response.data.zip;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(response.data.zip);
|
||||
} else {
|
||||
window.open(response.data.zip);
|
||||
}
|
||||
openByMobile(response.data.zip);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -774,13 +762,7 @@ export const openMenu = (src: string, onlyMenu = false) => {
|
|||
label: window.siyuan.languages.useBrowserView,
|
||||
accelerator: "Click",
|
||||
click: () => {
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = src;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(src);
|
||||
} else {
|
||||
window.open(src);
|
||||
}
|
||||
openByMobile(src);
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
|
|
|
@ -579,8 +579,11 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
genImageWidthMenu(window.siyuan.languages.default, assetElement, imgElement, protyle, id, nodeElement, html),
|
||||
]
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
openMenu(imgElement.getAttribute("src"));
|
||||
const imgSrc = imgElement.getAttribute("src")
|
||||
if (imgSrc) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
openMenu(imgSrc);
|
||||
}
|
||||
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
||||
window.siyuan.menus.menu.element.querySelector("input").focus();
|
||||
};
|
||||
|
@ -736,7 +739,9 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
|
|||
}
|
||||
}).element);
|
||||
}
|
||||
openMenu(linkAddress);
|
||||
if (linkAddress) {
|
||||
openMenu(linkAddress);
|
||||
}
|
||||
window.siyuan.menus.menu.element.classList.remove("fn__none");
|
||||
if (focusText || protyle.lute.IsValidLinkDest(linkAddress)) {
|
||||
window.siyuan.menus.menu.element.querySelectorAll("input")[1].select();
|
||||
|
@ -812,10 +817,15 @@ export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {
|
|||
event.stopPropagation();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: "separator"
|
||||
}];
|
||||
return subMenus.concat(openMenu(iframeElement.getAttribute("src") || "", true) as IMenu[]);
|
||||
const iframeSrc = iframeElement.getAttribute("src");
|
||||
if (iframeSrc) {
|
||||
subMenus.push({
|
||||
type: "separator"
|
||||
})
|
||||
return subMenus.concat(openMenu(iframeSrc, true) as IMenu[]);
|
||||
}
|
||||
return subMenus;
|
||||
};
|
||||
|
||||
export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string) => {
|
||||
|
@ -833,11 +843,12 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
|
|||
event.stopPropagation();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
type: "separator"
|
||||
}];
|
||||
const src = videoElement.getAttribute("src");
|
||||
if (src.startsWith("assets/")) {
|
||||
subMenus.push({
|
||||
type: "separator"
|
||||
})
|
||||
subMenus.push({
|
||||
label: window.siyuan.languages.rename,
|
||||
click() {
|
||||
|
@ -845,7 +856,11 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
|
|||
}
|
||||
});
|
||||
}
|
||||
return subMenus.concat(openMenu(videoElement.getAttribute("src"), true) as IMenu[]);
|
||||
const VideoSrc = videoElement.getAttribute("src");
|
||||
if (VideoSrc) {
|
||||
return subMenus.concat(openMenu(VideoSrc, true) as IMenu[]);
|
||||
}
|
||||
return subMenus;
|
||||
};
|
||||
|
||||
export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: HTMLTableCellElement, range: Range) => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {fetchPost} from "../../util/fetch";
|
||||
import {getEventName, writeText} from "../../protyle/util/compatibility";
|
||||
import {getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
|
||||
import {popSearch} from "./search";
|
||||
import {initAppearance} from "../settings/appearance";
|
||||
import {closePanel} from "./closePanel";
|
||||
|
@ -382,11 +382,7 @@ ${accountHTML}
|
|||
});
|
||||
modelMainElement.querySelector("#exportData").addEventListener("click", () => {
|
||||
fetchPost("/api/export/exportData", {}, response => {
|
||||
if (window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(response.data.zip);
|
||||
return;
|
||||
}
|
||||
window.location.href = response.data.zip;
|
||||
openByMobile(response.data.zip);
|
||||
});
|
||||
});
|
||||
modelMainElement.querySelector("#importData").addEventListener("change", (event: InputEvent & { target: HTMLInputElement }) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {getEventName, writeText} from "../util/compatibility";
|
||||
import {getEventName, openByMobile, writeText} from "../util/compatibility";
|
||||
import {hasClosestByTag} from "../util/hasClosest";
|
||||
import {focusByRange} from "../util/selection";
|
||||
import {showMessage} from "../../dialog/message";
|
||||
|
@ -38,11 +38,9 @@ export class Preview {
|
|||
if (event.target.tagName === "A") {
|
||||
const linkAddress = event.target.getAttribute("href");
|
||||
if (isMobile()) {
|
||||
if (window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(linkAddress);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
openByMobile(linkAddress);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
export const openByMobile = (uri:string) => {
|
||||
if (!uri) {
|
||||
return;
|
||||
}
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = uri;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(uri);
|
||||
} else {
|
||||
window.open(uri);
|
||||
}
|
||||
};
|
||||
|
||||
export const writeText = async (text: string) => {
|
||||
try {
|
||||
// navigator.clipboard.writeText 抛出异常不进入 catch,这里需要先处理移动端复制
|
||||
|
|
|
@ -51,7 +51,7 @@ import {openAsset, openBy, openFileById} from "../../editor/util";
|
|||
import {openGlobalSearch} from "../../search/util";
|
||||
/// #endif
|
||||
import {BlockPanel} from "../../block/Panel";
|
||||
import {isCtrl} from "../util/compatibility";
|
||||
import {isCtrl, openByMobile} from "../util/compatibility";
|
||||
import {MenuItem} from "../../menus/Menu";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {onGet} from "../util/onGet";
|
||||
|
@ -1419,11 +1419,7 @@ export class WYSIWYG {
|
|||
const fileIds = fileElement.getAttribute("data-id").split("/");
|
||||
const linkAddress = `assets/${fileIds[1]}`;
|
||||
/// #if MOBILE
|
||||
if (typeof window.JSAndroid === "undefined") {
|
||||
window.open(linkAddress);
|
||||
} else {
|
||||
window.JSAndroid.openExternal(linkAddress);
|
||||
}
|
||||
openByMobile(linkAddress)
|
||||
/// #else
|
||||
if (window.siyuan.ctrlIsPressed) {
|
||||
openBy(linkAddress, "folder");
|
||||
|
@ -1441,13 +1437,7 @@ export class WYSIWYG {
|
|||
event.preventDefault();
|
||||
const linkAddress = aElement.getAttribute("data-href");
|
||||
/// #if MOBILE
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = linkAddress;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(linkAddress);
|
||||
} else {
|
||||
window.open(linkAddress);
|
||||
}
|
||||
openByMobile(linkAddress);
|
||||
/// #else
|
||||
if (isLocalPath(linkAddress)) {
|
||||
const linkPathname = linkAddress.split("?page")[0];
|
||||
|
@ -1471,13 +1461,7 @@ export class WYSIWYG {
|
|||
openBy(linkAddress, "app");
|
||||
}
|
||||
/// #else
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = linkAddress;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(linkAddress);
|
||||
} else {
|
||||
window.open(linkAddress);
|
||||
}
|
||||
openByMobile(linkAddress)
|
||||
/// #endif
|
||||
}
|
||||
} else {
|
||||
|
@ -1486,13 +1470,7 @@ export class WYSIWYG {
|
|||
showMessage(e);
|
||||
});
|
||||
/// #else
|
||||
if (window.siyuan.config.system.container === "ios") {
|
||||
window.location.href = linkAddress;
|
||||
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
|
||||
window.JSAndroid.openExternal(linkAddress);
|
||||
} else {
|
||||
window.open(linkAddress);
|
||||
}
|
||||
openByMobile(linkAddress)
|
||||
/// #endif
|
||||
}
|
||||
/// #endif
|
||||
|
|
|
@ -5,6 +5,7 @@ export const isMobile = () => {
|
|||
export const getRandom = (min: number, max: number) => {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
|
||||
};
|
||||
|
||||
export const getSearch = (key: string, link = window.location.search) => {
|
||||
if (link.indexOf("?") === -1) {
|
||||
return "";
|
||||
|
|
Loading…
Add table
Reference in a new issue