aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/MenuItem.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-25 14:55:19 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-26 19:40:48 +0800
commit22be38a505183a5615b2934571e4c95b55c07583 (patch)
tree82a85ba56ed9a0e350aa84ca8e0321c577eaad3d /src/MenuItem.mjs
parentef12755cfa819b891998d1af756e6a1b0c16ee2c (diff)
feat: add MenuItem for GeoLink
Diffstat (limited to 'src/MenuItem.mjs')
-rw-r--r--src/MenuItem.mjs39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs
index 50afdb5..1b04d1c 100644
--- a/src/MenuItem.mjs
+++ b/src/MenuItem.mjs
@@ -1,3 +1,39 @@
1import { createGeoLink } from './dumbymap'
2
3export class GeoLink {
4
5 constructor({ range }) {
6 this.range = range
7 }
8
9 createElement = () => {
10 const element = document.createElement('div')
11 element.className = 'menu-item-add-geolink'
12 element.innerText = "Add GeoLink"
13 element.onclick = this.addGeoLinkbyRange
14
15 return element
16 }
17
18 addGeoLinkbyRange = () => {
19 const range = this.range
20 const content = range.toString()
21 // FIXME Apply geolink only on matching sub-range
22 const match = content.match(/(^\D*[\d.]+)\D+([\d.]+)\D*$/)
23 if (!match) return false
24
25 const [x, y] = match.slice(1)
26 const anchor = document.createElement('a')
27 anchor.textContent = content
28 // FIXME apply WGS84
29 anchor.href = `geo:${y},${x}?xy=${x},${y}`
30
31 if (createGeoLink(anchor)) {
32 range.deleteContents()
33 range.insertNode(anchor)
34 }
35 }
36}
1export class Suggestion { 37export class Suggestion {
2 constructor({ text, replace }) { 38 constructor({ text, replace }) {
3 this.text = text 39 this.text = text
@@ -13,7 +49,8 @@ export class Suggestion {
13 } 49 }
14 option.classList.add('container__suggestion'); 50 option.classList.add('container__suggestion');
15 option.onmouseover = () => { 51 option.onmouseover = () => {
16 Array.from(menu.children).forEach(s => s.classList.remove('focus')) 52 Array.from(option.parentElement?.children ?? [])
53 .forEach(s => s.classList.remove('focus'))
17 option.classList.add('focus') 54 option.classList.add('focus')
18 } 55 }
19 option.onmouseout = () => { 56 option.onmouseout = () => {