4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
12 * This control creates a custom checkbox.
15 * // Create and render a checkbox to the body element
16 * tinymce.ui.Factory.create({
20 * }).renderTo(document.body);
22 * @-x-less Checkbox.less
23 * @class tinymce.ui.Checkbox
24 * @extends tinymce.ui.Widget
26 define("tinymce/ui/Checkbox", [
31 return Widget.extend({
39 * Constructs a new Checkbox instance with the specified settings.
42 * @param {Object} settings Name/value object with settings.
43 * @setting {Boolean} checked True if the checkbox should be checked by default.
45 init: function(settings) {
48 self._super(settings);
50 self.on('click mousedown', function(e) {
54 self.on('click', function(e) {
57 if (!self.disabled()) {
58 self.checked(!self.checked());
62 self.checked(self.settings.checked);
66 * Getter/setter function for the checked state.
69 * @param {Boolean} [state] State to be set.
70 * @return {Boolean|tinymce.ui.Checkbox} True/false or checkbox if it's a set operation.
72 checked: function(state) {
75 if (typeof state != "undefined") {
77 self.addClass('checked');
79 self.removeClass('checked');
82 self._checked = state;
83 self.aria('checked', state);
92 * Getter/setter function for the value state.
95 * @param {Boolean} [state] State to be set.
96 * @return {Boolean|tinymce.ui.Checkbox} True/false or checkbox if it's a set operation.
98 value: function(state) {
99 return this.checked(state);
103 * Renders the control as a HTML string.
106 * @return {String} HTML representing the control.
108 renderHtml: function() {
109 var self = this, id = self._id, prefix = self.classPrefix;
112 '<div id="' + id + '" class="' + self.classes() + '" unselectable="on" aria-labeledby="' + id + '-al" tabindex="-1">' +
113 '<i class="' + prefix + 'ico ' + prefix + 'i-checkbox"></i>' +
114 '<span id="' + id +'-al" class="' + prefix + 'label">' + self.encode(self._text) + '</span>' +