120 lines
3.4 KiB
JavaScript
120 lines
3.4 KiB
JavaScript
if(!dojo._hasResource["dijit.form.CheckBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
dojo._hasResource["dijit.form.CheckBox"] = true;
|
|
dojo.provide("dijit.form.CheckBox");
|
|
|
|
dojo.require("dijit.form.Button");
|
|
|
|
dojo.declare(
|
|
"dijit.form.CheckBox",
|
|
dijit.form.ToggleButton,
|
|
{
|
|
// summary:
|
|
// Same as an HTML checkbox, but with fancy styling.
|
|
//
|
|
// description:
|
|
// User interacts with real html inputs.
|
|
// On onclick (which occurs by mouse click, space-bar, or
|
|
// using the arrow keys to switch the selected radio button),
|
|
// we update the state of the checkbox/radio.
|
|
//
|
|
// There are two modes:
|
|
// 1. High contrast mode
|
|
// 2. Normal mode
|
|
// In case 1, the regular html inputs are shown and used by the user.
|
|
// In case 2, the regular html inputs are invisible but still used by
|
|
// the user. They are turned quasi-invisible and overlay the background-image.
|
|
|
|
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",
|
|
|
|
baseClass: "dijitCheckBox",
|
|
|
|
// Value of "type" attribute for <input>
|
|
type: "checkbox",
|
|
|
|
// value: Value
|
|
// equivalent to value field on normal checkbox (if checked, the value is passed as
|
|
// the value when form is submitted)
|
|
value: "on",
|
|
|
|
postCreate: function(){
|
|
dojo.setSelectable(this.inputNode, false);
|
|
this.setChecked(this.checked);
|
|
this.inherited(arguments);
|
|
},
|
|
|
|
setChecked: function(/*Boolean*/ checked){
|
|
if(dojo.isIE){
|
|
if(checked){ this.inputNode.setAttribute('checked', 'checked'); }
|
|
else{ this.inputNode.removeAttribute('checked'); }
|
|
}else{ this.inputNode.checked = checked; }
|
|
this.inherited(arguments);
|
|
},
|
|
|
|
setValue: function(/*String*/ value){
|
|
if(value == null){ value = ""; }
|
|
this.inputNode.value = value;
|
|
dijit.form.CheckBox.superclass.setValue.call(this,value);
|
|
}
|
|
}
|
|
);
|
|
|
|
dojo.declare(
|
|
"dijit.form.RadioButton",
|
|
dijit.form.CheckBox,
|
|
{
|
|
// summary:
|
|
// Same as an HTML radio, but with fancy styling.
|
|
//
|
|
// description:
|
|
// Implementation details
|
|
//
|
|
// Specialization:
|
|
// We keep track of dijit radio groups so that we can update the state
|
|
// of all the siblings (the "context") in a group based on input
|
|
// events. We don't rely on browser radio grouping.
|
|
|
|
type: "radio",
|
|
baseClass: "dijitRadio",
|
|
|
|
// This shared object keeps track of all widgets, grouped by name
|
|
_groups: {},
|
|
|
|
postCreate: function(){
|
|
// add this widget to _groups
|
|
(this._groups[this.name] = this._groups[this.name] || []).push(this);
|
|
|
|
this.inherited(arguments);
|
|
},
|
|
|
|
uninitialize: function(){
|
|
// remove this widget from _groups
|
|
dojo.forEach(this._groups[this.name], function(widget, i, arr){
|
|
if(widget === this){
|
|
arr.splice(i, 1);
|
|
return;
|
|
}
|
|
}, this);
|
|
},
|
|
|
|
setChecked: function(/*Boolean*/ checked){
|
|
// If I am being checked then have to deselect currently checked radio button
|
|
if(checked){
|
|
dojo.forEach(this._groups[this.name], function(widget){
|
|
if(widget != this && widget.checked){
|
|
widget.setChecked(false);
|
|
}
|
|
}, this);
|
|
}
|
|
this.inherited(arguments);
|
|
},
|
|
|
|
_clicked: function(/*Event*/ e){
|
|
if(!this.checked){
|
|
this.setChecked(true);
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
}
|