-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
313 lines (280 loc) · 9.92 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Demo</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./vanillaSelectChooser.css">
<!-- internal css -->
<style>
h5 {
color: #3480D7;
font-weight: bold;
font-size: 24px;
}
p {
color: #3480D7;
font-size: 16px;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
}
.darkRed {
color: darkred;
}
.darkBlue {
color: darkblue;
}
.navbar {
position: relative;
border: 1px solid #080808;
background-color: #222;
background-image: linear-gradient(to bottom, #3c3c3c 0, #222 100%);
background-repeat: repeat-x;
border-radius: 4px;
margin: 0;
padding: 0;
}
.navbar-brand {
float: left;
padding: 14px 15px;
font-size: 18px;
line-height: 20px;
color: #fff;
cursor: pointer;
text-decoration: none;
}
a:hover {
color: #fff;
}
.navbar-links {
font-size: 14px;
line-height: 20px;
position: relative;
margin: 0;
}
.navbar-links li {
cursor: pointer;
text-decoration: none;
}
.navbar-links li {
display: inline-block;
min-width: 120px;
text-align: center;
margin-top: 15px;
}
.navbar-links li.active {
background-image: #080808;
background: #080808;
color: #fff;
height: 100%;
padding-top: 15px;
padding-bottom: 15px;
margin: 0;
}
a {
color: #9d9d9d;
cursor: pointer;
text-decoration: none;
}
@media (max-width: 640px) {
.navbar-brand {
width: 100%;
}
.navbar-links {
padding-left: 0;
}
button.demo {
margin-right: 100% !important;
}
}
#container {
padding-top: 0px;
padding-left: 50px;
width: 90%;
font-size: 14px;
}
.demo-zone {
display: block;
width: 100%;
min-height: 200px;
}
.btns-active,
.btns-inactive {
margin-top: 20px;
}
label {
display: inline-block;
min-width: 220px;
width: 220px;
}
button.demo {
margin-right: 0;
margin-left: 4px;
text-align: center;
white-space: nowrap;
vertical-align: middle;
user-select: none;
border-radius: 4px;
z-index: 1;
color: #333;
background: white;
background-image: linear-gradient(to bottom, #fff 0, #e0e0e0 100%);
border: 1px solid #ccc !important;
color: #333;
line-height: 20px;
font-size: 14px;
padding: 4px 12px;
margin-bottom: 2px;
}
button.demo:hover {
background-image: linear-gradient(to top, #fff 0, #e0e0e0 100%);
}
.presentation {
background: #eee;
color: #2e44b9;
border: 1px solid grey;
border-radius: 8px;
line-height: 20px;
padding: 8px;
margin-bottom: 40px;
width: 90%;
max-width: 800px;
font-size: 14px;
}
</style>
</head>
<body>
<nav class="navbar">
<div class="navbar-header">
<a class="navbar-brand" href="#">
Experiments with vanilla js
</a>
</div>
<ul class="navbar-links">
<li id="vanillaSelectBox" class="active"><a href="#vanillaSelectBox">vanillaSelectBox</a></li>
<li id="blog"><a href="https://philippemarcmeyer.github.io#vanillajs">Github Blog</a></li>
<li id="repos"><a href="https://github.com/PhilippeMarcMeyer/vanillaSelectChooser">Github repos</a></li>
</ul>
</nav>
<div id="container">
<div style="padding:0">
<h5>vanillaSelectChooser v.37 : IE11 Support in case someone needs it</h5>
<p>Takes a select ! Results are available in the hidden select thru change event</p>
</div>
<div class="demo-zone" id="demo">
<select id="brands" onChange="showChosen()" multiple="" size="20" style="display: none;">
<option value="Abarth">Abarth</option>
<option value="Alfa Romeo">Alfa Romeo</option>
<option value="Alpine">Alpine</option>
<option value="Aston Martin" selected="true">Aston Martin</option>
<option value="Audi" selected="true">Audi</option>
<option value="Bentley" selected="true">Bentley</option>
<option value="BMW" selected="true">BMW</option>
<option value="Cadillac" selected="true">Cadillac</option>
<option value="Chevrolet">Chevrolet</option>
<option value="Citroën">Citroën</option>
<option value="Cupra">Cupra</option>
<option value="DACIA">DACIA</option>
<option value="DS">DS</option>
<option value="Ferrari">Ferrari</option>
<option value="Fiat">Fiat</option>
<option value="Ford">Ford</option>
<option value="Honda">Honda</option>
<option value="Hyundai">Hyundai</option>
<option value="Infiniti">Infiniti</option>
<option value="Jaguar">Jaguar</option>
<option value="Jeep">Jeep</option>
<option value="KIA">KIA</option>
<option value="Lamborghini">Lamborghini</option>
<option value="Land Rover" selected="true">Land Rover</option>
<option value="Lexus">Lexus</option>
<option value="Lotus">Lotus</option>
<option value="Maserati">Maserati</option>
<option value="Mazda">Mazda</option>
<option value="McLaren">McLaren</option>
<option value="Mercedes-Benz">Mercedes-Benz</option>
<option value="MINI">MINI</option>
<option value="Mitsubishi">Mitsubishi</option>
<option value="Nissan">Nissan</option>
<option value="Opel">Opel</option>
<option value="Peugeot">Peugeot</option>
<option value="Porsche">Porsche</option>
<option value="Renault">Renault</option>
<option value="Rolls-Royce">Rolls-Royce</option>
<option value="SEAT">SEAT</option>
<option value="Skoda">Skoda</option>
<option value="smart">smart</option>
<option value="Ssangyong">Ssangyong</option>
<option value="Subaru">Subaru</option>
<option value="Suzuki">Suzuki</option>
<option value="Tesla">Tesla</option>
<option value="Toyota">Toyota</option>
<option value="Volkswagen">Volkswagen</option>
<option value="Volvo">Volvo</option>
</select>
</div>
</div>
<br />
<div style="margin-left:46px;">
<i>User Ctrl and Shift keys to select several items</i>
<p>Chosen items from the select :</p>
<div id="vanilla-result"></div>
</div>
<div style="margin-left:46px;">
<p>Actions</p>
<button id="demo-destroy" class="demo">Destroy</button> <button id="demo-init" class="demo">Init</button>
</div>
<script src="./vanillaSelectChooser.js"></script>
<script>
let chooser = null;
window.addEventListener("DOMContentLoaded", function (event) {
chooser = new vanillaSelectChooser("#brands",
{
minWidth: 180,
maxHeight: 400,
addButtonWidth: 50,
gapBeetween: 100
});
showChosen();
});
function getSelectValues() {
let values = [];
let options = document.querySelectorAll("#brands option");
Array.prototype.slice.call(options).forEach(function (x) {
if (x.hasAttribute("selected")) {
values.push({"val":x.value,"sort":parseInt(x.getAttribute("sort"))});
}
});
if(values.length > 0){
values = values.sort(function(a,b){
return a.sort - b.sort;
});
}
let output = values.map(function(x){
return x.val;
});
return output;
}
function showChosen() {
let values = getSelectValues();
document.getElementById("vanilla-result").innerHTML = values.join(",");
}
document.querySelector("#demo-destroy").addEventListener("click",function(){
chooser.destroy();
document.querySelector("#brands").style.display="block";
});
document.querySelector("#demo-init").addEventListener("click",function(){
chooser = new vanillaSelectChooser("#brands",
{
minWidth: 180,
maxHeight: 400,
addButtonWidth:50,
gapBeetween:100
});
});
</script>
</html>