mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 04:50:59 +08:00
Improve the class name of showTooltip()
(#12746)
This commit is contained in:
parent
bc53babb85
commit
1139ffddc0
@ -25,7 +25,8 @@ export const initBlockPopover = (app: App) => {
|
|||||||
hasClosestByClassName(event.target, "av__calc--ashow") ||
|
hasClosestByClassName(event.target, "av__calc--ashow") ||
|
||||||
hasClosestByClassName(event.target, "av__cell");
|
hasClosestByClassName(event.target, "av__cell");
|
||||||
if (aElement) {
|
if (aElement) {
|
||||||
let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content");
|
let tooltipClass = "";
|
||||||
|
let tip = aElement.getAttribute("aria-label");
|
||||||
if (aElement.classList.contains("av__cell")) {
|
if (aElement.classList.contains("av__cell")) {
|
||||||
if (aElement.classList.contains("av__cell--header")) {
|
if (aElement.classList.contains("av__cell--header")) {
|
||||||
const textElement = aElement.querySelector(".av__celltext");
|
const textElement = aElement.querySelector(".av__celltext");
|
||||||
@ -51,11 +52,18 @@ export const initBlockPopover = (app: App) => {
|
|||||||
} else if (aElement.classList.contains("av__calc--ashow") && aElement.clientWidth + 2 < aElement.scrollWidth) {
|
} else if (aElement.classList.contains("av__calc--ashow") && aElement.clientWidth + 2 < aElement.scrollWidth) {
|
||||||
tip = aElement.lastChild.textContent + " " + aElement.firstElementChild.textContent;
|
tip = aElement.lastChild.textContent + " " + aElement.firstElementChild.textContent;
|
||||||
}
|
}
|
||||||
|
if (!tip) {
|
||||||
|
tip = aElement.getAttribute("data-inline-memo-content");
|
||||||
|
if (tip) {
|
||||||
|
tooltipClass = "memo"; // 为行级备注添加 class https://github.com/siyuan-note/siyuan/issues/6161
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!tip) {
|
if (!tip) {
|
||||||
const href = aElement.getAttribute("data-href") || "";
|
const href = aElement.getAttribute("data-href") || "";
|
||||||
// 链接地址强制换行 https://github.com/siyuan-note/siyuan/issues/11539
|
// 链接地址强制换行 https://github.com/siyuan-note/siyuan/issues/11539
|
||||||
if (href) {
|
if (href) {
|
||||||
tip = `<span style="word-break: break-all">${href.substring(0, Constants.SIZE_TITLE)}</span>`;
|
tip = `<span style="word-break: break-all">${href.substring(0, Constants.SIZE_TITLE)}</span>`;
|
||||||
|
tooltipClass = "href"; // 为超链接添加 class https://github.com/siyuan-note/siyuan/issues/11440#issuecomment-2119080691
|
||||||
}
|
}
|
||||||
const title = aElement.getAttribute("data-title");
|
const title = aElement.getAttribute("data-title");
|
||||||
if (tip && isLocalPath(href) && !aElement.classList.contains("b3-tooltips")) {
|
if (tip && isLocalPath(href) && !aElement.classList.contains("b3-tooltips")) {
|
||||||
@ -78,10 +86,10 @@ export const initBlockPopover = (app: App) => {
|
|||||||
if (tip && !aElement.classList.contains("b3-tooltips")) {
|
if (tip && !aElement.classList.contains("b3-tooltips")) {
|
||||||
// https://github.com/siyuan-note/siyuan/issues/11294
|
// https://github.com/siyuan-note/siyuan/issues/11294
|
||||||
try {
|
try {
|
||||||
showTooltip(decodeURIComponent(tip), aElement);
|
showTooltip(decodeURIComponent(tip), aElement, tooltipClass);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// https://ld246.com/article/1718235737991
|
// https://ld246.com/article/1718235737991
|
||||||
showTooltip(tip, aElement);
|
showTooltip(tip, aElement, tooltipClass);
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {isMobile} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
|
|
||||||
export const showTooltip = (message: string, target: Element, error = false) => {
|
export const showTooltip = (message: string, target: Element, tooltipClass?: string) => {
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -16,15 +16,16 @@ export const showTooltip = (message: string, target: Element, error = false) =>
|
|||||||
} else {
|
} else {
|
||||||
messageElement.innerHTML = message;
|
messageElement.innerHTML = message;
|
||||||
}
|
}
|
||||||
if (error) {
|
|
||||||
messageElement.classList.add("tooltip--error");
|
if (tooltipClass) {
|
||||||
|
messageElement.classList.add("tooltip--" + tooltipClass);
|
||||||
} else {
|
} else {
|
||||||
messageElement.classList.remove("tooltip--error");
|
const classesToRemove = Array.from(messageElement.classList).filter(className =>
|
||||||
}
|
className.startsWith("tooltip--")
|
||||||
if (target.getAttribute("data-inline-memo-content")) {
|
);
|
||||||
messageElement.classList.add("tooltip--memo"); // 为行级备注添加 class https://github.com/siyuan-note/siyuan/issues/6161
|
classesToRemove.forEach(className => {
|
||||||
} else {
|
messageElement.classList.remove(className);
|
||||||
messageElement.classList.remove("tooltip--memo");
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let left = targetRect.left;
|
let left = targetRect.left;
|
||||||
|
@ -16,7 +16,7 @@ import {getAllEditor} from "../layout/getAll";
|
|||||||
export const validateName = (name: string, targetElement?: HTMLElement) => {
|
export const validateName = (name: string, targetElement?: HTMLElement) => {
|
||||||
if (/\r\n|\r|\n|\u2028|\u2029|\t|\//.test(name)) {
|
if (/\r\n|\r|\n|\u2028|\u2029|\t|\//.test(name)) {
|
||||||
if (targetElement) {
|
if (targetElement) {
|
||||||
showTooltip(window.siyuan.languages.fileNameRule, targetElement, true);
|
showTooltip(window.siyuan.languages.fileNameRule, targetElement, "error");
|
||||||
} else {
|
} else {
|
||||||
showMessage(window.siyuan.languages.fileNameRule);
|
showMessage(window.siyuan.languages.fileNameRule);
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ export const validateName = (name: string, targetElement?: HTMLElement) => {
|
|||||||
}
|
}
|
||||||
if (name.length > Constants.SIZE_TITLE) {
|
if (name.length > Constants.SIZE_TITLE) {
|
||||||
if (targetElement) {
|
if (targetElement) {
|
||||||
showTooltip(window.siyuan.languages["_kernel"]["106"], targetElement, true);
|
showTooltip(window.siyuan.languages["_kernel"]["106"], targetElement, "error");
|
||||||
} else {
|
} else {
|
||||||
showMessage(window.siyuan.languages["_kernel"]["106"]);
|
showMessage(window.siyuan.languages["_kernel"]["106"]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user