Skip to content

Commit

Permalink
bug(mindmap): fix image removal (#756)
Browse files Browse the repository at this point in the history
fixes #755
  • Loading branch information
Idrinth authored Apr 9, 2024
1 parent 0cb0069 commit 5b854f8
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ translation:
- changed-files:
- any-glob-to-any-file:
- '*/language/*.yml'
research:
mindmap:
- changed-files:
- any-glob-to-any-file:
- mindmap/**/*
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
/mindmap/node_modules
/mindmap/dist
/mindmap/cache
/mindmap/src/*.js

# Editor directories and files
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions mindmap/data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ children:
- text: Documentation Website
image: website-screenshot.png
url: https://idrinth-api-ben.ch
- text: Mindmap
- text: Logo
image: iab.svg
- text: work in progress
children:
- text: Logo
image: new-logo.png
- text: History Website
- text: requirements
children:
- text: dark mode
Expand Down
8 changes: 5 additions & 3 deletions mindmap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"version": "1.0.0",
"description": "",
"scripts": {
"build": "node tools/data.js",
"build": "npm run tsc && node tools/data.js",
"serve": "http-server ./dist -c-1 --proxy http://localhost:8080? --silent",
"start": "npm run build && npm run serve",
"spellcheck": "spellchecker",
"lint": "eslint . --ext .js,.ts,.cjs,.json,.tsx --report-unused-disable-directives --max-warnings 0",
"lint-fix": "eslint . --ext .js,.ts,.cjs,.json,.tsx --fix",
"lint-styles": "stylelint src/index.css",
"lint-css": "ilcd",
"knip": "knip"
"knip": "knip",
"tsc": "tsc -p tsconfig.json"
},
"repository": {
"type": "git",
Expand All @@ -34,7 +35,8 @@
"spellchecker-cli": "^6.2.0",
"@idrinth/duplicate-style-check": "^1.1.0",
"stylelint": "^16.2.1",
"stylelint-config-standard": "^36.0.0"
"stylelint-config-standard": "^36.0.0",
"typescript": "^5.4.4"
},
"engines": {
"node": ">=20"
Expand Down
25 changes: 0 additions & 25 deletions mindmap/src/show.js

This file was deleted.

55 changes: 55 additions & 0 deletions mindmap/src/show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const FIRST = 0;
const body = document.body;
const remove = (
element: HTMLAnchorElement|HTMLSpanElement,
) => body.removeChild(element,);
const add = (
element: HTMLAnchorElement|HTMLSpanElement,
) => body.appendChild(element,);
const set = (
element: HTMLAnchorElement|HTMLSpanElement,
key: string,
value: string,
) => element.setAttribute(key, value,);
const get = (
element: HTMLAnchorElement|HTMLSpanElement,
key: string,
) => element.getAttribute(key,);
const has = (
element: HTMLAnchorElement|HTMLSpanElement,
key: string,
) => element.hasAttribute(key,);
const create = (type: 'a'|'img',) => document.createElement(type,);
const removeModals = () => {
const modals = document.getElementsByClassName('modal',);
while (modals.item(FIRST,)) {
remove(modals.item(FIRST,) as HTMLSpanElement|HTMLAnchorElement,);
}
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
window.show = (element: HTMLAnchorElement|HTMLSpanElement,) => {
if (! element || ! has(element, 'data-image',)) {
return;
}
removeModals();
const img = create('img',);
set(img, 'src', get(element, 'data-image',),);
if (has(element, 'title',)) {
set(img, 'title', get(element, 'title',),);
}
if (has(element, 'href',)) {
const a = create('a',);
set(a, 'href', get(element, 'href',),);
set(a, 'target', '_blank',);
set(a, 'rel', 'noreferrer',);
set(a, 'class', 'modal',);
a.appendChild(img,);
img.onmouseleave = () => remove(a,);
add(a,);
return;
}
img.onmouseleave = () => remove(img,);
set(img, 'class', 'modal',);
body.append(img,);
};
2 changes: 1 addition & 1 deletion mindmap/tools/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ html = html.replace(
'</head>',
'<link rel=icon type=image/svg+xml href=iab.svg />' +
`<link rel=stylesheet type=text/css href=${ ch }.min.css />` +
`<script src=${ jsh }.min.js ></script>` +
`<script type=module src=${ jsh }.min.js ></script>` +
'</head>',
);
html = html
Expand Down
9 changes: 9 additions & 0 deletions mindmap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "nodenext"
},
"include": [
"src/**/*.ts"
]
}

0 comments on commit 5b854f8

Please sign in to comment.