You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
7.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-form-Checkbox-method-constructor'><span id='Ext-form-Checkbox'>/**
  19. </span></span> * @class Ext.form.Checkbox
  20. * @extends Ext.form.Field
  21. * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
  22. * @constructor
  23. * Creates a new Checkbox
  24. * @param {Object} config Configuration options
  25. * @xtype checkbox
  26. */
  27. Ext.form.Checkbox = Ext.extend(Ext.form.Field, {
  28. <span id='Ext-form-Checkbox-cfg-focusClass'> /**
  29. </span> * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
  30. */
  31. focusClass : undefined,
  32. <span id='Ext-form-Checkbox-cfg-fieldClass'> /**
  33. </span> * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to 'x-form-field')
  34. */
  35. fieldClass : 'x-form-field',
  36. <span id='Ext-form-Checkbox-cfg-checked'> /**
  37. </span> * @cfg {Boolean} checked &lt;tt&gt;true&lt;/tt&gt; if the checkbox should render initially checked (defaults to &lt;tt&gt;false&lt;/tt&gt;)
  38. */
  39. checked : false,
  40. <span id='Ext-form-Checkbox-cfg-boxLabel'> /**
  41. </span> * @cfg {String} boxLabel The text that appears beside the checkbox
  42. */
  43. boxLabel: '&amp;#160;',
  44. <span id='Ext-form-Checkbox-cfg-autoCreate'> /**
  45. </span> * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
  46. * {tag: 'input', type: 'checkbox', autocomplete: 'off'})
  47. */
  48. defaultAutoCreate : { tag: 'input', type: 'checkbox', autocomplete: 'off'},
  49. <span id='Ext-form-Checkbox-cfg-inputValue'> /**
  50. </span> * @cfg {String} inputValue The value that should go into the generated input element's value attribute
  51. */
  52. <span id='Ext-form-Checkbox-cfg-handler'> /**
  53. </span> * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of
  54. * handling the check event). The handler is passed the following parameters:
  55. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  56. * &lt;li&gt;&lt;b&gt;checkbox&lt;/b&gt; : Ext.form.Checkbox&lt;div class=&quot;sub-desc&quot;&gt;The Checkbox being toggled.&lt;/div&gt;&lt;/li&gt;
  57. * &lt;li&gt;&lt;b&gt;checked&lt;/b&gt; : Boolean&lt;div class=&quot;sub-desc&quot;&gt;The new checked state of the checkbox.&lt;/div&gt;&lt;/li&gt;
  58. * &lt;/ul&gt;&lt;/div&gt;
  59. */
  60. <span id='Ext-form-Checkbox-cfg-scope'> /**
  61. </span> * @cfg {Object} scope An object to use as the scope ('this' reference) of the {@link #handler} function
  62. * (defaults to this Checkbox).
  63. */
  64. <span id='Ext-form-Checkbox-property-actionMode'> // private
  65. </span> actionMode : 'wrap',
  66. <span id='Ext-form-Checkbox-method-initComponent'> // private
  67. </span> initComponent : function(){
  68. Ext.form.Checkbox.superclass.initComponent.call(this);
  69. this.addEvents(
  70. <span id='Ext-form-Checkbox-event-check'> /**
  71. </span> * @event check
  72. * Fires when the checkbox is checked or unchecked.
  73. * @param {Ext.form.Checkbox} this This checkbox
  74. * @param {Boolean} checked The new checked value
  75. */
  76. 'check'
  77. );
  78. },
  79. <span id='Ext-form-Checkbox-method-onResize'> // private
  80. </span> onResize : function(){
  81. Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
  82. if(!this.boxLabel &amp;&amp; !this.fieldLabel){
  83. this.el.alignTo(this.wrap, 'c-c');
  84. }
  85. },
  86. <span id='Ext-form-Checkbox-method-initEvents'> // private
  87. </span> initEvents : function(){
  88. Ext.form.Checkbox.superclass.initEvents.call(this);
  89. this.mon(this.el, {
  90. scope: this,
  91. click: this.onClick,
  92. change: this.onClick
  93. });
  94. },
  95. <span id='Ext-form-Checkbox-method-markInvalid'> /**
  96. </span> * @hide
  97. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  98. * @method
  99. */
  100. markInvalid : Ext.emptyFn,
  101. <span id='Ext-form-Checkbox-method-clearInvalid'> /**
  102. </span> * @hide
  103. * Overridden and disabled. The editor element does not support standard valid/invalid marking.
  104. * @method
  105. */
  106. clearInvalid : Ext.emptyFn,
  107. <span id='Ext-form-Checkbox-method-onRender'> // private
  108. </span> onRender : function(ct, position){
  109. Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
  110. if(this.inputValue !== undefined){
  111. this.el.dom.value = this.inputValue;
  112. }
  113. this.wrap = this.el.wrap({cls: 'x-form-check-wrap'});
  114. if(this.boxLabel){
  115. this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
  116. }
  117. if(this.checked){
  118. this.setValue(true);
  119. }else{
  120. this.checked = this.el.dom.checked;
  121. }
  122. // Need to repaint for IE, otherwise positioning is broken
  123. if (Ext.isIEQuirks) {
  124. this.wrap.repaint();
  125. }
  126. this.resizeEl = this.positionEl = this.wrap;
  127. },
  128. <span id='Ext-form-Checkbox-method-onDestroy'> // private
  129. </span> onDestroy : function(){
  130. Ext.destroy(this.wrap);
  131. Ext.form.Checkbox.superclass.onDestroy.call(this);
  132. },
  133. <span id='Ext-form-Checkbox-method-initValue'> // private
  134. </span> initValue : function() {
  135. this.originalValue = this.getValue();
  136. },
  137. <span id='Ext-form-Checkbox-method-getValue'> /**
  138. </span> * Returns the checked state of the checkbox.
  139. * @return {Boolean} True if checked, else false
  140. */
  141. getValue : function(){
  142. if(this.rendered){
  143. return this.el.dom.checked;
  144. }
  145. return this.checked;
  146. },
  147. <span id='Ext-form-Checkbox-method-onClick'> // private
  148. </span> onClick : function(){
  149. if(this.el.dom.checked != this.checked){
  150. this.setValue(this.el.dom.checked);
  151. }
  152. },
  153. <span id='Ext-form-Checkbox-method-setValue'> /**
  154. </span> * Sets the checked state of the checkbox, fires the 'check' event, and calls a
  155. * &lt;code&gt;{@link #handler}&lt;/code&gt; (if configured).
  156. * @param {Boolean/String} checked The following values will check the checkbox:
  157. * &lt;code&gt;true, 'true', '1', or 'on'&lt;/code&gt;. Any other value will uncheck the checkbox.
  158. * @return {Ext.form.Field} this
  159. */
  160. setValue : function(v){
  161. var checked = this.checked,
  162. inputVal = this.inputValue;
  163. if (v === false) {
  164. this.checked = false;
  165. } else {
  166. this.checked = (v === true || v === 'true' || v == '1' || (inputVal ? v == inputVal : String(v).toLowerCase() == 'on'));
  167. }
  168. if(this.rendered){
  169. this.el.dom.checked = this.checked;
  170. this.el.dom.defaultChecked = this.checked;
  171. }
  172. if(checked != this.checked){
  173. this.fireEvent('check', this, this.checked);
  174. if(this.handler){
  175. this.handler.call(this.scope || this, this, this.checked);
  176. }
  177. }
  178. return this;
  179. }
  180. });
  181. Ext.reg('checkbox', Ext.form.Checkbox);
  182. </pre>
  183. </body>
  184. </html>