-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
81 lines (74 loc) · 2.6 KB
/
renderer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const columnWidth = 400
const marginLeft = 150
function removeColumn(e) {
const elemOfColumn = e.currentTarget.parentNode
console.log(elemOfColumn)
console.log('removeColumn')
const indexOfColumn = getIndexOfColumn(elemOfColumn)
console.log(indexOfColumn)
window.snsdeck.openRemoveColumn(indexOfColumn)
elemOfColumn.remove()
// Redraw column
const columns = document.querySelectorAll(".column")
for (let i = indexOfColumn; i < columns.length; i++) {
const div = columns[i]
const left = div.style.left.slice(0, -2) - columnWidth
console.log(left)
div.style.left = `${left}px`
}
}
function getIndexOfColumn(node) {
const columns = document.querySelectorAll('.column')
for (let i = 0; i < columns.length; i++) {
if (node === columns[i]) {
return i
}
}
return -1
}
window.snsdeck.onScroll((_event, deltaX) => {
const columns = document.querySelectorAll(".column")
for (const column of columns) {
const newLeft = column.style.left.slice(0, -2) - deltaX
column.style.left = `${newLeft}px`
}
console.log('from BrowserView', deltaX)
})
window.snsdeck.onLoadColumns((_event, numOfColumn) => {
console.log('onLoadColumns', numOfColumn)
const controller = document.getElementById('controller')
for (let i = 0; i < numOfColumn; i++) {
const div = document.createElement('div')
div.className = 'column'
div.style = `top: 0px; left:${columnWidth * i + marginLeft}px;`
const btn = document.createElement('button')
btn.className = "close"
btn.innerText = 'X'
div.appendChild(btn)
controller.appendChild(div)
}
const buttons = document.querySelectorAll(".close")
for (const btn of buttons) {
btn.addEventListener('click', removeColumn)
}
})
window.snsdeck.onAddColumn((_event) => {
const columns = document.querySelectorAll(".column")
const lastColumn = columns[columns.length-1]
const controller = document.getElementById('controller')
const div = document.createElement('div')
div.className = 'column'
let left = ''
if (columns.length > 0) {
left = parseInt(lastColumn.style.left.slice(0, -2)) + columnWidth
} else {
left = marginLeft
}
div.style = `top: 0px; left:${left}px;`
const btn = document.createElement('button')
btn.className = "close"
btn.innerText = 'X'
btn.addEventListener('click', removeColumn)
div.appendChild(btn)
controller.appendChild(div)
})