CheckBox.js.uncompressed.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. require({cache:{
  2. 'url:dijit/form/templates/CheckBox.html':"<div class=\"dijit dijitReset dijitInline\" role=\"presentation\"\n\t><input\n\t \t${!nameAttrSetting} type=\"${type}\" role=\"${type}\" aria-checked=\"false\" ${checkedAttrSetting}\n\t\tclass=\"dijitReset dijitCheckBoxInput\"\n\t\tdata-dojo-attach-point=\"focusNode\"\n\t \tdata-dojo-attach-event=\"onclick:_onClick\"\n/></div>\n"}});
  3. define("dijit/form/CheckBox", [
  4. "require",
  5. "dojo/_base/declare", // declare
  6. "dojo/dom-attr", // domAttr.set
  7. "dojo/has", // has("dijit-legacy-requires")
  8. "dojo/query", // query
  9. "dojo/ready",
  10. "./ToggleButton",
  11. "./_CheckBoxMixin",
  12. "dojo/text!./templates/CheckBox.html",
  13. "dojo/NodeList-dom" // NodeList.addClass/removeClass
  14. ], function(require, declare, domAttr, has, query, ready, ToggleButton, _CheckBoxMixin, template){
  15. // module:
  16. // dijit/form/CheckBox
  17. // Back compat w/1.6, remove for 2.0
  18. if(has("dijit-legacy-requires")){
  19. ready(0, function(){
  20. var requires = ["dijit/form/RadioButton"];
  21. require(requires); // use indirection so modules not rolled into a build
  22. });
  23. }
  24. return declare("dijit.form.CheckBox", [ToggleButton, _CheckBoxMixin], {
  25. // summary:
  26. // Same as an HTML checkbox, but with fancy styling.
  27. //
  28. // description:
  29. // User interacts with real html inputs.
  30. // On onclick (which occurs by mouse click, space-bar, or
  31. // using the arrow keys to switch the selected radio button),
  32. // we update the state of the checkbox/radio.
  33. //
  34. // There are two modes:
  35. //
  36. // 1. High contrast mode
  37. // 2. Normal mode
  38. //
  39. // In case 1, the regular html inputs are shown and used by the user.
  40. // In case 2, the regular html inputs are invisible but still used by
  41. // the user. They are turned quasi-invisible and overlay the background-image.
  42. templateString: template,
  43. baseClass: "dijitCheckBox",
  44. _setValueAttr: function(/*String|Boolean*/ newValue, /*Boolean*/ priorityChange){
  45. // summary:
  46. // Handler for value= attribute to constructor, and also calls to
  47. // set('value', val).
  48. // description:
  49. // During initialization, just saves as attribute to the `<input type=checkbox>`.
  50. //
  51. // After initialization,
  52. // when passed a boolean, controls whether or not the CheckBox is checked.
  53. // If passed a string, changes the value attribute of the CheckBox (the one
  54. // specified as "value" when the CheckBox was constructed
  55. // (ex: `<input data-dojo-type="dijit/CheckBox" value="chicken">`).
  56. //
  57. // `widget.set('value', string)` will check the checkbox and change the value to the
  58. // specified string.
  59. //
  60. // `widget.set('value', boolean)` will change the checked state.
  61. if(typeof newValue == "string"){
  62. this.inherited(arguments);
  63. newValue = true;
  64. }
  65. if(this._created){
  66. this.set('checked', newValue, priorityChange);
  67. }
  68. },
  69. _getValueAttr: function(){
  70. // summary:
  71. // Hook so get('value') works.
  72. // description:
  73. // If the CheckBox is checked, returns the value attribute.
  74. // Otherwise returns false.
  75. return (this.checked ? this.value : false);
  76. },
  77. // Override behavior from Button, since we don't have an iconNode
  78. _setIconClassAttr: null,
  79. postMixInProperties: function(){
  80. this.inherited(arguments);
  81. // Need to set initial checked state as part of template, so that form submit works.
  82. // domAttr.set(node, "checked", bool) doesn't work on IE until node has been attached
  83. // to <body>, see #8666
  84. this.checkedAttrSetting = this.checked ? "checked" : "";
  85. },
  86. _fillContent: function(){
  87. // Override Button::_fillContent() since it doesn't make sense for CheckBox,
  88. // since CheckBox doesn't even have a container
  89. },
  90. _onFocus: function(){
  91. if(this.id){
  92. query("label[for='"+this.id+"']").addClass("dijitFocusedLabel");
  93. }
  94. this.inherited(arguments);
  95. },
  96. _onBlur: function(){
  97. if(this.id){
  98. query("label[for='"+this.id+"']").removeClass("dijitFocusedLabel");
  99. }
  100. this.inherited(arguments);
  101. }
  102. });
  103. });