| 1 |
define(["dojo/_base/kernel","dojo/_base/declare","dojo/_base/html","dojo/_base/lang","dojo/_base/query", |
| 2 |
"dijit/_Widget","dijit/_Templated","dijit/_Contained","dijit/layout/StackContainer", |
| 3 |
"dojo/fx/easing","dojo/_base/fx","dojo/dom-construct","dojo/dom-class"],function( |
| 4 |
kernel,declare,html,lang,query,Widget,Templated,Contained,StackContainer,easing,baseFx,domConstruct,domClass){ |
| 5 |
|
| 6 |
kernel.experimental("dojox.layout.RadioGroup"); |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var RadioGroup = declare("dojox.layout.RadioGroup",[StackContainer,Templated],{ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
duration: 750, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
hasButtons: false, |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
buttonClass: "dojox.layout._RadioButton", |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
templateString: '<div class="dojoxRadioGroup">' |
| 40 |
+' <div dojoAttachPoint="buttonHolder" style="display:none;">' |
| 41 |
+' <table class="dojoxRadioButtons"><tbody><tr class="dojoxRadioButtonRow" dojoAttachPoint="buttonNode"></tr></tbody></table>' |
| 42 |
+' </div>' |
| 43 |
+' <div class="dojoxRadioView" dojoAttachPoint="containerNode"></div>' |
| 44 |
+'</div>', |
| 45 |
|
| 46 |
startup: function(){ |
| 47 |
|
| 48 |
|
| 49 |
this.inherited(arguments); |
| 50 |
this._children = this.getChildren(); |
| 51 |
this._buttons = this._children.length; |
| 52 |
this._size = html.coords(this.containerNode); |
| 53 |
if(this.hasButtons){ |
| 54 |
html.style(this.buttonHolder, "display", "block"); |
| 55 |
} |
| 56 |
}, |
| 57 |
|
| 58 |
_setupChild: function(child){ |
| 59 |
|
| 60 |
|
| 61 |
html.style(child.domNode, "position", "absolute"); |
| 62 |
if(this.hasButtons){ |
| 63 |
|
| 64 |
var tmp = this.buttonNode.appendChild(domConstruct.create('td')); |
| 65 |
var n = domConstruct.create("div", null, tmp), |
| 66 |
_Button = lang.getObject(this.buttonClass), |
| 67 |
tmpw = new _Button({ |
| 68 |
label: child.title, |
| 69 |
page: child |
| 70 |
}, n) |
| 71 |
; |
| 72 |
|
| 73 |
lang.mixin(child, { _radioButton: tmpw }); |
| 74 |
tmpw.startup(); |
| 75 |
} |
| 76 |
child.domNode.style.display = "none"; |
| 77 |
}, |
| 78 |
|
| 79 |
removeChild: function(child){ |
| 80 |
if(this.hasButtons && child._radioButton){ |
| 81 |
child._radioButton.destroy(); |
| 82 |
delete child._radioButton; |
| 83 |
} |
| 84 |
this.inherited(arguments); |
| 85 |
}, |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
_transition: function( newWidget, oldWidget){ |
| 90 |
|
| 91 |
|
| 92 |
this._showChild(newWidget); |
| 93 |
if(oldWidget){ |
| 94 |
this._hideChild(oldWidget); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
if(this.doLayout && newWidget.resize){ |
| 100 |
newWidget.resize(this._containerContentBox || this._contentBox); |
| 101 |
} |
| 102 |
}, |
| 103 |
|
| 104 |
_showChild: function( page){ |
| 105 |
|
| 106 |
|
| 107 |
var children = this.getChildren(); |
| 108 |
page.isFirstChild = (page == children[0]); |
| 109 |
page.isLastChild = (page == children[children.length-1]); |
| 110 |
page.selected = true; |
| 111 |
|
| 112 |
page.domNode.style.display=""; |
| 113 |
|
| 114 |
if(page._onShow){ |
| 115 |
page._onShow(); |
| 116 |
}else if(page.onShow){ |
| 117 |
page.onShow(); |
| 118 |
} |
| 119 |
}, |
| 120 |
|
| 121 |
_hideChild: function( page){ |
| 122 |
|
| 123 |
|
| 124 |
page.selected = false; |
| 125 |
page.domNode.style.display="none"; |
| 126 |
if(page.onHide){ |
| 127 |
page.onHide(); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
}); |
| 132 |
|
| 133 |
declare("dojox.layout.RadioGroupFade", RadioGroup, { |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
_hideChild: function(page){ |
| 138 |
|
| 139 |
|
| 140 |
baseFx.fadeOut({ |
| 141 |
node:page.domNode, |
| 142 |
duration:this.duration, |
| 143 |
onEnd: lang.hitch(this,"inherited", arguments, arguments) |
| 144 |
}).play(); |
| 145 |
}, |
| 146 |
|
| 147 |
_showChild: function(page){ |
| 148 |
|
| 149 |
|
| 150 |
this.inherited(arguments); |
| 151 |
html.style(page.domNode, "opacity", 0); |
| 152 |
baseFx.fadeIn({ |
| 153 |
node:page.domNode, |
| 154 |
duration:this.duration |
| 155 |
}).play(); |
| 156 |
} |
| 157 |
}); |
| 158 |
|
| 159 |
declare("dojox.layout.RadioGroupSlide", RadioGroup, { |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
easing: "dojo.fx.easing.backOut", |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
zTop: 99, |
| 175 |
|
| 176 |
constructor: function(){ |
| 177 |
if(lang.isString(this.easing)){ |
| 178 |
this.easing = lang.getObject(this.easing); |
| 179 |
} |
| 180 |
}, |
| 181 |
|
| 182 |
_positionChild: function(page){ |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
if(!this._size){ return; } |
| 188 |
|
| 189 |
|
| 190 |
var rA = true, rB = true; |
| 191 |
switch(page.slideFrom){ |
| 192 |
case "bottom" : rB = !rB; break; |
| 193 |
case "right" : rA = !rA; rB = !rB; break; |
| 194 |
case "top" : break; |
| 195 |
case "left" : rA = !rA; break; |
| 196 |
default: |
| 197 |
rA = Math.round(Math.random()); |
| 198 |
rB = Math.round(Math.random()); |
| 199 |
break; |
| 200 |
} |
| 201 |
var prop = rA ? "top" : "left", |
| 202 |
val = (rB ? "-" : "") + (this._size[rA ? "h" : "w" ] + 20) + "px"; |
| 203 |
|
| 204 |
html.style(page.domNode, prop, val); |
| 205 |
|
| 206 |
}, |
| 207 |
|
| 208 |
_showChild: function(page){ |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
var children = this.getChildren(); |
| 213 |
page.isFirstChild = (page == children[0]); |
| 214 |
page.isLastChild = (page == children[children.length-1]); |
| 215 |
page.selected = true; |
| 216 |
|
| 217 |
html.style(page.domNode,{ |
| 218 |
zIndex: this.zTop, display:"" |
| 219 |
}); |
| 220 |
|
| 221 |
if(this._anim && this._anim.status()=="playing"){ |
| 222 |
this._anim.gotoPercent(100,true); |
| 223 |
} |
| 224 |
|
| 225 |
this._anim = baseFx.animateProperty({ |
| 226 |
node:page.domNode, |
| 227 |
properties: { |
| 228 |
left: 0, |
| 229 |
top: 0 |
| 230 |
}, |
| 231 |
duration: this.duration, |
| 232 |
easing: this.easing, |
| 233 |
onEnd: lang.hitch(page, function(){ |
| 234 |
if(this.onShow){ this.onShow(); } |
| 235 |
if(this._onShow){ this._onShow(); } |
| 236 |
}), |
| 237 |
beforeBegin: lang.hitch(this, "_positionChild", page) |
| 238 |
}); |
| 239 |
this._anim.play(); |
| 240 |
}, |
| 241 |
|
| 242 |
_hideChild: function(page){ |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
page.selected = false; |
| 247 |
page.domNode.style.zIndex = this.zTop - 1; |
| 248 |
if(page.onHide){ |
| 249 |
page.onHide(); |
| 250 |
} |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
}); |
| 255 |
|
| 256 |
declare("dojox.layout._RadioButton",[Widget,Templated,Contained],{ |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
label: "", |
| 265 |
|
| 266 |
|
| 267 |
page: null, |
| 268 |
|
| 269 |
templateString: '<div dojoAttachPoint="focusNode" class="dojoxRadioButton"><span dojoAttachPoint="titleNode" class="dojoxRadioButtonLabel">${label}</span></div>', |
| 270 |
|
| 271 |
startup: function(){ |
| 272 |
|
| 273 |
|
| 274 |
this.connect(this.domNode, "onmouseenter", "_onMouse"); |
| 275 |
}, |
| 276 |
|
| 277 |
_onMouse: function(e){ |
| 278 |
|
| 279 |
|
| 280 |
this.getParent().selectChild(this.page); |
| 281 |
this._clearSelected(); |
| 282 |
domClass.add(this.domNode,"dojoxRadioButtonSelected"); |
| 283 |
|
| 284 |
}, |
| 285 |
|
| 286 |
_clearSelected: function(){ |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
query(".dojoxRadioButtonSelected", this.domNode.parentNode.parentNode) |
| 293 |
.removeClass("dojoxRadioButtonSelected") |
| 294 |
; |
| 295 |
} |
| 296 |
|
| 297 |
}); |
| 298 |
|
| 299 |
lang.extend(Widget,{ |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
slideFrom: "random" |
| 306 |
}) |
| 307 |
}); |