# RadioButtonsGroup
Open me!
Demo View | Source Code (opens new window) | Download all widgets
Assets:
Images:
JavaScripts:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select radio buttons</title>
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="../core/lib/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../core/lib/jda-0.1.js"></script>
<script type="text/javascript" src="js/jquery.da_ui.radiobuttons.js"></script>
<script type="text/javascript" src="js/select-radio-buttons.js"></script>
</head>
<body>
<h1>Select radio buttons</h1>
<div class="content">
<select name="test" class="select-radio">
<option value="">-----</option>
<option value="1">value-1</option>
<option value="2">value-2</option>
</select>
</div>
<h1>Select multiple checkbox buttons</h1>
<div class="content">
<select name="test2" class="select-radio" multiple="multiple">
<option value="">-----</option>
<option value="1" selected="selected">value-1</option>
<option value="2">value-2</option>
<option value="3" selected="selected">value-3</option>
<option value="4">value-4</option>
<option value="5">value-5</option>
</select>
<div class="clear"></div>
</div>
</body>
</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
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
.da_ui-select-radio-list {
width: 636px;
padding: 10px 0 0 0;
}
.da_ui-select-radio-list li {
list-style: none;
display: block;
background: url("../core/images/radio_b.png") no-repeat left center;
width: 551px;
height: 38px;
line-height: 38px;
font-size: 12px;
padding: 0 17px 0 68px;
margin-bottom: 8px;
cursor: pointer;
}
.da_ui-select-radio-list li.da_ui-state-active {
background: url("../core/images/radio_b_a.png") no-repeat left center !important;
cursor: default;
}
.da_ui-select-radio-list li.da_ui-state-hover {
background: url("../core/images/radio_b_g.png") no-repeat left center;
}
ul.da_ui-select-radio-multi-list {
float: left;
}
.da_ui-select-radio-multi-list {
width: 322px;
padding: 15px 30px 0 0;
}
.da_ui-select-radio-last{
padding-right: 0px;
}
.da_ui-select-radio-multi-list li {
list-style: none;
display: block;
background: url("../core/images/checkbox_b.png") no-repeat left center;
width: 322px;
height: 37px;
line-height: 37px;
font-size: 12px;
padding: 0 17px 0 68px;
margin-bottom: 8px;
cursor: pointer;
}
.da_ui-select-radio-multi-list li.da_ui-state-active {
background: url("../core/images/checkbox_b_a.png") no-repeat left center !important;
}
.da_ui-select-radio-multi-list li.da_ui-state-hover {
background: url("../core/images/checkbox_b_g.png") no-repeat left center;
}
.clear {
clear: both;
}
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
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
$(function() {
$(".select-radio[name=test]").radioButtons({});
$(".select-radio[name=test2]").radioButtons({column: 2});
});
1
2
3
4
5
2
3
4
5
(function($) {
var incriment = 0;
$.widgetda("da_ui.radioButtons", {
version: "0.1",
options: {
multiple: false,
column: 1
},
_create: function() {
var self = this,
o = self.options,
el = self.element;
o.multiple = (el.attr('multiple') == "multiple" ? true: false);
incriment++;
this.element.css('display', 'none');
this.tmplOptions = '<li data-value="%value%" class="%class%">%label%</li>';
var listdata = el.children().map(
function() {
var $this=$(this);
return self._optionItem($this);
}).get();
var selectname = el.attr("id");
if(!selectname) {
selectname = "da_ui-select-radio-";
if(o.multiple) {
selectname += "multi-";
}
selectname += incriment + Math.floor(Math.random() * 1000);
}
this.lists = this._listsColumn(listdata, selectname);
this.block_list = $('<div class="da_ui-select-radio-block"></div>');
for(var ii = 0; ii < this.lists.length; ii++) {
var list = this.lists[ii];
$("li", list).click(
function() {
self._selectOption(this, list);
})
.bind("mouseenter", function() {
$(this).addClass("da_ui-state-hover");
})
.bind("mouseleave", function() {
$(this).removeClass("da_ui-state-hover");
});
this.block_list.append(list);
}
this.block_list.children().insertAfter(el);
},
_optionItem: function(elem){
if(!elem.val()) {
return;
}
if(elem.attr("selected")) {
recordclass = "da_ui-state-active "+ recordclass;
}
var optionItem = this.tmplOptions
.replace("%value%", elem.val())
.replace("%class%", recordclass)
.replace("%label%",elem.text());
return optionItem;
},
_listsColumn: function(listdata, selectname) {
var col_count = this.options.column;
var div_list = parseInt(listdata.length / col_count),
mod_list = listdata.length % col_count,
objects_array = [], last = 0, start;
for(var ii = 0; ii < col_count; ii++) {
start = last;
last = start + div_list;
if(ii < mod_list) last++;
objects_array.push(
$('<ul></ul>', {
'id': selectname +'-list-'+ii,
'class': (this.options.multiple?"da_ui-select-radio-multi-list":"da_ui-select-radio-list")
})
.data({
"element":this.element
})
.append(listdata.slice(start, last).join(""))
);
}
if( this.options.multiple) {
objects_array[0].addClass("da_ui-select-radio-first");
objects_array[objects_array.length-1].addClass("da_ui-select-radio-last");
}
return objects_array;
},
_selectOption: function(opt, list) {
if(this.options.multiple) {
return this._selectOptionMultiple(opt);
}
$("li", list).removeClass("da_ui-state-active");
$(opt).addClass("da_ui-state-active");
this._emptySelected();
var value = $( opt ).attr("data-value");
this.element.find("option[value='"+ value +"']").attr("selected", "selected");
},
_selectOptionMultiple: function(opt) {
var value = $( opt ).attr("data-value");
if(!$(opt).hasClass("da_ui-state-active")) {
$(opt).addClass("da_ui-state-active");
this.element.find("option[value='"+ value +"']").attr("selected", "selected");
} else {
$(opt).removeClass("da_ui-state-active");
this.element.find("option[value='"+ value +"']").removeAttr("selected");
}
},
_emptySelected: function() {
this.element.find("option:selected").each(function() {
this.selected = false;
});
}
});
})( jQuery );
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
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
// Make sure to add code blocks to your code group