-
Notifications
You must be signed in to change notification settings - Fork 0
/
radiogroup.js
46 lines (39 loc) · 1.05 KB
/
radiogroup.js
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
'use strict';
function igoRadiogroup($) {
return {
preinit: function(el) {
this.getRadios(el).filter('[value="' + el.text() + '"]').prop('checked', true);
},
init: function(el, self) {
this.$inputs = this.getRadios(el);
this.$labels = this.$inputs.parent();
this.$radios = this.$labels.parent();
this.$inputs.event('change.value', function (e) {
self.value = $(e.currentTarget).val();
});
},
value: {
get: function() {
return this.$inputs.filter(':checked').val();
},
set: function(value) {
this.$inputs.filter('[value="' + value + '"]').prop('checked', true);
}
},
label: {
get: function() {
return this.$inputs.filter(':checked').parent().text();
},
set: function(value) {
this.$inputs.filter(':checked').parent().text(value);
}
},
getRadios: function(el) {
return $('[_=igoRadio]>label>input[name="' + el.attr('id') + '"]');
},
class: function(name, isAdd) {
return isAdd ? this.$radios.addClass(name) : this.$radios.removeClass(name);
}
};
}
igoRadiogroup.register = null;