CheckBox.js 3.7 KB

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