]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/form/CheckBox.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / form / CheckBox.js
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:"<div class=\"dijitReset dijitInline\" waiRole=\"presentation\"\n\t><input\n\t \ttype=\"${type}\" name=\"${name}\"\n\t\tclass=\"dijitReset dijitCheckBoxInput\"\n\t\tdojoAttachPoint=\"focusNode\"\n\t \tdojoAttachEvent=\"onmouseover:_onMouse,onmouseout:_onMouse,onclick:_onClick\"\n/></div>\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                 setValue: function(/*String or Boolean*/ newValue){
40                         // summary:
41                         //              When passed a boolean, controls whether or not the CheckBox is checked.
42                         //              If passed a string, changes the value attribute of the CheckBox (the one
43                         //              specified as "value" when the CheckBox was constructed (ex: <input
44                         //              dojoType="dijit.CheckBox" value="chicken">)
45                         if(typeof newValue == "string"){
46                                 this.setAttribute('value', newValue);
47                                 newValue = true;
48                         }
49                         this.setAttribute('checked', newValue);
50                 },
51
52                 _getValueDeprecated: false, // remove when _FormWidget:_getValueDeprecated is removed
53                 getValue: function(){
54                         // summary:
55                         //              If the CheckBox is checked, returns the value attribute.
56                         //              Otherwise returns false.
57                         return (this.checked ? this.value : false);
58                 },
59
60                 reset: function(){
61                         this.inherited(arguments);
62                         this.setAttribute('value', this._resetValueAttr);
63                 },
64
65                 postCreate: function(){
66                         this.inherited(arguments);
67                         this._resetValueAttr = this.value;
68                 }
69         }
70 );
71
72 dojo.declare(
73         "dijit.form.RadioButton",
74         dijit.form.CheckBox,
75         {
76                 // summary:
77                 //              Same as an HTML radio, but with fancy styling.
78                 //
79                 // description:
80                 // Implementation details
81                 //
82                 // Specialization:
83                 // We keep track of dijit radio groups so that we can update the state
84                 // of all the siblings (the "context") in a group based on input
85                 // events. We don't rely on browser radio grouping.
86
87                 type: "radio",
88                 baseClass: "dijitRadio",
89
90                 // This shared object keeps track of all widgets, grouped by name
91                 _groups: {},
92
93                 postCreate: function(){
94                         // add this widget to _groups
95                         (this._groups[this.name] = this._groups[this.name] || []).push(this);
96
97                         this.inherited(arguments);
98                 },
99
100                 uninitialize: function(){
101                         // remove this widget from _groups
102                         dojo.forEach(this._groups[this.name], function(widget, i, arr){
103                                 if(widget === this){
104                                         arr.splice(i, 1);
105                                         return;
106                                 }
107                         }, this);
108                 },
109
110                 setAttribute: function(/*String*/ attr, /*anything*/ value){
111                         // If I am being checked then have to deselect currently checked radio button
112                         this.inherited(arguments);
113                         switch(attr){
114                                 case "checked":
115                                         if(this.checked){
116                                                 dojo.forEach(this._groups[this.name], function(widget){
117                                                         if(widget != this && widget.checked){
118                                                                 widget.setAttribute('checked', false);
119                                                         }
120                                                 }, this);
121                                         }
122                         }
123                 },
124
125                 _clicked: function(/*Event*/ e){
126                         if(!this.checked){
127                                 this.setAttribute('checked', true);
128                         }
129                 }
130         }
131 );
132
133 }