process anchor links (href.startsWith 'anchor')
This commit is contained in:
parent
ea1a96acd3
commit
8b0e1c0fa8
1 changed files with 26 additions and 6 deletions
|
@ -177,15 +177,26 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links
|
|
||||||
console.debug("[SVG] Processing hyperlinks.");
|
|
||||||
processHyperlinks(svg);
|
|
||||||
|
|
||||||
// Anchors
|
// Anchors
|
||||||
console.debug("[SVG] Processing anchors.");
|
console.debug("[SVG] Processing anchors.");
|
||||||
anchors.value = processAnchors(svg);
|
anchors.value = processAnchors(svg);
|
||||||
console.info(`[SVG] Found ${anchors.value.length} anchors.`);
|
console.info(`[SVG] Found ${anchors.value.length} anchors.`);
|
||||||
|
|
||||||
|
// Links
|
||||||
|
console.debug("[SVG] Processing hyperlinks.");
|
||||||
|
const {anchor, hyper} = processHyperlinks(svg);
|
||||||
|
console.info(`[SVG] Found ${anchor.length} anchor links and ${hyper.length} hyperlinks.`);
|
||||||
|
anchor.forEach(([anchorId, element]) => {
|
||||||
|
const anchor = anchors.value.find((a) => a.id == anchorId);
|
||||||
|
if (!anchor) {
|
||||||
|
console.error(`[SVG] Could not find anchor #${anchorId}!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
element.addEventListener("click", () => {
|
||||||
|
panToElement(anchor, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Audio areas
|
// Audio areas
|
||||||
console.debug("[SVG] Processing audio areas.");
|
console.debug("[SVG] Processing audio areas.");
|
||||||
audioAreas.value = processAudio(svg);
|
audioAreas.value = processAudio(svg);
|
||||||
|
@ -369,10 +380,19 @@ function processAudio(svg: XMLDocument): AudioAreaDef[] {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function processHyperlinks(svg: XMLDocument) {
|
function processHyperlinks(svg: XMLDocument): { anchor: [string, SVGAElement][], hyper: SVGAElement[] } {
|
||||||
|
const anchor: [string, SVGAElement][] = [];
|
||||||
|
const hyper: SVGAElement[] = [];
|
||||||
Array.from(svg.getElementsByTagName("a")).forEach((el) => {
|
Array.from(svg.getElementsByTagName("a")).forEach((el) => {
|
||||||
el.setAttribute("target", "_blank");
|
if (el.getAttribute("xlink:href")?.startsWith("anchor")) {
|
||||||
|
anchor.push([el.getAttribute("xlink:href") as string, el as unknown as SVGAElement]);
|
||||||
|
el.setAttribute("xlink:href", "#");
|
||||||
|
} else {
|
||||||
|
el.setAttribute("target", "_blank");
|
||||||
|
hyper.push(el as unknown as SVGAElement);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
return {anchor, hyper};
|
||||||
}
|
}
|
||||||
|
|
||||||
function processStart(svg: XMLDocument): SVGRectElement | null {
|
function processStart(svg: XMLDocument): SVGRectElement | null {
|
||||||
|
|
Loading…
Reference in a new issue