mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
module.exports = {
|
|
onInput: function(input) {
|
|
this.state = {
|
|
checked: input.checked === true,
|
|
className: input['class'],
|
|
data: input.data
|
|
};
|
|
},
|
|
getInitialBody: function(input) {
|
|
return input.label || input.renderBody;
|
|
},
|
|
|
|
isChecked: function() {
|
|
return this.state.checked === true;
|
|
},
|
|
|
|
setChecked: function(newChecked) {
|
|
if (newChecked !== this.state.checked) {
|
|
this.setState('checked', !this.state.checked);
|
|
}
|
|
},
|
|
|
|
toggle: function() {
|
|
this.setChecked(!this.state.checked);
|
|
},
|
|
|
|
getData: function() {
|
|
return this.state.data;
|
|
},
|
|
|
|
handleClick: function() {
|
|
var newChecked = !this.state.checked;
|
|
|
|
var defaultPrevented = false;
|
|
|
|
this.emit('toggle', {
|
|
checked: newChecked,
|
|
data: this.state.data,
|
|
preventDefault: function() {
|
|
defaultPrevented = true;
|
|
}
|
|
});
|
|
|
|
if (!defaultPrevented) {
|
|
this.setState('checked', newChecked);
|
|
}
|
|
}
|
|
}; |