forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiconLinks.ts
More file actions
50 lines (49 loc) · 1.67 KB
/
Copy pathiconLinks.ts
File metadata and controls
50 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { NamedNode } from 'rdflib'
import { originalIconBase } from '../../iconBase'
/**
* Creates an anchor tag for a NamedNode
*
* Takes a NamedNode and creates an anchor tag for it
*
* @param dom The HTML Document object aka Document Object Model
* @param subject NamedNode the anchor tag is created for
* @param iconURI? Optional if you have your own icon link
*
* @returns The anchor tag for the subject
*
*/
// eslint-disable-next-line complexity
export function linkIcon (dom: HTMLDocument, subject: NamedNode, iconURI?: string): HTMLElement {
const anchor = dom.createElement('a')
anchor.setAttribute('href', subject.uri)
if (subject.uri.startsWith('http')) {
// If diff web page
anchor.setAttribute('target', '_blank') // open in a new tab or window
} // as mailboxes and mail messages do not need new browser window
const img = anchor.appendChild(dom.createElement('img'))
img.setAttribute(
'src',
iconURI || originalIconBase + 'go-to-this.png'
)
img.setAttribute('style', 'margin: 0.3em;')
return anchor
}
/**
* Creates a Link for a URI
*
* Takes a div element for a link and attaches the provided linkIcon
*
* @param dom The HTML Document object aka Document Object Model
* @param linkDiv the created link will be appended to this
* @param obj NamedNode the link needs to be created for
*
* @returns The HTML widget created
*
*/
// eslint-disable-next-line complexity
export const createLinkForURI = (dom: HTMLDocument, linkDiv: HTMLDivElement, obj: NamedNode) => {
const iconLink = linkIcon(dom, obj)
const anchor = linkDiv.appendChild(iconLink)
anchor.classList.add('HoverControlHide')
linkDiv.appendChild(dom.createElement('br'))
}