1 |
a908ef13
|
Anděl Ondřej
|
<!DOCTYPE html>
|
2 |
|
|
<html>
|
3 |
|
|
<head>
|
4 |
|
|
<meta charset="utf-8">
|
5 |
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
6 |
|
|
<title>Demo</title>
|
7 |
|
|
<meta name="description" content="">
|
8 |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
9 |
|
|
<link rel="stylesheet" href="./vanillaSelectBox.css">
|
10 |
|
|
<!-- internal css -->
|
11 |
|
|
<style>
|
12 |
|
|
body {
|
13 |
|
|
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
14 |
|
|
margin: 0;
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
.darkRed {
|
18 |
|
|
color: darkred;
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
.darkBlue {
|
22 |
|
|
color: darkblue;
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
.navbar {
|
26 |
|
|
position: relative;
|
27 |
|
|
border: 1px solid #080808;
|
28 |
|
|
background-color: #222;
|
29 |
|
|
background-image: linear-gradient(to bottom,#3c3c3c 0,#222 100%);
|
30 |
|
|
background-repeat: repeat-x;
|
31 |
|
|
border-radius: 4px;
|
32 |
|
|
margin: 0;
|
33 |
|
|
padding: 0;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
.navbar-brand {
|
37 |
|
|
float: left;
|
38 |
|
|
padding: 14px 15px;
|
39 |
|
|
font-size: 18px;
|
40 |
|
|
line-height: 20px;
|
41 |
|
|
color: #fff;
|
42 |
|
|
cursor: pointer;
|
43 |
|
|
text-decoration: none;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
a:hover {
|
47 |
|
|
color: #fff;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
.navbar-links {
|
51 |
|
|
font-size: 14px;
|
52 |
|
|
line-height: 20px;
|
53 |
|
|
position: relative;
|
54 |
|
|
margin: 0;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
.navbar-links li {
|
58 |
|
|
cursor: pointer;
|
59 |
|
|
text-decoration: none;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
.navbar-links li {
|
63 |
|
|
display: inline-block;
|
64 |
|
|
min-width: 120px;
|
65 |
|
|
text-align: center;
|
66 |
|
|
margin-top: 15px;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
.navbar-links li.active {
|
70 |
|
|
background-image: #080808;
|
71 |
|
|
background: #080808;
|
72 |
|
|
color: #fff;
|
73 |
|
|
height: 100%;
|
74 |
|
|
padding-top: 15px;
|
75 |
|
|
padding-bottom: 15px;
|
76 |
|
|
margin: 0;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
a {
|
80 |
|
|
color: #9d9d9d;
|
81 |
|
|
cursor: pointer;
|
82 |
|
|
text-decoration: none;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
@media (max-width: 640px) {
|
86 |
|
|
.navbar-brand {
|
87 |
|
|
width: 100%;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
.navbar-links {
|
91 |
|
|
padding-left: 0;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
button.demo {
|
95 |
|
|
margin-right: 100% !important;
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
#container {
|
100 |
|
|
padding-top: 30px;
|
101 |
|
|
padding-left: 50px;
|
102 |
|
|
width: 90%;
|
103 |
|
|
font-size: 14px;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
.demo-zone {
|
107 |
|
|
display: block;
|
108 |
|
|
width: 100%;
|
109 |
|
|
min-height: 200px;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
.mini-demo-zone {
|
113 |
|
|
display: block;
|
114 |
|
|
width: 100%;
|
115 |
|
|
min-height: 100px;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
.btns-active, .btns-inactive {
|
119 |
|
|
margin-top: 20px;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
label {
|
123 |
|
|
display: inline-block;
|
124 |
|
|
min-width: 220px;
|
125 |
|
|
width: 220px;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
button.demo {
|
129 |
|
|
margin-right: 0;
|
130 |
|
|
margin-left: 4px;
|
131 |
|
|
text-align: center;
|
132 |
|
|
white-space: nowrap;
|
133 |
|
|
vertical-align: middle;
|
134 |
|
|
user-select: none;
|
135 |
|
|
border-radius: 4px;
|
136 |
|
|
z-index: 1;
|
137 |
|
|
color: #333;
|
138 |
|
|
background: white;
|
139 |
|
|
background-image: linear-gradient(to bottom,#fff 0,#e0e0e0 100%);
|
140 |
|
|
border: 1px solid #ccc !important;
|
141 |
|
|
color: #333;
|
142 |
|
|
line-height: 20px;
|
143 |
|
|
font-size: 14px;
|
144 |
|
|
padding: 4px 12px;
|
145 |
|
|
margin-bottom: 2px;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
button.demo:hover {
|
149 |
|
|
background-image: linear-gradient(to top,#fff 0,#e0e0e0 100%);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
.presentation {
|
153 |
|
|
background: #eee;
|
154 |
|
|
color: #2e44b9;
|
155 |
|
|
border: 1px solid grey;
|
156 |
|
|
border-radius: 8px;
|
157 |
|
|
line-height: 20px;
|
158 |
|
|
padding: 8px;
|
159 |
|
|
margin-bottom: 40px;
|
160 |
|
|
width: 90%;
|
161 |
|
|
max-width: 800px;
|
162 |
|
|
font-size: 14px;
|
163 |
|
|
}
|
164 |
|
|
</style>
|
165 |
|
|
</head>
|
166 |
|
|
<body>
|
167 |
|
|
<nav class="navbar">
|
168 |
|
|
<div class="navbar-header">
|
169 |
|
|
<a class="navbar-brand" href="#">
|
170 |
|
|
Experiments with vanilla js
|
171 |
|
|
</a>
|
172 |
|
|
</div>
|
173 |
|
|
<ul class="navbar-links">
|
174 |
|
|
<li id="vanillaSelectBox" class="active"><a href="#vanillaSelectBox">vanillaSelectBox Ajax demo</a></li>
|
175 |
|
|
<li id="blog"><a href="https://philippemarcmeyer.github.io#vanillajs">Github Blog</a></li>
|
176 |
|
|
<li id="repos"><a href="https://github.com/PhilippeMarcMeyer/vanillaSelectBox">Github repos</a></li>
|
177 |
|
|
</ul>
|
178 |
|
|
</nav>
|
179 |
|
|
<div id="container">
|
180 |
|
|
<p class="presentation">
|
181 |
|
|
<b>vanillaSelectBox()</b> <br/>
|
182 |
|
|
Special demo for rvpatel : gets data from ajax call, build a select tage in the DOM, then uses vanillaSelectBox
|
183 |
|
|
</p>
|
184 |
|
|
|
185 |
|
|
<div class="demo-zone" style="text-align:left;" id="demo-ajax">
|
186 |
|
|
|
187 |
|
|
</div>
|
188 |
|
|
|
189 |
|
|
<script src="./vanillaSelectBox.js"></script>
|
190 |
|
|
<script>
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
httpRequest = new XMLHttpRequest();
|
194 |
|
|
let peopleVSB = null;
|
195 |
|
|
if (httpRequest) {
|
196 |
|
|
httpRequest.onreadystatechange = function () {
|
197 |
|
|
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
198 |
|
|
if (httpRequest.status === 200) {
|
199 |
|
|
let response = null;
|
200 |
|
|
try{
|
201 |
|
|
response = JSON.parse(httpRequest.responseText);
|
202 |
|
|
|
203 |
|
|
}catch(error){
|
204 |
|
|
console.error(error);
|
205 |
|
|
}
|
206 |
|
|
if(response && response.data){
|
207 |
|
|
buildSelect(response.data,"demo-ajax","demo-ajax-select");
|
208 |
|
|
peopleVSB = new vanillaSelectBox("#demo-ajax-select",{ "maxHeight": 200, "search": true,translations: { "all": "All", "items": "ppl" } });
|
209 |
|
|
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
} else {
|
213 |
|
|
alert('There was a problem with the request.');
|
214 |
|
|
}
|
215 |
|
|
}
|
216 |
|
|
};
|
217 |
|
|
|
218 |
|
|
httpRequest.open('GET', 'https://dummy.restapiexample.com/api/v1/employees');
|
219 |
|
|
httpRequest.send();
|
220 |
|
|
}
|
221 |
|
|
function buildSelect(data,divId,SelectId){
|
222 |
|
|
let anOption;
|
223 |
|
|
let div = document.getElementById(divId);
|
224 |
|
|
div.innerHTML="";
|
225 |
|
|
let elem = document.createElement("select");
|
226 |
|
|
elem.setAttribute('id',SelectId);
|
227 |
|
|
elem.setAttribute('multiple','true');
|
228 |
|
|
elem.setAttribute('size','1');
|
229 |
|
|
div.appendChild(elem);
|
230 |
|
|
data.forEach(function(x){
|
231 |
|
|
anOption = document.createElement("option");
|
232 |
|
|
anOption.value = x.id;
|
233 |
|
|
anOption.text = x.employee_name;
|
234 |
|
|
elem.appendChild(anOption);
|
235 |
|
|
});
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
</script>
|
239 |
|
|
</html>
|