2150 |
mathias |
1 |
if(!dojo._hasResource["dijit.form.CheckBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dijit.form.CheckBox"] = true;
|
|
|
3 |
dojo.provide("dijit.form.CheckBox");
|
|
|
4 |
|
|
|
5 |
dojo.require("dijit.form.Button");
|
|
|
6 |
|
|
|
7 |
dojo.declare(
|
|
|
8 |
"dijit.form.CheckBox",
|
|
|
9 |
dijit.form.ToggleButton,
|
|
|
10 |
{
|
|
|
11 |
// summary:
|
|
|
12 |
// Same as an HTML checkbox, but with fancy styling.
|
|
|
13 |
//
|
|
|
14 |
// description:
|
|
|
15 |
// User interacts with real html inputs.
|
|
|
16 |
// On onclick (which occurs by mouse click, space-bar, or
|
|
|
17 |
// using the arrow keys to switch the selected radio button),
|
|
|
18 |
// we update the state of the checkbox/radio.
|
|
|
19 |
//
|
|
|
20 |
// There are two modes:
|
|
|
21 |
// 1. High contrast mode
|
|
|
22 |
// 2. Normal mode
|
|
|
23 |
// In case 1, the regular html inputs are shown and used by the user.
|
|
|
24 |
// In case 2, the regular html inputs are invisible but still used by
|
|
|
25 |
// the user. They are turned quasi-invisible and overlay the background-image.
|
|
|
26 |
|
|
|
27 |
templateString:"<fieldset class=\"dijitReset dijitInline\" waiRole=\"presentation\"\n\t><input\n\t \ttype=\"${type}\" name=\"${name}\"\n\t\tclass=\"dijitReset dijitCheckBoxInput\"\n\t\tdojoAttachPoint=\"inputNode,focusNode\"\n\t \tdojoAttachEvent=\"onmouseover:_onMouse,onmouseout:_onMouse,onclick:_onClick\"\n/></fieldset>\n",
|
|
|
28 |
|
|
|
29 |
baseClass: "dijitCheckBox",
|
|
|
30 |
|
|
|
31 |
// Value of "type" attribute for <input>
|
|
|
32 |
type: "checkbox",
|
|
|
33 |
|
|
|
34 |
// value: Value
|
|
|
35 |
// equivalent to value field on normal checkbox (if checked, the value is passed as
|
|
|
36 |
// the value when form is submitted)
|
|
|
37 |
value: "on",
|
|
|
38 |
|
|
|
39 |
postCreate: function(){
|
|
|
40 |
dojo.setSelectable(this.inputNode, false);
|
|
|
41 |
this.setChecked(this.checked);
|
|
|
42 |
this.inherited(arguments);
|
|
|
43 |
},
|
|
|
44 |
|
|
|
45 |
setChecked: function(/*Boolean*/ checked){
|
|
|
46 |
if(dojo.isIE){
|
|
|
47 |
if(checked){ this.inputNode.setAttribute('checked', 'checked'); }
|
|
|
48 |
else{ this.inputNode.removeAttribute('checked'); }
|
|
|
49 |
}else{ this.inputNode.checked = checked; }
|
|
|
50 |
this.inherited(arguments);
|
|
|
51 |
},
|
|
|
52 |
|
|
|
53 |
setValue: function(/*String*/ value){
|
|
|
54 |
if(value == null){ value = ""; }
|
|
|
55 |
this.inputNode.value = value;
|
|
|
56 |
dijit.form.CheckBox.superclass.setValue.call(this,value);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
);
|
|
|
60 |
|
|
|
61 |
dojo.declare(
|
|
|
62 |
"dijit.form.RadioButton",
|
|
|
63 |
dijit.form.CheckBox,
|
|
|
64 |
{
|
|
|
65 |
// summary:
|
|
|
66 |
// Same as an HTML radio, but with fancy styling.
|
|
|
67 |
//
|
|
|
68 |
// description:
|
|
|
69 |
// Implementation details
|
|
|
70 |
//
|
|
|
71 |
// Specialization:
|
|
|
72 |
// We keep track of dijit radio groups so that we can update the state
|
|
|
73 |
// of all the siblings (the "context") in a group based on input
|
|
|
74 |
// events. We don't rely on browser radio grouping.
|
|
|
75 |
|
|
|
76 |
type: "radio",
|
|
|
77 |
baseClass: "dijitRadio",
|
|
|
78 |
|
|
|
79 |
// This shared object keeps track of all widgets, grouped by name
|
|
|
80 |
_groups: {},
|
|
|
81 |
|
|
|
82 |
postCreate: function(){
|
|
|
83 |
// add this widget to _groups
|
|
|
84 |
(this._groups[this.name] = this._groups[this.name] || []).push(this);
|
|
|
85 |
|
|
|
86 |
this.inherited(arguments);
|
|
|
87 |
},
|
|
|
88 |
|
|
|
89 |
uninitialize: function(){
|
|
|
90 |
// remove this widget from _groups
|
|
|
91 |
dojo.forEach(this._groups[this.name], function(widget, i, arr){
|
|
|
92 |
if(widget === this){
|
|
|
93 |
arr.splice(i, 1);
|
|
|
94 |
return;
|
|
|
95 |
}
|
|
|
96 |
}, this);
|
|
|
97 |
},
|
|
|
98 |
|
|
|
99 |
setChecked: function(/*Boolean*/ checked){
|
|
|
100 |
// If I am being checked then have to deselect currently checked radio button
|
|
|
101 |
if(checked){
|
|
|
102 |
dojo.forEach(this._groups[this.name], function(widget){
|
|
|
103 |
if(widget != this && widget.checked){
|
|
|
104 |
widget.setChecked(false);
|
|
|
105 |
}
|
|
|
106 |
}, this);
|
|
|
107 |
}
|
|
|
108 |
this.inherited(arguments);
|
|
|
109 |
},
|
|
|
110 |
|
|
|
111 |
_clicked: function(/*Event*/ e){
|
|
|
112 |
if(!this.checked){
|
|
|
113 |
this.setChecked(true);
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
);
|
|
|
118 |
|
|
|
119 |
}
|