| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>dojo.NodeList-fx and dojox.fx.ext-dojo.Nodelist | fx add-ons to dojo.query()</title> |
| 6 | |
| 7 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="parseOnLoad:true, isDebug:true"></script> |
| 8 | <style type="text/css"> |
| 9 | @import "../../../dojo/resources/dojo.css"; |
| 10 | @import "../../../dijit/themes/dijit.css"; |
| 11 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 12 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 13 | |
| 14 | .testBoxContainer { |
| 15 | position:relative; |
| 16 | width:418px; |
| 17 | height:240px; |
| 18 | margin-left:50px; |
| 19 | border-top:1px dashed #b7b7b7; |
| 20 | border-bottom:1px dashed #b7b7b7; |
| 21 | } |
| 22 | |
| 23 | .testBox { |
| 24 | position:absolute; |
| 25 | top:0; left:0; |
| 26 | width:50px; |
| 27 | height:50px; |
| 28 | background:#ededed; |
| 29 | border:1px solid #b7b7b7; |
| 30 | -moz-border-radius:6pt; |
| 31 | -webkit-border-radius:5pt; |
| 32 | overflow:hidden; |
| 33 | } |
| 34 | .rowOne { top:0; } |
| 35 | .rowTwo { top:60px; } |
| 36 | .rowThree { top:120px; } |
| 37 | .rowFour { top:180px; } |
| 38 | |
| 39 | .iOne { left:0; } |
| 40 | .iTwo { left:60px; } |
| 41 | .iThree { left:120px; } |
| 42 | .iFour { left:180px; } |
| 43 | .iFive { left:240px; } |
| 44 | .iSix { left:300px; } |
| 45 | .iSeven { left:360px; } |
| 46 | |
| 47 | </style> |
| 48 | <script type="text/javascript"> |
| 49 | |
| 50 | dojo.require("dojox.fx.ext-dojo.NodeList"); |
| 51 | dojo.require("dijit.form.Button"); |
| 52 | dojo.require("dijit.form.RadioButton"); |
| 53 | |
| 54 | // its funny... |
| 55 | var dQuery = dojo.query; |
| 56 | var d$ = dQuery; |
| 57 | |
| 58 | var anim2 = null; |
| 59 | |
| 60 | var init = function(){ |
| 61 | var anim = d$(".rowOne").highlight({ |
| 62 | duration:700, |
| 63 | onEnd: function(){ |
| 64 | d$(".rowTwo").fadeTo({ end: 0.5, |
| 65 | duration:700, |
| 66 | onEnd: function(){ |
| 67 | |
| 68 | anim2 = d$(".rowThree").fadeOut({ |
| 69 | top:20, left:20, |
| 70 | duration:500 |
| 71 | }).play(700); |
| 72 | } |
| 73 | }).play(300); |
| 74 | } |
| 75 | }); |
| 76 | |
| 77 | dojo.connect(anim,"onEnd",function(){ |
| 78 | |
| 79 | var q1v = true; |
| 80 | var q1 = ".iSix"; // colum six |
| 81 | // this will setup a connection on each of the nodes to toggle their fade state |
| 82 | d$(q1).connect("onclick",function(){ |
| 83 | d$(q1)[(q1v ? "fadeOut" : "fadeIn")]().play(); |
| 84 | q1v = !q1v; |
| 85 | }); |
| 86 | |
| 87 | // this highlights all the nodes via a mouseenter event, which automatically |
| 88 | // |
| 89 | d$(".testBox").connect("onmouseenter",function(e){ |
| 90 | dojox.fx.highlight({ node: e.target, duration:250 }).play(); |
| 91 | }); |
| 92 | |
| 93 | |
| 94 | var q3 = ".rowOne.iSeven"; // top right node |
| 95 | d$(q3).connect("onclick",function(){ |
| 96 | d$(q3).sizeTo({ |
| 97 | width:300, height:300, duration:300, |
| 98 | onEnd: function(){ |
| 99 | // FIXME: sizeTo isn't calculating it's start value properly |
| 100 | d$(q3).sizeTo({ width: 50, height:50, duration:115, delay:1000, method:"combine" }).play(); |
| 101 | } |
| 102 | }).play(); |
| 103 | }); |
| 104 | |
| 105 | |
| 106 | |
| 107 | }); |
| 108 | // main animation |
| 109 | anim.play(700); |
| 110 | }; |
| 111 | // start the code |
| 112 | dojo.addOnLoad(init); |
| 113 | |
| 114 | // for our dojo.query() form, some animations take different params which would be kind of difficult |
| 115 | // to make both dynamic and robust and easy to explain. see each function individually in the API |
| 116 | // for the breakdown. just going to hard-code some values in for somet things: |
| 117 | var animArgs = { |
| 118 | // dojo.NodeList-fx ones: |
| 119 | animateProperty: { |
| 120 | properties: { |
| 121 | borderWidth:5, |
| 122 | marginTop:8 |
| 123 | } |
| 124 | |
| 125 | }, |
| 126 | |
| 127 | slideTo: { top:0, left: 0 }, |
| 128 | |
| 129 | // dojox extension ones: |
| 130 | sizeTo: { |
| 131 | width: 75, height:75 |
| 132 | }, |
| 133 | fadeTo: { |
| 134 | end: 0.35 |
| 135 | }, |
| 136 | slideBy: { |
| 137 | top:55, left: 55 |
| 138 | }, |
| 139 | |
| 140 | // mix these into every 'custom query animation' |
| 141 | defaultArgs: { |
| 142 | // duration: 500 //, |
| 143 | // onEnd: function(){ console.log('ended animation') } |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | |
| 149 | </script> |
| 150 | </head> |
| 151 | <body class="tundra"> |
| 152 | |
| 153 | <h1 class="testTitle">NodeList and dojo.query "magic"</h1> |
| 154 | |
| 155 | <div style="width:200px; float:right; padding:10px"> |
| 156 | <h4>stuff going on:</h4> |
| 157 | <ul> |
| 158 | <li>watch the startup cycle</li> |
| 159 | <li>click col 6</li> |
| 160 | <li>click top right box</li> |
| 161 | <li>hover to highlight() node</li> |
| 162 | </ul> |
| 163 | </div> |
| 164 | |
| 165 | <div style="width:200px; float:right; padding:10px"> |
| 166 | <h4>custom query:</h4> |
| 167 | <form id="whichAnim"> |
| 168 | <p> |
| 169 | dojo.query("<input type="text" name="str" id="customStr" value=".noIdHere" size="10" />"); |
| 170 | <br>(dojo:)<br> |
| 171 | <input type="radio" name="g2" id="g2rb1" value="fadeIn" dojoType="dijit.form.RadioButton" checked="checked"/> |
| 172 | <label for="g2rb1">.fadeIn</label><br> |
| 173 | |
| 174 | <input type="radio" name="g2" id="g2rb2" value="fadeOut" dojoType="dijit.form.RadioButton"/> |
| 175 | <label for="g2rb2">.fadeOut</label><br> |
| 176 | |
| 177 | <input type="radio" name="g2" id="g2rb3" value="wipeOut" dojoType="dijit.form.RadioButton"/> |
| 178 | <label for="g2rb3">.wipeOut</label><br> |
| 179 | |
| 180 | <input type="radio" name="g2" id="g2rb4" value="wipeIn" dojoType="dijit.form.RadioButton"/> |
| 181 | <label for="g2rb4">.wipeIn</label><br> |
| 182 | |
| 183 | <input type="radio" name="g2" id="g2rb0" value="slideTo" dojoType="dijit.form.RadioButton"/> |
| 184 | <label for="g2rb0">.slideTo</label> (x: 0, y:0)<br> |
| 185 | |
| 186 | <br>(dojox:)<br> |
| 187 | |
| 188 | <input type="radio" name="g2" id="g2rb5" value="highlight" dojoType="dijit.form.RadioButton"/> |
| 189 | <label for="g2rb5">.highlight</label><br> |
| 190 | |
| 191 | <input type="radio" name="g2" id="g2rb6" value="sizeTo" dojoType="dijit.form.RadioButton"/> |
| 192 | <label for="g2rb6">.sizeTo (a fixed size)</label><br> |
| 193 | |
| 194 | <input type="radio" name="g2" id="g2rb7" value="slideBy" dojoType="dijit.form.RadioButton"/> |
| 195 | <label for="g2rb7">.slideBy (top: left: offset fixed)</label><br> |
| 196 | |
| 197 | <input type="radio" name="g2" id="g2rb8" value="fadeTo" dojoType="dijit.form.RadioButton"/> |
| 198 | <label for="g2rb8">.fadeTo (35% opacity)</label><br> |
| 199 | |
| 200 | </p> |
| 201 | <script type="dojo/method" data-dojo-event="onSubmit"> |
| 202 | // it's like cheating, but we don't event want this form to submit. you can type |
| 203 | // a query(), use the arrows to select a method, and hit enter. (or should be able to) |
| 204 | return false; |
| 205 | </script> |
| 206 | |
| 207 | <button dojoType="dijit.form.Button" type="submit" id="runnerButton" > |
| 208 | Run |
| 209 | <script type="dojo/method" data-dojo-event="onClick"> |
| 210 | // our runner / submit button |
| 211 | var str = dojo.byId("customStr").value; |
| 212 | var animType; |
| 213 | dojo.query('.dijitRadioChecked').forEach(function(n){ |
| 214 | animType = dijit.byNode(n).attr("value"); |
| 215 | }); |
| 216 | if(str && animType){ |
| 217 | var theseArgs = animArgs[animType] || {}; |
| 218 | // combine our base args with 'theseArgs' if they exist |
| 219 | var args = dojo.mixin(theseArgs,animArgs.defaultArgs) |
| 220 | //var nodelist = dojo.query(str); |
| 221 | dojo.query(str)[(animType)](args).play(); |
| 222 | } |
| 223 | return false; |
| 224 | </script> |
| 225 | </button> |
| 226 | |
| 227 | </form> |
| 228 | </div> |
| 229 | |
| 230 | <div class="testBoxContainer"> |
| 231 | <div id="node1" class="testBox rowOne iOne">1</div> |
| 232 | <div id="node2" class="testBox rowOne iTwo">2</div> |
| 233 | <div class="testBox noIdHere rowOne iThree">3</div> |
| 234 | <div class="testBox noIdHere rowOne iFour">4</div> |
| 235 | <div class="testBox noIdHere rowOne iFive">5</div> |
| 236 | <div class="testBox noIdHere rowOne iSix">6</div> |
| 237 | <div class="testBox noIdHere rowOne iSeven">7</div> |
| 238 | |
| 239 | <div id="node4" class="testBox rowTwo iOne">2</div> |
| 240 | <div class="testBox noIdHere rowTwo iTwo"></div> |
| 241 | <div id="node6" class="testBox rowTwo iThree"></div> |
| 242 | <div class="testBox noIdHere rowTwo iFour"></div> |
| 243 | <div class="testBox noIdHere rowTwo iFive"></div> |
| 244 | <div class="testBox noIdHere rowTwo iSix"></div> |
| 245 | <div class="testBox noIdHere rowTwo iSeven"></div> |
| 246 | |
| 247 | <div id="node7" class="testBox rowThree iOne">3</div> |
| 248 | <div class="testBox noIdHere rowThree iTwo"></div> |
| 249 | <div id="node9" class="testBox rowThree iThree"></div> |
| 250 | <div class="testBox noIdHere rowThree iFour"></div> |
| 251 | <div class="testBox noIdHere rowThree iFive"></div> |
| 252 | <div class="testBox noIdHere rowThree iSix"></div> |
| 253 | <div id="aNode" class="testBox rowThree iSeven"></div> |
| 254 | |
| 255 | <div id="node7" class="testBox rowFour iOne">4</div> |
| 256 | <div class="testBox noIdHere rowFour iTwo"></div> |
| 257 | <div id="node9" class="testBox rowFour iThree"></div> |
| 258 | <div class="testBox noIdHere rowFour iFour"></div> |
| 259 | <div class="testBox noIdHere rowFour iFive"></div> |
| 260 | <div id="randomNode" class="testBox rowFour iSix"></div> |
| 261 | <div class="testBox noIdHere rowFour iSeven"></div> |
| 262 | |
| 263 | </div> |
| 264 | |
| 265 | <br style="clear:both;"> |
| 266 | HTML AFTER |
| 267 | <br> |
| 268 | |
| 269 | <h3>classes available to play with:</h3> |
| 270 | |
| 271 | <pre><code style="border:0px;" |
| 272 | > .testBox |
| 273 | .noIdHere |
| 274 | each row: .rowOne .rowTwo .rowThree .rowFour |
| 275 | each col: .iOne .iTwo .. iSeven |
| 276 | #randomNode, #node9, #node7, #aNode, #node1, #node2, #node4, #node6</code |
| 277 | ></pre> |
| 278 | |
| 279 | <p>the dojo.query() isn't limited to the testDiv, it parses the body. try: dojo.query("fieldset") and slideBy animation</p> |
| 280 | |
| 281 | </body> |
| 282 | </html> |