forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgetHelpers.ts
More file actions
64 lines (57 loc) · 1.9 KB
/
widgetHelpers.ts
File metadata and controls
64 lines (57 loc) · 1.9 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { style } from '../style'
/**
* Wraps a Div in a TR/RD
*
* Takes a div and wraps it in a TR/TD to be backwards compatible to the
* table structure of mashlib
*
* @param dom The HTML Document object aka Document Object Model
* @param div the created widget will be appended to this
* @param obj not sure what this is used for exactly
*
* @returns The HTML widget created
*
* @internal exporting this only for unit tests
*/
export const wrapDivInATR = (dom: HTMLDocument, div: HTMLDivElement, obj: any) => {
const tr = dom.createElement('tr')
const td = tr.appendChild(dom.createElement('td'))
td.appendChild(div)
;(tr as any).subject = obj
return tr
}
/**
* Adds a click listener to a div
*
* Adds a given function as a click listener on the given div
*
* @param dom The HTML Document object aka Document Object Model
* @param onClickFunction the click function to add to the click listener
*
* @returns The HTML widget created
*
* @internal exporting this only for unit tests
*/
export const addClickListenerToElement = (div: HTMLDivElement, onClickFunction: () => void) => {
div.addEventListener('click', onClickFunction)
}
/**
* Wraps a Div in a TR/RD
*
* Takes a div and wraps it in a TR/TD to be backwards compatible to the
* table structure of mashlib
*
* @param dom The HTML Document object aka Document Object Model
* @param div the created widget will be appended to this
* @param obj not sure what this is used for exactly
*
* @returns The HTML widget created
*
* @internal exporting this only for unit tests
*/
export const createImageDiv = (dom: HTMLDocument, div: HTMLDivElement, image: HTMLImageElement | HTMLObjectElement) => {
const imageDiv = div.appendChild(dom.createElement('div'))
imageDiv.setAttribute('style', style.imageDivStyle)
imageDiv.appendChild(image)
image.setAttribute('draggable', 'false') // Stop the image being dragged instead - just the TR
}