diff options
Diffstat (limited to 'src/MenuItem.mjs')
-rw-r--r-- | src/MenuItem.mjs | 39 |
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 @@ | |||
1 | import { createGeoLink } from './dumbymap' | ||
2 | |||
3 | export 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 | } | ||
1 | export class Suggestion { | 37 | export 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 = () => { |