forked from stefnotch/starboard-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.html
375 lines (316 loc) · 8.62 KB
/
notes.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<html lang="en"><head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/hierarchy-list/dist/style.css"
/>
<style>
.phl-list {
list-style-type: none;
margin: 0;
padding: 0;
}
.phl-list > * {
border-bottom: 1px solid #dadada;
list-style-type: none;
padding: 16px;
}
.phl-list > *:last-child {
border-bottom: none;
}
.phl-list .phl-list {
border: 1px solid #dadada;
margin-top: 10px;
border-radius: 4px;
}
.phl-drag {
position: absolute;
box-shadow: 0 0 4px black;
list-style-type: none;
opacity: 0.4;
pointer-events: none;
border-radius: 4px;
}
.phl-active {
opacity: 0.5;
}
.phl-label-group {
display: flex;
align-items: center;
}
.phl-item {
padding: 16px;
}
.phl-handle {
cursor: move;
}
button.phl-handle {
position: relative;
height: 12px;
width: 16px;
margin-right: 8px;
background: linear-gradient(to right, rgb(208, 212, 218), rgb(208, 212, 218));
background-size: 100% 2px;
background-position: center;
background-repeat: no-repeat;
}
button.phl-handle::before,
button.phl-handle::after {
content: '';
position: absolute;
height: 2px;
width: 100%;
left: 0;
background: rgb(208, 212, 218);
}
button.phl-handle::before {
top: 0;
}
button.phl-handle::after {
bottom: 0;
}
.phl-expand,
.phl-collapse,
.phl-extract {
position: relative;
height: 20px;
width: 20px;
line-height: 12px;
color: #a7a7a7;
border-radius: 4px;
}
.phl-expand::after,
.phl-collapse::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
height: 8px;
width: 8px;
border: 1px solid #a7a7a7;
}
.phl-expand::after {
border: 2px solid;
transform: translate(-50%, -75%) rotate(45deg);
border-left: none;
border-top: none;
}
.phl-collapse::after {
border: 2px solid;
transform: translate(-50%, -25%) rotate(45deg);
border-right: none;
border-bottom: none;
}
.phl-extract {
margin-right: 4px;
background-image: url('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="24" height="24" viewBox="0 0 24 24"%3E%3Cg id="evaUndoFill0"%3E%3Cg id="evaUndoFill1"%3E%3Cpath id="evaUndoFill2" fill="rgb(156, 163, 175)" d="M20.22 21a1 1 0 0 1-1-.76a8.91 8.91 0 0 0-7.8-6.69v1.12a1.78 1.78 0 0 1-1.09 1.64A2 2 0 0 1 8.18 16l-5.06-4.41a1.76 1.76 0 0 1 0-2.68l5.06-4.42a2 2 0 0 1 2.18-.3a1.78 1.78 0 0 1 1.09 1.64V7A10.89 10.89 0 0 1 21.5 17.75a10.29 10.29 0 0 1-.31 2.49a1 1 0 0 1-1 .76Z"%2F%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E') !important;
background-size: contain;
}
.phl-label {
flex-grow: 1;
}
.phl-moving * {
cursor: move !important;
}
.card {
box-shadow: 0px 0px 3px 1px #ddd;
}
.phl-handle {
padding: .5rem .75rem;
border: 1px solid rgba(0, 0, 0, .07);
display: flex;
align-items: center;
}
.phl-handle:first-child {
border-radius: 0;
}
.phl-handle:last-child {
border-radius: 0;
}
.phl-handle i.fa-square {
flex-grow: 0;
cursor: pointer;
order: 1;
}
.phl-handle i.fa-check-square {
display: none;
}
.phl-handle i.fa-trash-alt {
flex-grow: 0;
cursor: pointer;
color: #dc3545;
order: 3;
}
.phl-handle i.fa-trash-alt:hover {
color: #af1e2c;
}
.phl-handle .todo-text {
flex-grow: 1;
margin: 0 10px;
order: 2;
}
.phl-handle.done i.fa-check-square {
flex-grow: 0;
cursor: pointer;
color: #28a745;
display: block;
}
phl-handle.done i.fa-square {
display: none;
}
.phl-handle.done .todo-text {
text-decoration: line-through;
color: #888;
}
[contenteditable=true] {
border: 1px dotted #999;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/hierarchy-list/dist/hierarchy-list.umd.js"></script>
</head>
<body translate="no">
<div class="container">
<div class="row">
<div class="col-lg-5 col-md-6 col-sm-8 mx-auto">
<div class="card my-5">
<h5 class="card-header bg-primary text-white">
Todo List
</h5>
<div class="card-body">
<div class="input-group mb-3">
<input type="text" id="search" class="form-control" placeholder="Search todo">
<div class="input-group-append">
<span class="input-group-text"> <i class="fas fa-search"></i> </span>
</div>
</div>
<div id="list-id">
<ul class="list-group mb-3"></ul>
</div>
<button id="clearBtn" type="button" class="btn btn-dark btn-sm">Clear All</button>
</div>
<div class="card-footer">
<form id="form">
<div class="input-group">
<input type="text" class="form-control" id="todo" placeholder="Add new todo item">
<div class="input-group-append">
<button type="submit" class="btn btn-primary"><i class="fas fa-plus"></i> Add
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script id="rendered-js">
// Define all UI variable
const todoList = document.querySelector('.list-group');
const form = document.querySelector('#form');
const todoInput = document.querySelector('#todo');
const clearBtn = document.querySelector('#clearBtn');
const search = document.querySelector('#search');
const list = HierarchyList.make('#list-id', {
// options
});
// Load all event listners
allEventListners();
// Functions of all event listners
function allEventListners() {
// Add todo event
form.addEventListener('submit', addTodo);
// Remove and complete todo event
todoList.addEventListener('click', removeTodo);
// Clear or remove all todos
clearBtn.addEventListener('click', clearTodoList);
// Search todo event
search.addEventListener('keyup', searchTodo);
}
// Add todo item function
function addTodo(e) {
if (todoInput.value !== '') {
// Create li element
const li = document.createElement('li');
// Add class
li.className = 'phl-handle2';
// Add complete and remove icon
li.innerHTML = ` <div class="phl-display">
<button class="phl-handle">
<div class="sr-only">Item Handle</div>
</button>
<div class="phl-label">`+todoInput.value+`</div>
<button class="phl-extract">
<div class="sr-only">Extract inner list</div>
</button>
<button class="phl-collapse">
<div class="sr-only">Collapse inner list</div>
</button>
<button class="phl-expand">
<div class="sr-only">Expand inner list</div>
</button>
</div><i class="far fa-square done-icon"></i>
<i class="far fa-check-square done-icon"></i>
<i class="far fa-trash-alt"></i>`;
// Create span element
const span = document.createElement('span');
// Add class
// span.className = 'todo-text';
// span.contentEditable="true";
// Create text node and append to span
// span.appendChild(document.createTextNode(todoInput.value));
// Append span to li
li.appendChild(span);
// Append li to ul (todoList)
// todoList.appendChild(li);
list.addItem(li);
// Clear input
todoInput.value = '';
} else {
alert('Please add todo');
}
e.preventDefault();
}
// Remove and complete todo item function
function removeTodo(e) {
// Remove todo
if (e.target.classList.contains('fa-trash-alt')) {
let items = e.target.parentElement.parentElement.getElementsByTagName("li").length;
if (confirm('Are you sure')) {
if(items < 2){
e.target.parentElement.parentElement.remove();
} else {
e.target.parentElement.remove();
}
}
}
// Complete todo
if (e.target.classList.contains('todo-text')) {
e.target.parentElement.classList.toggle('done');
}
if (e.target.classList.contains('done-icon')) {
e.target.parentElement.classList.toggle('done');
}
}
// Clear or remove all todos function
function clearTodoList() {
todoList.innerHTML = '';
}
// Search todo function
function searchTodo(e) {
const text = e.target.value.toLowerCase();
const allItem = document.querySelectorAll('.phl-handle');
for (let task of allItem) {
const item = task.textContent;
if (item.toLowerCase().indexOf(text) != -1) {
task.style.display = 'block';
} else {
task.style.display = 'none';
}
};
}
//# sourceURL=pen.js
</script>
</body></html>