-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
536 lines (426 loc) · 17.7 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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Selectoid</title>
<link rel="stylesheet" href="libs/css/normalize.css">
<link rel="stylesheet" href="libs/css/boilerplate.css">
<link rel="stylesheet" href="src/selectoid.css">
<!--<link rel="stylesheet" href="dist/selectoid.min.css">-->
<!--<link rel="stylesheet" href="dist/selectoid.css">-->
<link rel="stylesheet" href="libs/css/main.css">
<link rel="stylesheet" href="libs/font-awesome/css/font-awesome.css">
<script src="libs/js/modernizr-2.6.2.min.js"></script>
</head>
<body>
<header>
<span class="galaxy yellow">Selectoid</span>
<br>
<img src="libs/img/SelectoidLogoSmall_black.png" alt="Selectoid Logo">
</header>
<div id="main">
<p class="announcement">
Selectoid as well as this page are in the process of updating to a newer version 0.0.7. Some content may be broken. Thank you for your understanding.
</p>
<p>
Selectoid is a JavaScript plugin that turns mean select boxes into happy ones.
Selectoid was originally inspired by <a href="http://www.translate.google.com">Google Translate page's select box</a>.
However selectoid has its
limitations - it likes small data set - up to a 50~80 elements. After that, feel free to use any of
the select box enhancing JS libraries with auto-complete capabilities that are out there -
<a href="http://harvesthq.github.io/chosen/">Chosen</a>, <a href="http://ivaynberg.github.io/select2/">Select2</a>, etc.
</p>
<p>
<i>
Before we continue: there is 10 pixel padding on this page for representational
purposes. Don't be lost when it says "100% width div" and it looks 20 pixels short.
</i>
</p>
Language select example:
<div class="selectoid" id="selectoid1"></div>
<br>
Cities select example:
<div class="selectoid" id="selectoid2"></div>
<hr>
<b>Code</b>
<div class="gist">
<script src="https://gist.github.com/gogromat/5987274.js"></script>
</div>
<hr>
<table>
<tr width="30%">
<td>
Feature: Not responsive, no keyboard commands :s
<br>
Example: select box should not be responsive and default should be set to Boston.
Also no keyboard keys should change values of selectoid.
<br>
<div class="selectoid" id="selectoid4"
data-initial="bo"
data-responsive="false"
data-addKeyboardAction="false"></div>
</td>
</tr>
</table>
<br>
<hr>
Feature: Width related settings and examples
<br>
<br>
<br>
<div style="background-color:#A9D0F5;">
Outer div 100% width;
<br>
Selectoid's width is based off its <b>.selectoid_direct_parent</b>.
<div style="width:20%; background-color: yellow !important;z-index:10000;" id="selectoid_direct_parent">
Inner div 20% width.
<div class="selectoid" id="selectoidDirect" data-initial="bo" data-responsive="true"></div>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="selectoid_parent" style="background-color:#A9D0F5;">
Outer div 100% width; <b>.selectoid_parent</b>.
<br>
Selectoid's width is based off <b>window's</b> width, not of inner div.
<div style="width:20%; background-color: yellow !important;z-index:10000;">
Inner div 20% width
<div class="selectoid" id="selectoid7" data-initial="bo" data-responsive="true"></div>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="selectoid_parent" style="background-color:#A9D0F5;">
Outer div 100% width; <b>.selectoid_parent</b>.
<br>
Selectoid's width is based off <b>.selectoid_parent</b> width, not on inner div.
<div style="width:20%; background-color: yellow !important;z-index:10000;">
Inner div 20% width
<div class="selectoid" id="selectoid5" data-initial="bo" data-responsive="true"></div>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="elementWidth" style="background-color: #A9D0F5">
Parent div, width is 100%
<br>
<div style="width:60%; float: left;background-color:yellow">
Div's width is 60%
<br>
<br>
<br>
<br>
<div class="selectoid" id="selectoid6" data-initial="bo"></div>
</div>
<div style="width:40%; float: right;background-color:orange;" id="selectoid6WidthElement">
Div's width is 40%
<br>
Selectoid's width is based off width of <b>this div</b>.
<br>
<br>
<br>
<br>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<hr>
Feature: Selectoid based on jQuery object:
<br>
<ul>
<li>useful when you auto-generate Selectoid input fields</li>
<li>useful when you do not have an id of the element you want to make into a Selectoid</li>
<li>is an alternative way to make element/field into a Selectoid</li>
</ul>
Example:
<ul>
<li>both divs have <b>same class</b> "someClass"</li>
<li>we create a new Selectoid with <b>object: $($(".someClass")[0])</b> property in <i>parameters</i></li>
<li>only first item should turn into a Selectoid</li>
<li>first item should now have a unique Selectoid id - it is auto-assigned if item had no id before</li>
<li>first item (element with class "someClass") now has an id <b>selectoid_0</b></li>
<li>first item <b>closes</b> on mouseLeave action</li>
</ul>
<div class="someClass selectoid" data-initial="en" style="border:dashed 1px black">Should turn into selectoid</div>
<br>
<div class="someClass selectoid" data-initial="en" style="border:dashed 1px black">Should not turn into selectoid</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<hr>
Feature: change Selectoid data set on the fly.
<br>
Example: this is better shown in code.
<br>
<br>
In this example we change the data of the Selectoid that was initialized previously with <b>completely new data</b>.
Initially data should be languages, but later on it is changed to cities.
<br>
We change it using changeData() function that accepts object with new parameters, data, and format.
<br>
<br>
<ul>
<li>Data should change from languages to cities or animals</li>
<li>Initial values are set to San Francisco / English / Giraffe</li>
<li>Also should not close on mouseOut/focusOut - (open Selectoid, and then press button to switch data) - pretty neat :p</li>
</ul>
<br>
<button class="changeInitialSelectoid citiesClass">
<span>Change data to "Cities"</span>
</button>
<button class="changeInitialSelectoid languagesClass">
<span>Change data to "Languages"</span>
</button>
<button class="changeInitialSelectoid animalsClass">
<span>Change data to "Animals"</span>
</button>
<br>
<br>
<div id="initiallyLanguages" class="selectoid" data-initial="en" style="border:dashed 1px black"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<footer>
<p class="centered">
designed & developed by
<br>
<a href="https://github.com/gogromat/" target="_blank" class="galaxy link">GogromaT</a>
<br>
<a href="https://plus.google.com/116898228043449492263/posts" class="link contact">
<i class="icon-google-plus-sign icon-4"></i>
</a>
<a href="https://github.com/gogromat/" target="_blank" class="link contact">
<i class="icon-github-sign icon-4"></i>
</a>
<a href="https://twitter.com/Astafurov_Alex" target="_blank" class="link contact">
<i class="icon-twitter-sign icon-4"></i>
</a>
<br>
<br>
<br>
<br>
<script data-gittip-username="gogromat" src="https://www.gittip.com/assets/widgets/0002.js"></script>
</p>
</footer>
<script src="libs/js/underscore.js"></script>
<script src="libs/js/jquery_1.10.0_min.js"></script>
<script src="libs/js/languages.js"></script>
<script src="src/selectoid.js"></script>
<!--<script src="dist/selectoid.min.js"></script>-->
<!--<script src="dist/selectoid.js"></script>-->
<script>
$(document).ready(function () {
//console.clear();
var citiesData = [
{name:"New York City", value: "nyc"},
{name:"Los Angeles", value: "lac"},
{name:"San Francisco", value: "sf" },
{name:"Boston", value: "bo" },
{name:"Washington", value: "wdc"},
{name:"Chicago", value: "chi"},
{name:"Houston", value: "hou"},
{name:"Philadelphia", value: "phi"},
{name:"Phoenix", value: "pho"},
];
var Animals = [
{name: "Dog", value: "dg"},
{name: "Cat", value: "ct"},
{name: "Giraffe", value: "gf"},
//{name: "Tux", value: "tx"},
{name: "Horse", value: "hr"},
{name: "Wildebeest",value: "gnu"},
{name: "Lion", value: "li"},
{name: "Wolf", value: "wf"},
{name: "Capybara", value: "cp"},
{name: "Leopard", value: "lp"},
{name: "Zebra", value: "zb"},
{name: "Elephant", value: "en"},
{name: "Dolphin", value: "dp"},
{name: "Llama", value: "ll"},
{name: "Panda", value: "pd"}
];
var languageDataFormat = function (element) {
if (element) {
return {
name: element.name,
value: element.abbreviation.gt
};
}
};
var citiesDataFormat = function (element) {
if (element) {
return {
name: element.name,
value: element.value
};
}
};
var animalsFormat = function (element) {
if (element) {
return {
name: element.name,
value: element.value
}
}
}
var selectoid = new Selectoid({
object: "#selectoid1",
data: Languages,
htmlFormat: function (element) {
return ("<div>" +
element.name +
"<div class='secondary'>" + element.greeting + "</div>" +
"</div>");
},
dataFormat: languageDataFormat,
parameters: {
closeOnMouseLeave: false,
closeOnFocusOut: false,
initial: "en"
}
});
var cities = new Selectoid("#selectoid2", citiesData, "wdc");
var cities2 = new Selectoid("#selectoid4", citiesData);
var cities7 = new Selectoid({
object: "#selectoid7",
data: citiesData,
parameters: {
initial: "wdc",
closeOnMouseLeave: false,
closeOnFocusOut: false,
}
});
var selectoidDirect = new Selectoid({
object: "#selectoidDirect",
data: citiesData,
parameters: {
initial: "wdc",
closeOnMouseLeave: false,
closeOnFocusOut: false,
widthElement: "#selectoid_direct_parent"
}
});
var cities4 = new Selectoid({
object: "#selectoid5",
data: citiesData,
parameters: {
initial: "wdc",
closeOnMouseLeave: false,
closeOnFocusOut: false,
widthElement: ".selectoid_parent"
}
});
var cities5 = new Selectoid({
object: "#selectoid6",
data: citiesData,
parameters: {
initial: "wdc",
closeOnMouseLeave: false,
closeOnFocusOut: false,
widthElement: "#selectoid6WidthElement"
}
});
var languages2 = new Selectoid({
object: $($(".someClass")[0]),
data: Languages,
parameters: {
closeOnFocusOut: false,
closeOnMouseLeave: true,
},
dataFormat: languageDataFormat
});
var initiallyLanguages = new Selectoid({
object: "#initiallyLanguages",
data: Languages,
parameters: {
closeOnFocusOut: false,
closeOnMouseLeave: false,
},
dataFormat: languageDataFormat
});
$(".changeInitialSelectoid").click(function () {
var self = $(this);
//console.log(self);
setTimeout(function () {
if (self.hasClass("citiesClass")) {
//console.log("CITIES");
Selectoid.initiallyLanguages.changeData({
data: citiesData,
parameters: {
initial: "sf",
closeOnFocusOut: false,
closeOnMouseLeave: false,
},
dataFormat: citiesDataFormat
});
return false;
} else if (self.hasClass("languagesClass")) {
//console.log("LANGUAGES");
Selectoid.initiallyLanguages.changeData({
data: Languages,
parameters: {
initial: "en",
closeOnFocusOut: false,
closeOnMouseLeave: false,
},
dataFormat: languageDataFormat
});
return false;
} else if (self.hasClass("animalsClass")) {
//console.log("ANIMALS");
Selectoid.initiallyLanguages.changeData({
data: Animals,
parameters: {
initial: "gf",
closeOnFocusOut: false,
closeOnMouseLeave: false,
},
dataFormat: animalsFormat
});
return false;
}
}, 10);
});
$.fn.initiallyLanguages = initiallyLanguages;
});
</script>
</body>
</html>