-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox.js
61 lines (56 loc) · 1.7 KB
/
checkbox.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Backbone-Forms jQuery UI checkbox editor 1.0.0
Copyright (c) 2016 Tomasz Jakub Rup
https://github.com/tomi77/backbone-forms-jquery-ui
Released under the MIT license
*/
(function(root, factory) {
/* istanbul ignore next */
switch (false) {
case !(typeof define === 'function' && define.amd):
define(['backbone-forms', 'jquery-ui/widgets/checkboxradio'], factory);
break;
case typeof exports !== 'object':
require('jquery-ui/widgets/checkboxradio');
factory(require('backbone-forms'));
break;
default:
factory(root.Backbone.Form);
}
})(this, function(Form) {
Form.editors['jqueryui.checkbox'] = Form.editors.Checkbox.extend({
className: 'bbf-jui-checkbox',
initialize: function(options) {
var $label, ref;
Form.editors.Checkbox.prototype.initialize.call(this, options);
this.editorOptions = this.schema.editorOptions || {};
ref = [this.$el, Backbone.$('<div>'), Backbone.$("<label for='" + this.id + "'>")], this.$input = ref[0], this.$el = ref[1], $label = ref[2];
this.el = this.$el[0];
$label.html(' ');
this.$el.html(this.$input);
this.$el.append($label);
},
render: function() {
this.$input.checkboxradio(this.editorOptions);
return Form.editors.Checkbox.prototype.render.call(this);
},
getValue: function() {
return this.$input.prop('checked');
},
setValue: function(value) {
this.$input.prop('checked', value === true);
},
focus: function() {
if (this.hasFocus) {
return;
}
this.$input.focus();
},
blur: function() {
if (!this.hasFocus) {
return;
}
this.$input.blur();
}
});
});