forked from Apoxx/spawnkill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdownList.js
More file actions
49 lines (37 loc) · 1.2 KB
/
DropdownList.js
File metadata and controls
49 lines (37 loc) · 1.2 KB
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
"use strict";
/* jshint multistr: true */
/* jshint newcap: false */
/**
* Représente une dropdownlist de SpawnKill, options possibles :
* value (string) : valeur par défaut
* values Object : Liste de valeurs de la forme { value: "Label", value2: "Label 2" }
* select : Options jQuery du select
* + options habituelles d'un objet jQuery
*/
SK.DropdownList = function(options) {
options = options || {};
var defaultValue = options.value || false;
delete options.value;
var values = options.values || {};
delete options.values;
var selectOptions = options.select || {};
delete options.select;
var $dropdown = $("<span>", options);
$dropdown.addClass("sk-dropdown");
var $select = $("<select>", selectOptions);
$select.addClass("sk-dropdown-select");
//On ajoute les options
for(var value in values) {
var $option = $("<option>", {
value: value,
text: values[value]
});
$select.append($option);
//On sélectionne la valeur par défaut
if(defaultValue === value) {
$option.prop("selected", true);
}
}
$dropdown.append($select);
return $dropdown;
};