-
Notifications
You must be signed in to change notification settings - Fork 0
/
applyLayoutNode.js
57 lines (49 loc) · 1.28 KB
/
applyLayoutNode.js
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
//#!py
/**
* @include updateLayoutStyle setNodeStyle
*/
function applyLayoutNode(node = document)
Array.from(node.querySelectorAll('[layout]')).forEach((node)=> {
const type = node.getAttribute('layout')
setLayout.call(node, type)
})
function setLayout(type)
const node = this
node.setAttribute('layout', type)
if type
const nodes = Array.from(node.childNodes).filter(node=> node.nodeType === 1)
const styles = nodes.map(node=> {
node.setSize = setSize
const size = node.getAttribute('size')
return {
itemSize: size
}
})
Object.assign(node, {
setLayout,
updateLayout,
layoutData: {
type,
nodes,
styles,
},
})
node.updateLayout()
function toggleSize()
function setSize(size)
const node = this
this.setAttribute('size', size)
const {nodes, styles} = node.parentNode.layoutData
styles[nodes.indexOf(node)].itemSize = size
node.parentNode.updateLayout()
function updateLayout()
const node = this
const {nodes} = node.layoutData
node.layoutData.style = node.getBoundingClientRect()
updateLayoutStyle(node.layoutData).forEach((style, i)=> {
const node = nodes[i]
setNodeStyle(node, style)
node.dispatchEvent(new Event('resize'))
if node.updateLayout
node.updateLayout()
})