]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_RadioButtonMixin.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / form / _RadioButtonMixin.js.uncompressed.js
1 define("dijit/form/_RadioButtonMixin", [
2 "dojo/_base/array", // array.forEach
3 "dojo/_base/declare", // declare
4 "dojo/dom-attr", // domAttr.set
5 "dojo/_base/event", // event.stop
6 "dojo/_base/lang", // lang.hitch
7 "dojo/query", // query
8 "dojo/_base/window", // win.doc
9 "../registry" // registry.getEnclosingWidget
10 ], function(array, declare, domAttr, event, lang, query, win, registry){
11
12 // module:
13 // dijit/form/_RadioButtonMixin
14 // summary:
15 // Mixin to provide widget functionality for an HTML radio button
16
17 return declare("dijit.form._RadioButtonMixin", null, {
18 // summary:
19 // Mixin to provide widget functionality for an HTML radio button
20
21 // type: [private] String
22 // type attribute on <input> node.
23 // Users should not change this value.
24 type: "radio",
25
26 _getRelatedWidgets: function(){
27 // Private function needed to help iterate over all radio buttons in a group.
28 var ary = [];
29 query("input[type=radio]", this.focusNode.form || win.doc).forEach( // can't use name= since query doesn't support [] in the name
30 lang.hitch(this, function(inputNode){
31 if(inputNode.name == this.name && inputNode.form == this.focusNode.form){
32 var widget = registry.getEnclosingWidget(inputNode);
33 if(widget){
34 ary.push(widget);
35 }
36 }
37 })
38 );
39 return ary;
40 },
41
42 _setCheckedAttr: function(/*Boolean*/ value){
43 // If I am being checked then have to deselect currently checked radio button
44 this.inherited(arguments);
45 if(!this._created){ return; }
46 if(value){
47 array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){
48 if(widget != this && widget.checked){
49 widget.set('checked', false);
50 }
51 }));
52 }
53 },
54
55 _onClick: function(/*Event*/ e){
56 if(this.checked || this.disabled){ // nothing to do
57 event.stop(e);
58 return false;
59 }
60 if(this.readOnly){ // ignored by some browsers so we have to resync the DOM elements with widget values
61 event.stop(e);
62 array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){
63 domAttr.set(this.focusNode || this.domNode, 'checked', widget.checked);
64 }));
65 return false;
66 }
67 return this.inherited(arguments);
68 }
69 });
70 });