aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dumbymap.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-21 10:52:23 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-21 11:01:03 +0800
commite23a85dd4039ab43b6f5893a3615639ec4feff7d (patch)
tree5d3efca0c022a2dc4859d3f32a2af9a019aa060c /src/dumbymap.mjs
parent5c0a292a1518976d653d9a917669a2edc0c685eb (diff)
style: definition of link methods
Diffstat (limited to 'src/dumbymap.mjs')
-rw-r--r--src/dumbymap.mjs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index d2492db..dd96437 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -6,11 +6,10 @@ import MarkdownItTocDoneRight from 'markdown-it-toc-done-right'
6import LeaderLine from 'leader-line' 6import LeaderLine from 'leader-line'
7import { renderWith, parseConfigsFromYaml } from 'mapclay' 7import { renderWith, parseConfigsFromYaml } from 'mapclay'
8import { onRemove, animateRectTransition, throttle } from './utils' 8import { onRemove, animateRectTransition, throttle } from './utils'
9
10// FUNCTION: Get DocLinks from special anchor element {{{
11import { OverlayLayout } from './OverlayLayout' 9import { OverlayLayout } from './OverlayLayout'
12 10
13const docLinkSelector = 'a[href^="#"][title^="=>"]' 11const docLinkSelector = 'a[href^="#"][title^="=>"]'
12const geoLinkSelector = 'a[href^="geo:"]'
14 13
15class Layout { 14class Layout {
16 constructor({ name, enterHandler = null, leaveHandler = null }) { 15 constructor({ name, enterHandler = null, leaveHandler = null }) {
@@ -26,6 +25,14 @@ const layouts = [
26 new Layout({ name: "side" }), 25 new Layout({ name: "side" }),
27 new OverlayLayout(), 26 new OverlayLayout(),
28] 27]
28
29// FUNCTION: Get DocLinks from special anchor element {{{
30/**
31 * CreateDocLinks.
32 *
33 * @param {HTMLElement} Elements contains anchor elements for doclinks
34 * @returns {Array} List of doclinks just created
35 */
29export const createDocLinks = (container) => Array.from(container.querySelectorAll(docLinkSelector)) 36export const createDocLinks = (container) => Array.from(container.querySelectorAll(docLinkSelector))
30 .map(link => { 37 .map(link => {
31 link.classList.add('with-leader-line', 'doclink') 38 link.classList.add('with-leader-line', 'doclink')
@@ -59,8 +66,12 @@ export const createDocLinks = (container) => Array.from(container.querySelectorA
59 }) 66 })
60// }}} 67// }}}
61// FUNCTION: Get GeoLinks from special anchor element {{{ 68// FUNCTION: Get GeoLinks from special anchor element {{{
62// Links points to map by geo schema and id 69/**
63const geoLinkSelector = 'a[href^="geo:"]' 70 * Create geolinks, which points to map by geo schema and id
71 *
72 * @param {HTMLElement} Elements contains anchor elements for doclinks
73 * @returns {Array} List of doclinks just created
74 */
64export const createGeoLinks = (container, callback) => Array.from(container.querySelectorAll(geoLinkSelector)) 75export const createGeoLinks = (container, callback) => Array.from(container.querySelectorAll(geoLinkSelector))
65 .filter(link => { 76 .filter(link => {
66 const url = new URL(link.href) 77 const url = new URL(link.href)
@@ -80,7 +91,6 @@ export const createGeoLinks = (container, callback) => Array.from(container.quer
80 91
81 return true 92 return true
82 }) 93 })
83
84// }}} 94// }}}
85export const markdown2HTML = (container, mdContent) => { 95export const markdown2HTML = (container, mdContent) => {
86 // Render: Markdown -> HTML {{{ 96 // Render: Markdown -> HTML {{{