forked from maykinmedia/dual-listbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
236 lines (213 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
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dual listbox example</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.3/css/bulma.min.css"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.8.1/themes/prism.min.css"
rel="stylesheet"
/>
<link href="style.css" rel="stylesheet" />
<link href="dist/dual-listbox.css" rel="stylesheet" />
</head>
<body>
<section class="hero is-medium is-primary is-bold">
<div class="hero-body">
<div class="container">
<h1 class="title">Dual Listbox</h1>
<h2 class="subtitle">
A better way to manage your multi select element.
</h2>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h2 class="subtitle">
Select by class
<span class="source" data-source="dlb1">source</span>
</h2>
<pre
class="dlb1"
><code class="language-html"><select class="select1" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<script>
let dlb1 = new DualListbox('.select1');
</script></code></pre>
<select class="select1" multiple>
<option value="1" selected="selected">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</section>
<section class="section">
<div class="container">
<h2 class="subtitle">
Add options and add eventListeners
<span class="source" data-source="dlb2">source</span>
</h2>
<pre
class="dlb2"
><code class="language-html"><select class="select2" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<script>
let dlb2 = new DualListbox('.select2', {
availableTitle:'Available numbers',
selectedTitle: 'Selected numbers',
addButtonText: '>',
removeButtonText: '<',
addAllButtonText: '>>',
removeAllButtonText: '<<',
searchPlaceholder: 'search numbers',
selectedLabel: ' test'
});
dlb2.addEventListener('added', function(event){
console.log(event);
});
dlb2.addEventListener('removed', function(event){
console.log(event);
});
</script></code></pre>
<div class="selected-element">
<p>Selected element:</p>
<ul class="changed-element">
<li>Nothing yet</li>
</ul>
</div>
<select class="select2" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</section>
<section class="section">
<div class="container">
<h2 class="subtitle">
Remove all the buttons from being rendered.
<span class="source" data-source="dlb3">source</span>
</h2>
<pre
class="dlb3"
><code class="language-html"><select class="select3" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<script>
let dlb3 = new DualListbox('.select3', {
showAddButton: false,
showAddAllButton: false,
showRemoveButton: false,
showRemoveAllButton: false,
selectedLabel: ' test'
});
</script></code></pre>
<select class="select3" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</section>
<section class="section">
<div class="container">
<h2 class="subtitle">
Allow ordering
<span class="source" data-source="dlb4">source</span>
</h2>
<pre
class="dlb4"
><code class="language-html"><select class="select4" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<script>
let dlb4 = new DualListbox('.select4', {
sortable: true,
});
</script></code></pre>
<select class="select4" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</section>
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
<p>
<strong>Dual Listbox</strong> by
<a href="http://maykinmedia.nl/">Maykin Media</a>
</p>
<p>
<a
class="icon"
href="https://github.com/maykinmedia/dual-listbox"
>
<i class="fa fa-github"></i>
</a>
</p>
</div>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.8.1/prism.min.js"></script>
<script src="dist/dual-listbox.js"></script>
<script>
var dlb1 = new DualListbox(".select1");
var dlb2 = new DualListbox(".select2", {
availableTitle: "Available numbers",
selectedTitle: "Selected numbers",
addButtonText: ">",
removeButtonText: "<",
addAllButtonText: ">>",
removeAllButtonText: "<<",
searchPlaceholder: "search numbers",
selectedLabel: ' people',
availableLabel: ' people'
});
dlb2.addEventListener("added", function (event) {
document.querySelector(".changed-element").innerHTML =
event.addedElement.outerHTML;
});
dlb2.addEventListener("removed", function (event) {
document.querySelector(".changed-element").innerHTML =
event.removedElement.outerHTML;
});
var dlb3 = new DualListbox(".select3", {
showAddButton: false,
showAddAllButton: false,
showRemoveButton: false,
showRemoveAllButton: false,
});
var dlb4 = new DualListbox(".select4", {
sortable: true,
});
var sources = document.querySelectorAll(".source");
for (var i = 0; i < sources.length; i++) {
var source = sources[i];
source.addEventListener("click", function (event) {
var code = document.querySelector(
"." + event.currentTarget.dataset.source
);
code.classList.toggle("open");
});
}
</script>
</body>
</html>