2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.layout.RadioGroup"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.layout.RadioGroup"] = true;
|
|
|
3 |
dojo.provide("dojox.layout.RadioGroup");
|
|
|
4 |
dojo.experimental("dojox.layout.RadioGroup");
|
|
|
5 |
//
|
|
|
6 |
// dojox.layout.RadioGroup - an experimental (probably poorly named) Layout widget extending StackContainer
|
|
|
7 |
// that accepts ContentPanes as children, and applies aesthetically pleasing responsive transition animations
|
|
|
8 |
// attached to :hover of the Buttons created.
|
|
|
9 |
//
|
|
|
10 |
// FIXME: take the Buttons out of the root template, and allow layoutAlign or similar attrib to use a different
|
|
|
11 |
// template, or build the template dynamically?
|
|
|
12 |
//
|
|
|
13 |
dojo.require("dijit._Widget");
|
|
|
14 |
dojo.require("dijit._Templated");
|
|
|
15 |
dojo.require("dijit._Container");
|
|
|
16 |
dojo.require("dijit.layout.StackContainer");
|
|
|
17 |
dojo.require("dojox.fx.easing");
|
|
|
18 |
|
|
|
19 |
dojo.declare("dojox.layout.RadioGroup",
|
|
|
20 |
[dijit.layout.StackContainer,dijit._Templated],
|
|
|
21 |
{
|
|
|
22 |
// summary: A Container that turns its Layout Children into a single Pane and transitions between states
|
|
|
23 |
// onHover of the button
|
|
|
24 |
//
|
|
|
25 |
|
|
|
26 |
// duration: Int
|
|
|
27 |
// used for Fade and Slide RadioGroup's, the duration to run the transition animation. does not affect anything
|
|
|
28 |
// in default RadioGroup
|
|
|
29 |
duration: 750,
|
|
|
30 |
|
|
|
31 |
// hasButtons: Boolean
|
|
|
32 |
// toggles internal button making on or off
|
|
|
33 |
hasButtons: true,
|
|
|
34 |
|
|
|
35 |
// templateString: String
|
|
|
36 |
// the template for our container
|
|
|
37 |
templateString: '<div class="dojoxRadioGroup">'
|
|
|
38 |
+' <div dojoAttachPoint="buttonHolder" style="display:none;">'
|
|
|
39 |
+' <table class="dojoxRadioButtons"><tbody><tr class="dojoxRadioButtonRow" dojoAttachPoint="buttonNode"></tr></tbody></table>'
|
|
|
40 |
+' </div>'
|
|
|
41 |
+' <div class="dojoxRadioView" dojoAttachPoint="containerNode"></div>'
|
|
|
42 |
+'</div>',
|
|
|
43 |
|
|
|
44 |
startup: function(){
|
|
|
45 |
// summary: scan the container for children, and make "tab buttons" for them
|
|
|
46 |
this.inherited("startup",arguments);
|
|
|
47 |
this._children = this.getChildren();
|
|
|
48 |
this._buttons = this._children.length;
|
|
|
49 |
this._size = dojo.coords(this.containerNode);
|
|
|
50 |
if(this.hasButtons){
|
|
|
51 |
dojo.style(this.buttonHolder,"display","block");
|
|
|
52 |
dojo.forEach(this._children,this._makeButton,this);
|
|
|
53 |
}
|
|
|
54 |
},
|
|
|
55 |
|
|
|
56 |
// private:
|
|
|
57 |
_makeButton: function(/* DomNode */n){
|
|
|
58 |
// summary: creates a hover button for a child node of the RadioGroup
|
|
|
59 |
dojo.style(n.domNode,"position","absolute");
|
|
|
60 |
var tmp = document.createElement('td');
|
|
|
61 |
this.buttonNode.appendChild(tmp);
|
|
|
62 |
var tmpt = tmp.appendChild(document.createElement('div'));
|
|
|
63 |
var tmpw = new dojox.layout._RadioButton({
|
|
|
64 |
label: n.title,
|
|
|
65 |
page: n
|
|
|
66 |
},tmpt);
|
|
|
67 |
tmpw.startup();
|
|
|
68 |
},
|
|
|
69 |
|
|
|
70 |
// FIXME: shouldn't have to rewriting these, need to take styling out of _showChild and _hideChild
|
|
|
71 |
// and use classes on the domNode in _transition or something similar (in StackContainer)
|
|
|
72 |
_transition: function(/*Widget*/newWidget, /*Widget*/oldWidget){
|
|
|
73 |
// summary: called when StackContainer receives a selectChild call, used to transition the panes.
|
|
|
74 |
this._showChild(newWidget);
|
|
|
75 |
if(oldWidget){
|
|
|
76 |
this._hideChild(oldWidget);
|
|
|
77 |
}
|
|
|
78 |
// Size the new widget, in case this is the first time it's being shown,
|
|
|
79 |
// or I have been resized since the last time it was shown.
|
|
|
80 |
// page must be visible for resizing to work
|
|
|
81 |
if(this.doLayout && newWidget.resize){
|
|
|
82 |
newWidget.resize(this._containerContentBox || this._contentBox);
|
|
|
83 |
}
|
|
|
84 |
},
|
|
|
85 |
|
|
|
86 |
_showChild: function(/*Widget*/ page){
|
|
|
87 |
// summary: show the selected child widget
|
|
|
88 |
var children = this.getChildren();
|
|
|
89 |
page.isFirstChild = (page == children[0]);
|
|
|
90 |
page.isLastChild = (page == children[children.length-1]);
|
|
|
91 |
page.selected = true;
|
|
|
92 |
|
|
|
93 |
page.domNode.style.display="";
|
|
|
94 |
|
|
|
95 |
if(page._loadCheck){
|
|
|
96 |
page._loadCheck(); // trigger load in ContentPane
|
|
|
97 |
}
|
|
|
98 |
if(page.onShow){
|
|
|
99 |
page.onShow();
|
|
|
100 |
}
|
|
|
101 |
},
|
|
|
102 |
|
|
|
103 |
_hideChild: function(/*Widget*/ page){
|
|
|
104 |
// summary: hide the specified child widget
|
|
|
105 |
page.selected=false;
|
|
|
106 |
page.domNode.style.display="none";
|
|
|
107 |
if(page.onHide){
|
|
|
108 |
page.onHide();
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
});
|
|
|
113 |
|
|
|
114 |
dojo.declare("dojox.layout.RadioGroupFade",
|
|
|
115 |
dojox.layout.RadioGroup,
|
|
|
116 |
{
|
|
|
117 |
// summary: An extension on a stock RadioGroup, that fades the panes.
|
|
|
118 |
|
|
|
119 |
_hideChild: function(page){
|
|
|
120 |
// summary: hide the specified child widget
|
|
|
121 |
dojo.fadeOut({
|
|
|
122 |
node:page.domNode,
|
|
|
123 |
duration:this.duration,
|
|
|
124 |
onEnd: this.inherited("_hideChild",arguments)
|
|
|
125 |
}).play();
|
|
|
126 |
},
|
|
|
127 |
|
|
|
128 |
_showChild: function(page){
|
|
|
129 |
// summary: show the specified child widget
|
|
|
130 |
this.inherited("_showChild",arguments);
|
|
|
131 |
dojo.style(page.domNode,"opacity",0);
|
|
|
132 |
dojo.fadeIn({
|
|
|
133 |
node:page.domNode,
|
|
|
134 |
duration:this.duration
|
|
|
135 |
}).play();
|
|
|
136 |
}
|
|
|
137 |
});
|
|
|
138 |
|
|
|
139 |
dojo.declare("dojox.layout.RadioGroupSlide",
|
|
|
140 |
dojox.layout.RadioGroup,
|
|
|
141 |
{
|
|
|
142 |
// summary: A Sliding Radio Group
|
|
|
143 |
// description:
|
|
|
144 |
// An extension on a stock RadioGroup widget, sliding the pane
|
|
|
145 |
// into view from being hidden. The entry direction is randomized
|
|
|
146 |
// on each view
|
|
|
147 |
//
|
|
|
148 |
|
|
|
149 |
// easing: dojo._Animation.easing
|
|
|
150 |
// A hook to override the default easing of the pane slides.
|
|
|
151 |
easing: dojox.fx.easing.easeOut,
|
|
|
152 |
|
|
|
153 |
startup: function(){
|
|
|
154 |
// summary: on startup, set each of the panes off-screen (_showChild is called later)
|
|
|
155 |
this.inherited("startup",arguments);
|
|
|
156 |
dojo.forEach(this._children,this._positionChild,this);
|
|
|
157 |
},
|
|
|
158 |
|
|
|
159 |
_positionChild: function(page){
|
|
|
160 |
// summary: randomly set the child out of view
|
|
|
161 |
// description:
|
|
|
162 |
var rA = Math.round(Math.random());
|
|
|
163 |
var rB = Math.round(Math.random());
|
|
|
164 |
dojo.style(page.domNode, rA? "top" : "left", (rB ? "-" : "") + this._size[rA?"h":"w"]+"px");
|
|
|
165 |
},
|
|
|
166 |
|
|
|
167 |
_showChild: function(page){
|
|
|
168 |
// summary: Slide in the selected child widget
|
|
|
169 |
this.inherited("_showChild",arguments);
|
|
|
170 |
if(this._anim && this._anim.status()=="playing"){
|
|
|
171 |
this._anim.gotoPercent(100,true);
|
|
|
172 |
}
|
|
|
173 |
this._anim = dojo.animateProperty({
|
|
|
174 |
node:page.domNode,
|
|
|
175 |
properties: {
|
|
|
176 |
// take a performance hit determinging one of these doesn't get modified
|
|
|
177 |
// but it's better this way than an extra call to mixin in think?
|
|
|
178 |
left: { end:0, unit:"px" },
|
|
|
179 |
top: { end:0, unit:"px" }
|
|
|
180 |
},
|
|
|
181 |
duration:this.duration,
|
|
|
182 |
easing:this.easing
|
|
|
183 |
});
|
|
|
184 |
this._anim.play();
|
|
|
185 |
},
|
|
|
186 |
|
|
|
187 |
_hideChild: function(page){
|
|
|
188 |
// summary: reset the position of the hidden pane out of sight
|
|
|
189 |
this.inherited("_hideChild",arguments);
|
|
|
190 |
this._positionChild(page);
|
|
|
191 |
}
|
|
|
192 |
});
|
|
|
193 |
|
|
|
194 |
dojo.declare("dojox.layout._RadioButton",
|
|
|
195 |
[dijit._Widget,dijit._Templated,dijit._Contained],
|
|
|
196 |
{
|
|
|
197 |
// summary: The Buttons for a RadioGroup
|
|
|
198 |
//
|
|
|
199 |
// description: A private widget used to manipulate the StackContainer (RadioGroup*). Don't create directly.
|
|
|
200 |
//
|
|
|
201 |
|
|
|
202 |
// label: String
|
|
|
203 |
// the Text Label of the button
|
|
|
204 |
label: "",
|
|
|
205 |
|
|
|
206 |
// domNode to tell parent to select
|
|
|
207 |
page: null,
|
|
|
208 |
|
|
|
209 |
templateString: '<div dojoAttachPoint="focusNode" class="dojoxRadioButton"><span dojoAttachPoint="titleNode" class="dojoxRadioButtonLabel">${label}</span></div>',
|
|
|
210 |
|
|
|
211 |
startup: function(){
|
|
|
212 |
// summary: start listening to mouseOver
|
|
|
213 |
this.connect(this.domNode,"onmouseover","_onMouse");
|
|
|
214 |
},
|
|
|
215 |
|
|
|
216 |
_onMouse: function(/* Event */e){
|
|
|
217 |
// summary: set the selected child on hover, and set our hover state class
|
|
|
218 |
this.getParent().selectChild(this.page);
|
|
|
219 |
this._clearSelected();
|
|
|
220 |
dojo.addClass(this.domNode,"dojoxRadioButtonSelected");
|
|
|
221 |
},
|
|
|
222 |
|
|
|
223 |
_clearSelected: function(){
|
|
|
224 |
// summary: remove hover state class from sibling Buttons. This is easier (and more reliable)
|
|
|
225 |
// than setting up an additional connection to onMouseOut
|
|
|
226 |
// FIXME: this relies on the template being [div][span]node[/span][/div]
|
|
|
227 |
dojo.query(".dojoxRadioButtonSelected",this.domNode.parentNode.parentNode).forEach(function(n){
|
|
|
228 |
dojo.removeClass(n,"dojoxRadioButtonSelected");
|
|
|
229 |
});
|
|
|
230 |
}
|
|
|
231 |
});
|
|
|
232 |
|
|
|
233 |
}
|