diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js')
-rw-r--r-- | lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js b/lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js new file mode 100644 index 000000000..dabd07928 --- /dev/null +++ b/lib/dijit/form/_ToggleButtonMixin.js.uncompressed.js @@ -0,0 +1,55 @@ +define("dijit/form/_ToggleButtonMixin", [ + "dojo/_base/declare", // declare + "dojo/dom-attr" // domAttr.set +], function(declare, domAttr){ + +// module: +// dijit/form/_ToggleButtonMixin + +return declare("dijit.form._ToggleButtonMixin", null, { + // summary: + // A mixin to provide functionality to allow a button that can be in two states (checked or not). + + // checked: Boolean + // Corresponds to the native HTML `<input>` element's attribute. + // In markup, specified as "checked='checked'" or just "checked". + // True if the button is depressed, or the checkbox is checked, + // or the radio button is selected, etc. + checked: false, + + // aria-pressed for toggle buttons, and aria-checked for checkboxes + _aria_attr: "aria-pressed", + + _onClick: function(/*Event*/ evt){ + var original = this.checked; + this._set('checked', !original); // partially set the toggled value, assuming the toggle will work, so it can be overridden in the onclick handler + var ret = this.inherited(arguments); // the user could reset the value here + this.set('checked', ret ? this.checked : original); // officially set the toggled or user value, or reset it back + return ret; + }, + + _setCheckedAttr: function(/*Boolean*/ value, /*Boolean?*/ priorityChange){ + this._set("checked", value); + var node = this.focusNode || this.domNode; + domAttr.set(node, "checked", !!value); // "mixed" -> true + if(value){ + node.setAttribute("checked", ""); + }else{ + node.removeAttribute("checked"); + } + node.setAttribute(this._aria_attr, String(value)); // aria values should be strings + this._handleOnChange(value, priorityChange); + }, + + reset: function(){ + // summary: + // Reset the widget's value to what it was at initialization time + + this._hasBeenBlurred = false; + + // set checked state to original setting + this.set('checked', this.params.checked || false); + } +}); + +}); |