-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
226 lines (225 loc) · 8.22 KB
/
index.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS Grid Creator</title>
</head>
<body>
<h1>CSS Grid Creator <iframe class="gh-button" src="https://ghbtns.com/github-btn.html?user=Weedshaker&repo=cssGridLayout&type=star&count=true&size=large" scrolling="0" width="160px" height="30px" frameborder="0"></iframe></h1>
<hr>
<!-- add cells -->
<button onclick="
this.dispatchEvent(new CustomEvent('addCell', {
bubbles: true,
cancelable: true,
composed: true
}))
">add cell</button>
<!-- remove cells -->
<script>
const button = document.createElement('button')
button.textContent = 'delete cell on click'
const checkbox = document.createElement('input')
checkbox.setAttribute('type', 'checkbox')
button.appendChild(checkbox)
button.addEventListener('click', event => {
if (event.composedPath()[0] === button) checkbox.click()
})
document.body.appendChild(button)
document.body.addEventListener('click', event => {
if (checkbox.checked && event.composedPath().includes(document.body.querySelector('o-interactive-grid'))) {
document.body.dispatchEvent(new CustomEvent('removeCell', {
detail: {
cell: event.composedPath()[0]
},
bubbles: true,
cancelable: true,
composed: true
}))
}
})
</script>
<br><code>Note: If the drag starts to get impracise, reload!</code>
<hr>
<details>
<summary>html with inline style</summary>
<textarea id="save-html" style="width: 100%; height: fit-content; min-height: min(20vh, 200px);"></textarea>
</details>
<details>
<summary>html with css</summary>
<textarea id="save-html-css" style="width: 100%; height: fit-content; min-height: min(20vh, 200px);"></textarea>
</details>
<hr>
<!-- save/load stuff -->
<script>
const save = event => {
// save
if (event) (new Promise(resolve => document.body.dispatchEvent(new CustomEvent('getInnerHTML', {
detail: {
resolve
},
bubbles: true,
cancelable: true,
composed: true
})))).then(html => localStorage.setItem('html', html));
// set html
(new Promise(resolve => document.body.dispatchEvent(new CustomEvent('getOuterHTML', {
detail: {
resolve
},
bubbles: true,
cancelable: true,
composed: true
})))).then(html => (document.querySelector('#save-html').textContent = html));
// set html with css
(new Promise(resolve => document.body.dispatchEvent(new CustomEvent('getHTMLCSS', {
detail: {
resolve
},
bubbles: true,
cancelable: true,
composed: true
})))).then(html => (document.querySelector('#save-html-css').textContent = html));
}
document.body.addEventListener('dragend', save)
document.body.addEventListener('resizeend', save)
document.body.addEventListener('doubletap', save)
document.body.addEventListener('add-cell', save)
document.body.addEventListener('remove-cell', save)
const div = document.createElement('div')
div.innerHTML = /* html */`
<o-interactive-grid is-interactive min-height=50>
${localStorage.getItem('html') && self.confirm('Do you wanna load the last state?')
? localStorage.getItem('html')
: /* html */`
<div style="grid-row-start: 1; grid-column-start: 1;"></div>
<div style="grid-row-start: 2; grid-column-start: 2;"></div>
<div style="grid-row-start: 3; grid-column-start: 3;"></div>
<div style="grid-row-start: 4; grid-column-start: 4;"></div>
<div style="grid-row-start: 5; grid-column-start: 5;"></div>
<!--<div style="grid-row-start: 6; grid-column-start: 6;"></div>
<div style="grid-row-start: 7; grid-column-start: 7;"></div>
<div style="grid-row-start: 8; grid-column-start: 8;"></div>
<div style="grid-row-start: 9; grid-column-start: 9;"></div>
<div style="grid-row-start: 10; grid-column-start: 10;"></div>
<div style="grid-row-start: 11; grid-column-start: 11;"></div>
<div style="grid-row-start: 12; grid-column-start: 12;"></div>-->
`
}
</o-interactive-grid>
`
document.body.appendChild(div.children[0])
setTimeout(save, 1000)
</script>
<script rel="modulepreload" type="module">
import('./JavaScript/Components/InteractiveGrid.js').then(module => {
if (!customElements.get('o-interactive-grid')) customElements.define('o-interactive-grid', module.default)
})
// log all interactive events out in console
document.body.addEventListener('dragstart', event => console.log('dragstart', event.detail))
document.body.addEventListener('dragmove', event => console.log('dragmove', event.detail))
document.body.addEventListener('dragend', event => console.log('dragend', event.detail))
document.body.addEventListener('resizestart', event => console.log('resizestart', event.detail))
document.body.addEventListener('resizemove', event => console.log('resizemove', event.detail))
document.body.addEventListener('resizeend', event => console.log('resizeend', event.detail))
document.body.addEventListener('doubletap', event => console.log('doubletap', event.detail))
document.body.addEventListener('add-cell', event => console.log('add-cell', event.detail))
document.body.addEventListener('remove-cell', event => console.log('remove-cell', event.detail))
</script>
<hr>
<!-- div stuff -->
<details>
<summary>misc tests</summary>
<button onclick="
this.dispatchEvent(new CustomEvent('addCell', {
detail: {
cell: document.createElement('span'),
style: 'grid-area: 8 / 9 / span 1 / span 3; transform-origin: left top;'
},
bubbles: true,
cancelable: true,
composed: true
}))
">add cell at row 8 & col 9</button>
<script>
const particularCell = document.createElement('p')
particularCell.textContent = 'particular cell'
</script>
<button onclick="
this.dispatchEvent(new CustomEvent('addCell', {
detail: {
cell: particularCell
},
bubbles: true,
cancelable: true,
composed: true
}))
">add particular cell</button>
<button onclick="
this.dispatchEvent(new CustomEvent('removeCell', {
detail: {
cell: particularCell
},
bubbles: true,
cancelable: true,
composed: true
}))
">remove particular cell</button>
<!-- remove cells -->
<button onclick="
this.dispatchEvent(new CustomEvent('removeCell', {
bubbles: true,
cancelable: true,
composed: true
}))
">remove last cell</button>
<button onclick="
this.dispatchEvent(new CustomEvent('removeCell', {
detail: {
position: self.prompt('which cell pick a number from 1 to ...')
},
bubbles: true,
cancelable: true,
composed: true
}))
">remove cell at pos</button>
<!-- get html cells -->
<script>
const htmlResolve = () => {
let resolveFunc
new Promise(resolve => (resolveFunc = resolve)).then(html => console.log('grid html: ', html))
return resolveFunc
}
</script>
<button onclick="
this.dispatchEvent(new CustomEvent('getInnerHTML', {
detail: {
resolve: htmlResolve()
},
bubbles: true,
cancelable: true,
composed: true
}))
">print html to console</button>
<br>
<code>Note: It is still buggy to toggle Interactive...</code><br>
<!-- add set/remove interactive -->
<button onclick="
this.dispatchEvent(new CustomEvent('setInteractive', {
bubbles: true,
cancelable: true,
composed: true
}))
">set Interactive</button>
<button onclick="
this.dispatchEvent(new CustomEvent('removeInteractive', {
bubbles: true,
cancelable: true,
composed: true
}))
">remove Interactive</button>
</details>
</body>
</html>