-
Notifications
You must be signed in to change notification settings - Fork 29
/
examples.html
245 lines (245 loc) · 11.6 KB
/
examples.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
<!DOCTYPE html>
<head>
<title>ListExtender.js</title>
<link rel="stylesheet" href="css/style.css">
<!-- /*
Title: Nunito
Author: Vernon Adams, Cyreal
Date: n.d.
Availability: https://fonts.google.com/specimen/Nunito#standard-styles
*/ -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito">
<link rel="icon" href="img/icon.png">
<script defer type="text/javascript" src="https://www.julienbl.me/ListExtender/lib/ListExtender.min.js"></script>
<script defer type="text/javascript" src="js/examples.js"></script>
</head>
<body>
<nav>
<a href="index.html"><h3>ListExtender.js</h3></a>
<div id="nav-buttons">
<a href="https://github.com/JLambertazzo/ListExtender#readme"><img id='gh' src="img/GitHub-Mark-Light-32px.png" /></a>
<a href="examples.html"><button>Examples</button></a>
<a href="documentation.html"><button>Documentation</button></a>
</div>
</nav>
<div id="examples">
<h1>Examples</h1>
<div class="card" id="simpleList">
<h3>A basic extending list</h3>
<p>Enter text to expand the list.
<br> Drag and drop elements to rearrange them.
<br> Double click validated elements to modify them again.
<br> Clear elements and deselect them to delete them</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const simpleList = new ListExtender()</pre>
<pre>simpleList.addAfter('#simpleList p')</pre>
<pre>simpleList.setPlaceholder('Type here!')</pre>
</code>
</details>
</div>
<div class="card" id="themeList">
<h3>Try a few of the built-in styles for extending lists!</h3>
<div id="themeButtons" onclick="setTheme(event)">
<button theme="simpleLight">Simple Light Theme</button>
<button theme="simpleDark">Simple Dark Theme</button>
<button theme="underwater">Underwater Theme</button>
<button theme="hacker">Hacker Theme</button>
</div>
<details>
<summary>Source Code</summary>
<code>
<pre>const themeList = new ListExtender()</pre>
<pre>themeList.addBefore('#themeList details')</pre>
<pre>themeList.setPlaceholder('Type here!')</pre>
<pre>themeList.addFromArray(['Try', 'The', 'Buttons', 'Above'])</pre><br>
<pre>// event listener on button</pre>
<pre>const setTheme = event => {themeList.setTheme(themeList[event.target.getAttribute('theme')])}</pre>
</code>
</details>
</div>
<div class="card" id="commList">
<h3>Try community-made built-in styles for extending lists!</h3>
<div id="commButtons" onclick="setCommTheme(event)">
<!-- Made a theme? Add the button for it here -->
<button theme="fire">Fire Theme</button>
<button theme="typewriter">Typewriter Theme</button>
<button theme="checklist">Checklist Theme</button>
<button theme="hacktoberfest">hacktoberfest Theme</button>
<button theme="softSkyblue">Soft - Skyblue Theme</button>
<button theme="halloween">Halloween Theme</button>
<button theme="Love">Love Theme</button>
<button theme="Scissors">Scissors Theme</button>
<button theme="Spiderman">Spiderman Theme</button>
<button theme="batman">Batman Theme</button>
<button theme="Sunflower">Sunflower Theme</button>
<button theme="matte">Matte Theme</button>
<button theme="Alien">Alien Theme</button>
<button theme="Dog">Dog Theme</button>
<button theme="Folders">Folders Theme</button>
<button theme="dracula">Dracula Theme</button>
<button theme="Python">Python Theme</button>
</div>
<details>
<summary>Source Code</summary>
<code>
<pre>const commList = new ListExtender()</pre>
<pre>commList.addBefore('#commList details')</pre>
<pre>commList.setPlaceholder('Type here!')</pre>
<pre>commList.addFromArray(['Try', 'The', 'Buttons', 'Above'])</pre><br>
<pre>// event listener on button</pre>
<pre>const setCommTheme = event => {commList.setTheme(commList[event.target.getAttribute('theme')])}</pre>
</code>
</details>
<p>Want to add your own theme to this list? Check out <a href="https://github.com/JLambertazzo/ListExtender/blob/master/CONTRIBUTING.md">contributing.md</a></p>
</div>
<div class="card" id="delThemeList">
<h3>We also have built-in styles for extending lists! Special thanks to
<a href="https://github.com/basil08" style="text-decoration: underline;">@basil08</a> for the contribution 🚀</h3>
<div id="delThemeButtons" onclick="setDelTheme(event)">
<!-- Made a theme for delete buttons? Add it below! -->
<button theme="todo">To-Do Theme</button>
<button theme="cream">Cream Theme</button>
<button theme="default">Default Theme</button>
</div>
<details>
<summary>Source Code</summary>
<code>
<pre>const themeList = new ListExtender({ showDeleteButton: true })</pre>
<pre>themeList.addBefore('#delThemeList details')</pre>
<pre>themeList.setPlaceholder('Type here!')</pre>
<pre>themeList.addFromArray(['Try', 'The', 'Buttons', 'Above'])</pre><br>
<pre>// event listener on button</pre>
<pre>const setDelTheme = event => {delThemeList.setDelBtnTheme(delThemeList.delBtnThemes[event.target.getAttribute('theme')])}</pre>
</code>
</details>
<p>Want to add your own theme to this list? Check out <a href="https://github.com/JLambertazzo/ListExtender/blob/master/CONTRIBUTING.md">contributing.md</a></p>
</div>
<div class="card" id="deleteButton">
<h3>Lists have an optional delete button that shows on hover</h3>
<p>When not using the delete button, remove an item by double clicking it and clearing the text.</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const deleteList = new ListExtender({ showDeleteButton: true })</pre>
<pre>deleteList.addAfter('#deleteButton p')</pre>
<pre>deleteList.setPlaceholder('Type Here!')</pre>
<pre>deleteList.addFromArray(['Delete', 'These', 'Elements!!'])</pre>
</code>
</details>
</div>
<div class="card" id="validationOne">
<h3>ListExtender makes it easy to validate inputs</h3>
<p>The following list accepts dates in the following formats: 2020-12-19, 12/19/2020, 19122020</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const validateOne = new ListExtender({ showDeleteButton: true })</pre>
<pre>validateOne.addAfter('#validationOne p')</pre>
<pre>validateOne.setPlaceholder('yyyy-mm-dd || mm/dd/yyyy || ddmmyyyy')</pre>
<pre>validateOne.addValidation(value => {</pre>
<pre> return (value.match(/\d{4}-\d{2}-\d{2}/) && value.match(/\d{4}-\d{2}-\d{2}/)[0] === value) ||</pre>
<pre> (value.match(/\d{2}\/\d{2}\/\d{4}/) && value.match(/\d{2}\/\d{2}\/\d{4}/)[0] === value) || </pre>
<pre> (value.match(/\d{8}/) && value.match(/\d{8}/)[0] === value)</pre>
<pre>}, 'Please follow specified format!!')</pre>
</code>
</details>
</div>
<div class="card" id="validationTwo">
<h3>ListExtender allows for more complex validation as well!</h3>
<p>The following list does not accept duplicate dates entries.</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const validateTwo = new ListExtender() </pre>
<pre>validateTwo.addAfter('#validationTwo p') </pre>
<pre>validateTwo.setInputType('date')</pre>
<pre>validateTwo.addValidation(value => { </pre>
<pre> const vals = validateTwo.getData() </pre>
<pre> for (let i = 0; i < vals.length; i++) { </pre>
<pre> if (vals[i] === value) { </pre>
<pre> return false </pre>
<pre> } </pre>
<pre> } </pre>
<pre> return true </pre>
<pre>}, 'Duplicates not allowed!') </pre>
</code>
</details>
</div>
<div class="card" id="addItems">
<h3>It's easy to add items to the list!</h3>
<p>Type text in the input box below, each word will be added to the list</p>
<form onsubmit="handleSubmit(event)">
<input type="text" required />
<input type="submit" value="Add to List" />
</form>
<details>
<summary>Source Code</summary>
<code>
<pre>const addItems = new ListExtender()</pre>
<pre>addItems.setPlaceholder('Use form above!')</pre>
<pre>addItems.appendTo('#addItems')</pre> <br>
<pre>// event listener for button click</pre>
<pre>const handleSubmit = event => {</pre>
<pre> event.preventDefault()</pre>
<pre> const items = event.target.firstElementChild.value.split(' ').filter(val => val !== '')</pre>
<pre> addItems.addFromArray(items)</pre>
<pre> event.target.firstElementChild.value = ''</pre>
<pre>}</pre>
</code>
</details>
</div>
<div class="card" id="getItems">
<h3>It's easy to get items from the list!</h3>
<p>The items given in the list are: </p>
<button onclick="handleGetItems(event)">Click Me!</button>
<details>
<summary>Source Code</summary>
<code>
<pre>const getItems = new ListExtender()</pre>
<pre>getItems.addAfter('#getItems code')</pre> <br>
<pre>getItems.setPlaceholder('Type Here!')</pre>
<pre>// event listener for button click</pre>
<pre>const handleGetItems = event => {</pre>
<pre> const p = event.target.previousElementSibling</pre>
<pre> p.innerText = ''</pre>
<pre> const data = getItems.getData()</pre>
<pre> p.appendChild(document.createTextNode(`The items given in the list are: ${data.toString()}`))</pre>
<pre>}</pre>
</code>
</details>
</div>
<div class="card" id="markedLists">
<h3>Make a simple completed todo list!</h3>
<p>The items that you can set complete.</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const markedLists = new ListExtender({ showDeleteButton: true })</pre>
<pre>markedLists.addAfter('#markedLists p')</pre>
<pre>const dataMarkedList = ['bug fixing', 'implement new feature']</pre>
<pre>markedLists.addFromArray(dataMarkedList)</pre>
<pre>markedLists.element.addEventListener('mouseenter', event => {</pre>
<pre> const children = [...markedLists.element.children]</pre>
<pre> children.forEach(child => {</pre>
<pre> if (child.querySelector('input[type="submit"]')) {</pre>
<pre> child.querySelector('input[type="submit"]').value = 'DONE'</pre>
<pre> child.querySelector('input[type="submit"]').style.visibility = 'visible'</pre>
<pre> child.querySelector('input[type="submit"]').style.background = 'green'</pre>
<pre> }</pre>
<pre> })</pre>
<pre>})</pre>
<pre>markedLists.element.addEventListener('mousedown', event => {</pre>
<pre> if (event.target.tagName === 'INPUT' && event.target.getAttribute('type') === 'submit') { </pre>
<pre> let ulElement = event.target.parentElement</pre>
<pre> markedLists.element.insertBefore(ulElement, markedLists.element.children[0])</pre>
<pre> ulElement.style['text-decoration'] = 'line-through'</pre>
<pre> }</pre>
<pre>})</pre>
</code>
</details>
</div>
</div>
</body>
</html>