diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-21 10:52:23 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-21 11:01:03 +0800 |
| commit | e23a85dd4039ab43b6f5893a3615639ec4feff7d (patch) | |
| tree | 5d3efca0c022a2dc4859d3f32a2af9a019aa060c /src | |
| parent | 5c0a292a1518976d653d9a917669a2edc0c685eb (diff) | |
style: definition of link methods
Diffstat (limited to 'src')
| -rw-r--r-- | src/dumbymap.mjs | 20 |
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' | |||
| 6 | import LeaderLine from 'leader-line' | 6 | import LeaderLine from 'leader-line' |
| 7 | import { renderWith, parseConfigsFromYaml } from 'mapclay' | 7 | import { renderWith, parseConfigsFromYaml } from 'mapclay' |
| 8 | import { onRemove, animateRectTransition, throttle } from './utils' | 8 | import { onRemove, animateRectTransition, throttle } from './utils' |
| 9 | |||
| 10 | // FUNCTION: Get DocLinks from special anchor element {{{ | ||
| 11 | import { OverlayLayout } from './OverlayLayout' | 9 | import { OverlayLayout } from './OverlayLayout' |
| 12 | 10 | ||
| 13 | const docLinkSelector = 'a[href^="#"][title^="=>"]' | 11 | const docLinkSelector = 'a[href^="#"][title^="=>"]' |
| 12 | const geoLinkSelector = 'a[href^="geo:"]' | ||
| 14 | 13 | ||
| 15 | class Layout { | 14 | class 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 | */ | ||
| 29 | export const createDocLinks = (container) => Array.from(container.querySelectorAll(docLinkSelector)) | 36 | export 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 | /** |
| 63 | const 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 | */ | ||
| 64 | export const createGeoLinks = (container, callback) => Array.from(container.querySelectorAll(geoLinkSelector)) | 75 | export 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 | // }}} |
| 85 | export const markdown2HTML = (container, mdContent) => { | 95 | export const markdown2HTML = (container, mdContent) => { |
| 86 | // Render: Markdown -> HTML {{{ | 96 | // Render: Markdown -> HTML {{{ |