| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 | <html dir="ltr"> |
| 3 | <head> |
| 4 | <style type="text/css"> |
| 5 | body, html { font-family:helvetica,arial,sans-serif; font-size:90%; } |
| 6 | </style> |
| 7 | <script type="text/javascript" src="../../../../dojo/dojo.js" |
| 8 | data-dojo-config="parseOnLoad: true, isDebug: true, has: { 'dojo-bidi': true }"> |
| 9 | </script> |
| 10 | <link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 11 | <script type="text/javascript"> |
| 12 | dojo.require("doh.runner"); |
| 13 | dojo.require("dojo.data.ItemFileWriteStore"); |
| 14 | dojo.require("dijit.Tree"); |
| 15 | |
| 16 | dojo.ready(function() { |
| 17 | var store = new dojo.data.ItemFileWriteStore({ |
| 18 | url: "../../../../dijit/tests/_BidiSupport/_data/countriesHeb.json" |
| 19 | }); |
| 20 | var treeModel = new dijit.tree.ForestStoreModel({ |
| 21 | store: store, |
| 22 | query: { |
| 23 | "type": "continent" |
| 24 | }, |
| 25 | rootId: "root", |
| 26 | rootLabel: "Continents!", |
| 27 | childrenAttrs: ["children"] |
| 28 | }); |
| 29 | new dijit.Tree({ |
| 30 | textDir: "ltr", |
| 31 | model: treeModel |
| 32 | }, |
| 33 | "treeLtr"); |
| 34 | new dijit.Tree({ |
| 35 | textDir: "rtl", |
| 36 | model: treeModel |
| 37 | }, |
| 38 | "treeRtl"); |
| 39 | new dijit.Tree({ |
| 40 | textDir: "auto", |
| 41 | model: treeModel |
| 42 | }, |
| 43 | "treeAuto"); |
| 44 | var treeRtl, treeLtr, treeAuto, buttonLtr, buttonRtl, buttonAuto, buttonRenameCountry; |
| 45 | function testNodeAuto(node,textDir){ |
| 46 | doh.is(node.tree._checkContextual(node.label), node.labelNode.dir, "direction of " + node.tree.id +" : rootNode"); |
| 47 | if(!node.item.children){ |
| 48 | return; |
| 49 | } |
| 50 | dojo.forEach(node.getChildren(), function(childNode){ |
| 51 | //doh.is(textDir, childNode.labelNode.dir, "direction of " + childNode.tree.id + " element: " + i); |
| 52 | testNodeAuto(childNode,textDir); |
| 53 | }); |
| 54 | } |
| 55 | function testNode(node,textDir){ |
| 56 | doh.is(textDir, node.labelNode.dir, "direction of " + node.tree.id +" : rootNode"); |
| 57 | if(!node.item.children){ |
| 58 | return; |
| 59 | } |
| 60 | dojo.forEach(node.getChildren(), function(childNode){ |
| 61 | //doh.is(textDir, childNode.labelNode.dir, "direction of " + childNode.tree.id + " element: " + i); |
| 62 | testNode(childNode,textDir); |
| 63 | }); |
| 64 | } |
| 65 | function expandedNodesTextDirTest(tree, textDir){ |
| 66 | textDir == "auto" ? testNodeAuto(tree.rootNode, textDir) : testNode(tree.rootNode, textDir); |
| 67 | } |
| 68 | function renameContinent(){ |
| 69 | store.fetch({ |
| 70 | query:{ |
| 71 | type: "continent" |
| 72 | }, |
| 73 | onComplete: rename, |
| 74 | queryOptions:{ |
| 75 | deep: true |
| 76 | } |
| 77 | }); |
| 78 | } |
| 79 | function renameCountry(){ |
| 80 | store.fetch ({ |
| 81 | query:{ |
| 82 | type: "country" |
| 83 | }, |
| 84 | onComplete: rename, |
| 85 | queryOptions:{ |
| 86 | deep: true |
| 87 | } |
| 88 | }); |
| 89 | } |
| 90 | function rename(items, request){ |
| 91 | if(items){ |
| 92 | var i; |
| 93 | for(i = 0; i < items.length; i++){ |
| 94 | var item = items[i]; |
| 95 | var newName = '\u05D0' + '_' + store.getValue(item, 'name'); |
| 96 | store.setValue(item, 'name', newName); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | buttonRenameCountry = dojo.byId("buttonRenameCountry"); |
| 101 | dojo.connect(buttonRenameCountry, "onclick", renameCountry); |
| 102 | doh.register("initial", [ |
| 103 | { |
| 104 | name: "initial dirs", |
| 105 | setUp: function(){ |
| 106 | treeRtl = dijit.byId("treeRtl"); |
| 107 | treeLtr = dijit.byId("treeLtr"); |
| 108 | treeAuto = dijit.byId("treeAuto"); |
| 109 | }, |
| 110 | runTest: function(){ |
| 111 | var d = new doh.Deferred(); |
| 112 | setTimeout(d.getTestCallback(function(){ |
| 113 | doh.is("rtl", treeRtl.rootNode.labelNode.dir, "direction of treeRtl: rootNode"); |
| 114 | doh.is("ltr", treeLtr.rootNode.labelNode.dir, "direction of treeLtr: rootNode"); |
| 115 | doh.is("ltr", treeAuto.rootNode.labelNode.dir, "direction of treeAuto: rootNode"); |
| 116 | var rtlChildren = treeRtl.rootNode.getChildren(), ltrChildren = treeLtr.rootNode.getChildren(), |
| 117 | autoChildren = treeAuto.rootNode.getChildren(); |
| 118 | for(var i = 0 ; i < rtlChildren.length ; i++){ |
| 119 | doh.is("rtl", rtlChildren[i].labelNode.dir, "direction of treeRtl element: " + i); |
| 120 | doh.is("ltr", ltrChildren[i].labelNode.dir, "direction of treeLtr element: " + i); |
| 121 | doh.is(treeAuto._checkContextual(autoChildren[i].label), autoChildren[i].labelNode.dir, "direction of treeAuto element: " + autoChildren[i].label); |
| 122 | } |
| 123 | }), 100); |
| 124 | return d; |
| 125 | } |
| 126 | }, |
| 127 | { |
| 128 | name: "expanded RTL", |
| 129 | timeout: 10000, |
| 130 | runTest: function(){ |
| 131 | var d = new doh.Deferred(); |
| 132 | treeRtl.expandAll().then(d.getTestCallback(function(){ |
| 133 | expandedNodesTextDirTest(treeRtl, "rtl"); |
| 134 | })); |
| 135 | return d; |
| 136 | } |
| 137 | }, |
| 138 | { |
| 139 | name: "expanded LTR", |
| 140 | timeout: 10000, |
| 141 | runTest: function(){ |
| 142 | var d = new doh.Deferred(); |
| 143 | treeLtr.expandAll().then(d.getTestCallback(function(){ |
| 144 | expandedNodesTextDirTest(treeLtr, "ltr"); |
| 145 | })); |
| 146 | return d; |
| 147 | } |
| 148 | }, |
| 149 | { |
| 150 | name: "expanded AUTO", |
| 151 | timeout: 10000, |
| 152 | runTest: function(){ |
| 153 | var d = new doh.Deferred(); |
| 154 | treeAuto.expandAll().then(d.getTestCallback(function(){ |
| 155 | expandedNodesTextDirTest(treeAuto, "auto"); |
| 156 | })); |
| 157 | return d; |
| 158 | } |
| 159 | } |
| 160 | ]); |
| 161 | doh.register("Dynamic change textDir", [ |
| 162 | { |
| 163 | name: 'check "set("textDir", textDir)" function', |
| 164 | setUp: function(){ |
| 165 | treeRtl = dijit.byId("treeRtl"); |
| 166 | treeLtr = dijit.byId("treeLtr"); |
| 167 | treeAuto = dijit.byId("treeAuto"); |
| 168 | buttonLtr = dojo.byId("buttonLtr"); |
| 169 | buttonRtl = dojo.byId("buttonRtl"); |
| 170 | buttonAuto = dojo.byId("buttonAuto"); |
| 171 | }, |
| 172 | runTest: function(){ |
| 173 | dijit.byId("treeRtl").set("textDir", "ltr"); |
| 174 | expandedNodesTextDirTest(treeRtl, "ltr"); |
| 175 | expandedNodesTextDirTest(treeAuto, "auto"); |
| 176 | } |
| 177 | }, |
| 178 | { |
| 179 | name: 'set using the buttons: LTR', |
| 180 | runTest: function(){ |
| 181 | buttonLtr.click(); |
| 182 | expandedNodesTextDirTest(treeRtl, "ltr"); |
| 183 | expandedNodesTextDirTest(treeLtr, "ltr"); |
| 184 | expandedNodesTextDirTest(treeAuto, "ltr"); |
| 185 | } |
| 186 | }, |
| 187 | { |
| 188 | name: 'set using the buttons: RTL', |
| 189 | runTest: function(){ |
| 190 | buttonRtl.click(); |
| 191 | expandedNodesTextDirTest(treeRtl, "rtl"); |
| 192 | expandedNodesTextDirTest(treeLtr, "rtl"); |
| 193 | expandedNodesTextDirTest(treeAuto, "rtl"); |
| 194 | } |
| 195 | }, |
| 196 | { |
| 197 | name: 'set using the buttons: AUTO', |
| 198 | runTest: function(){ |
| 199 | buttonAuto.click(); |
| 200 | expandedNodesTextDirTest(treeRtl, "auto"); |
| 201 | expandedNodesTextDirTest(treeLtr, "auto"); |
| 202 | expandedNodesTextDirTest(treeAuto, "auto"); |
| 203 | } |
| 204 | } |
| 205 | ]); |
| 206 | doh.register("Change Node label", [ |
| 207 | { |
| 208 | name: 'check "_setLabelAttr" function', |
| 209 | runTest: function() { |
| 210 | renameContinent(); |
| 211 | expandedNodesTextDirTest(treeAuto, "auto"); |
| 212 | } |
| 213 | } |
| 214 | ]); |
| 215 | doh.run(); |
| 216 | }); |
| 217 | </script> |
| 218 | </head> |
| 219 | <body class="claro"> |
| 220 | <table> |
| 221 | <tr><td> |
| 222 | <label for="treeLtr" > |
| 223 | <b> I'm a LTR Tree </b> |
| 224 | </label> |
| 225 | <div id="treeLtr"></div> |
| 226 | </td> |
| 227 | <td> |
| 228 | <label for="treeRtl" > |
| 229 | <b> I'm a RTL Tree </b> |
| 230 | </label> |
| 231 | <div id="treeRtl"></div> |
| 232 | </td> |
| 233 | <td> |
| 234 | <label for="treeAuto" > |
| 235 | <b> I'm a Contextual Tree </b> |
| 236 | </label> |
| 237 | <div id="treeAuto"></div> |
| 238 | </td> |
| 239 | </tr> |
| 240 | </table> |
| 241 | <input id="buttonRtl" type="button" value="RTL" |
| 242 | onclick="dijit.byId('treeLtr').set('textDir','rtl'); |
| 243 | dijit.byId('treeRtl').set('textDir','rtl'); |
| 244 | dijit.byId('treeAuto').set('textDir','rtl');" |
| 245 | > |
| 246 | <input id="buttonLtr" type="button" value="LTR" |
| 247 | onclick="dijit.byId('treeLtr').set('textDir','ltr'); |
| 248 | dijit.byId('treeRtl').set('textDir','ltr'); |
| 249 | dijit.byId('treeAuto').set('textDir','ltr');" |
| 250 | > |
| 251 | <input id="buttonAuto" type="button" value="AUTO" |
| 252 | onclick="dijit.byId('treeLtr').set('textDir','auto'); |
| 253 | dijit.byId('treeRtl').set('textDir','auto'); |
| 254 | dijit.byId('treeAuto').set('textDir','auto');" |
| 255 | > |
| 256 | <input id="buttonRenameCountry" type="button" value="Rename Country"> |
| 257 | </body> |
| 258 | </html> |