| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>Bidi TimeTextBox</title> |
| 6 | |
| 7 | <script type="text/javascript" src="../../boilerplate.js" |
| 8 | data-dojo-config="parseOnLoad: true, has: { 'dojo-bidi': true }"></script> |
| 9 | |
| 10 | <script type="text/javascript"> |
| 11 | require([ |
| 12 | "doh/runner", |
| 13 | "dojo/_base/array", |
| 14 | "dojo/dom-class", |
| 15 | "dojo/parser", |
| 16 | "dijit/registry", |
| 17 | "dijit/form/TimeTextBox", |
| 18 | "dijit/form/Button", |
| 19 | "dojo/domReady!" |
| 20 | ], function(doh, array, domClass, parser, registry, TimeTextBox){ |
| 21 | |
| 22 | doh.register("parse", function(){ |
| 23 | return parser.parse(); |
| 24 | }); |
| 25 | |
| 26 | function testWidget(element, guiDir, textDir, isfirstChildLatin){ |
| 27 | doh.is(textDir, registry.byId(element).get("textDir"), "widget textDir"); |
| 28 | doh.is(guiDir, registry.byId(element).dir.toLowerCase(), "GUI dir"); |
| 29 | doh.is(guiDir.toLowerCase() == "ltr", registry.byId(element).isLeftToRight(), "isLeftToRight()"); |
| 30 | if(textDir == "auto"){ |
| 31 | textDir = isfirstChildLatin? "ltr" : "rtl"; |
| 32 | } |
| 33 | doh.is(textDir, registry.byId(element).focusNode.dir, "focusNode textDir"); |
| 34 | doh[guiDir.toLowerCase() == "rtl" ? "t" : "f"](domClass.contains(registry.byId(element).domNode, "dijitTimeTextBoxRtl"), "dijitTimeTextBoxRtl"); |
| 35 | } |
| 36 | |
| 37 | function testDropDownList(widgetId){ |
| 38 | var widget = registry.byId(widgetId); |
| 39 | widget.openDropDown(); |
| 40 | var widgetTextDir = widget.get("textDir"); |
| 41 | var itemTextDir = widgetTextDir; |
| 42 | var list = widget.dropDown.getChildren(); |
| 43 | var correct = true; |
| 44 | array.forEach(list, function(child){ |
| 45 | if(widgetTextDir == "auto"){ |
| 46 | itemTextDir = widget._checkContextual(child.label.replace(/<[^>]*>/gm," ")); |
| 47 | } |
| 48 | correct &= itemTextDir == child.textDirNode.dir; |
| 49 | }); |
| 50 | widget.closeDropDown(); |
| 51 | doh.t(correct, "child textDir"); |
| 52 | } |
| 53 | |
| 54 | doh.register("setup", function(){ |
| 55 | //change textDir dynamically |
| 56 | var btnLtr = registry.byId("btn1"); |
| 57 | btnLtr.on("click", function(){ |
| 58 | registry.byId("q1").set("textDir", "ltr"); |
| 59 | |
| 60 | }); |
| 61 | var btnRtl = registry.byId("btn2"); |
| 62 | btnRtl.on("click", function(){ |
| 63 | registry.byId("q1").set("textDir", "rtl"); |
| 64 | |
| 65 | }); |
| 66 | var btnAuto = registry.byId("btn3"); |
| 67 | btnAuto.on("click", function(){ |
| 68 | registry.byId("q1").set("textDir", "auto"); |
| 69 | |
| 70 | }); |
| 71 | |
| 72 | var programmatic1 = new TimeTextBox({}); |
| 73 | programmatic1.placeAt('testProgramatic1'); |
| 74 | programmatic1.set("textDir",'ltr'); |
| 75 | |
| 76 | var programmatic2 = new TimeTextBox({}); |
| 77 | programmatic2.placeAt('testProgramatic2'); |
| 78 | programmatic2.set("textDir",'rtl'); |
| 79 | |
| 80 | var programmatic3 = new TimeTextBox({}); |
| 81 | programmatic3.placeAt('testProgramatic3'); |
| 82 | programmatic3.set("textDir",'auto'); |
| 83 | }); |
| 84 | |
| 85 | doh.register("LTR GUI, LTR textDir", [ |
| 86 | { |
| 87 | name:"textbox", |
| 88 | runTest:function(){ |
| 89 | testWidget("q1", "ltr", "ltr", true); |
| 90 | } |
| 91 | }, |
| 92 | { |
| 93 | name:"dropdown", |
| 94 | runTest:function(){ |
| 95 | testDropDownList("q1"); |
| 96 | } |
| 97 | } |
| 98 | ]); |
| 99 | |
| 100 | doh.register("LTR GUI, RTL textDir", [ |
| 101 | { |
| 102 | name:"textbox", |
| 103 | runTest:function(){ |
| 104 | testWidget("q2", "ltr", "rtl", true); |
| 105 | } |
| 106 | }, |
| 107 | { |
| 108 | name:"dropdown", |
| 109 | runTest:function(){ |
| 110 | testDropDownList("q2"); |
| 111 | } |
| 112 | } |
| 113 | ]); |
| 114 | |
| 115 | doh.register("LTR GUI, auto textDir with LTR text", [ |
| 116 | { |
| 117 | name:"textbox", |
| 118 | runTest:function(){ |
| 119 | testWidget("q3", "ltr", "auto", true); |
| 120 | } |
| 121 | }, |
| 122 | { |
| 123 | name:"dropdown", |
| 124 | runTest:function(){ |
| 125 | testDropDownList("q3"); |
| 126 | } |
| 127 | } |
| 128 | ]); |
| 129 | |
| 130 | doh.register("LTR GUI, auto textDir with RTL text", [ |
| 131 | { |
| 132 | name:"textbox", |
| 133 | runTest:function(){ |
| 134 | testWidget("q4", "ltr", "auto", false); |
| 135 | } |
| 136 | }, |
| 137 | { |
| 138 | name:"dropdown", |
| 139 | runTest:function(){ |
| 140 | testDropDownList("q4"); |
| 141 | } |
| 142 | } |
| 143 | ]); |
| 144 | |
| 145 | doh.register("RTL GUI, LTR textDir", [ |
| 146 | { |
| 147 | name:"textbox", |
| 148 | runTest:function(){ |
| 149 | testWidget("q5", "rtl", "ltr", true); |
| 150 | } |
| 151 | }, |
| 152 | { |
| 153 | name:"dropdown", |
| 154 | runTest:function(){ |
| 155 | testDropDownList("q5"); |
| 156 | } |
| 157 | } |
| 158 | ]); |
| 159 | |
| 160 | doh.register("RTL GUI, RTL textDir", [ |
| 161 | { |
| 162 | name:"textbox", |
| 163 | runTest:function(){ |
| 164 | testWidget("q6", "rtl", "rtl", true); |
| 165 | } |
| 166 | }, |
| 167 | { |
| 168 | name:"dropdown", |
| 169 | runTest:function(){ |
| 170 | testDropDownList("q6"); |
| 171 | } |
| 172 | } |
| 173 | ]); |
| 174 | |
| 175 | doh.register("RTL GUI, auto textDir with LTR text", [ |
| 176 | { |
| 177 | name:"textbox", |
| 178 | runTest:function(){ |
| 179 | testWidget("q7", "rtl", "auto", true); |
| 180 | } |
| 181 | }, |
| 182 | { |
| 183 | name:"dropdown", |
| 184 | runTest:function(){ |
| 185 | testDropDownList("q7"); |
| 186 | } |
| 187 | } |
| 188 | ]); |
| 189 | |
| 190 | doh.register("RTL GUI, auto textDir with RTL text", [ |
| 191 | { |
| 192 | name:"textbox", |
| 193 | runTest:function(){ |
| 194 | testWidget("q8", "rtl", "auto", false); |
| 195 | } |
| 196 | }, |
| 197 | { |
| 198 | name:"dropdown", |
| 199 | runTest:function(){ |
| 200 | testDropDownList("q8"); |
| 201 | } |
| 202 | } |
| 203 | ]); |
| 204 | |
| 205 | doh.run(); |
| 206 | }); |
| 207 | </script> |
| 208 | |
| 209 | </head> |
| 210 | <body> |
| 211 | |
| 212 | <h1 class="testTitle">TimeTextBox</h1> |
| 213 | <br> |
| 214 | <table border="1"> |
| 215 | <tr> |
| 216 | <td colspan="2" rowspan="2"></td> |
| 217 | <th colspan="4" align="right"><h2><div align=center><font size="5">Base text direction</font></div></h2></th> |
| 218 | </tr> |
| 219 | <tr> |
| 220 | <td> <font size=4 color=red> LTR </font></td> |
| 221 | <td> <font size=4 color=red> RTL </font></td> |
| 222 | <td> <font size=4 color=red> Auto/LTR </font></td> |
| 223 | <td> <font size=4 color=red> Auto/RTL </font></td> |
| 224 | </tr> |
| 225 | <tr> |
| 226 | |
| 227 | <th rowspan="2" ><h2><div align=center><font size="5">GUI direction</font></div></h2></th> |
| 228 | <td > <font size=4 color=blue>LTR</font></td> |
| 229 | <td> |
| 230 | <input dir="ltr" id="q1" data-dojo-type="dijit/form/TimeTextBox" |
| 231 | data-dojo-props='type:"text", name:"time1a", value:"T10:30:00", textDir:"ltr", |
| 232 | constraints:{formatLength:"short"}, |
| 233 | required:true, |
| 234 | invalidMessage:"" '/> |
| 235 | </td> |
| 236 | <td> |
| 237 | <input dir="ltr" id="q2" data-dojo-type="dijit/form/TimeTextBox" |
| 238 | data-dojo-props='type:"text", name:"time1a", value:"T11:30:00", textDir:"rtl", |
| 239 | constraints:{formatLength:"short"}, |
| 240 | required:true, |
| 241 | invalidMessage:"" '/> |
| 242 | </td> |
| 243 | <td> |
| 244 | <input dir="ltr" id="q3" data-dojo-type="dijit/form/TimeTextBox" |
| 245 | data-dojo-props='type:"text", name:"time1a", value:"T12:30:00", textDir:"auto", |
| 246 | constraints:{formatLength:"short"}, |
| 247 | required:true, |
| 248 | invalidMessage:"" '/> |
| 249 | </td> |
| 250 | <td> |
| 251 | <input dir="LTR" id="q4" data-dojo-type="dijit/form/TimeTextBox" |
| 252 | data-dojo-props='type:"text", name:"time1a", value:"T12:30:00", textDir:"auto", |
| 253 | constraints:{formatLength:"short"}, |
| 254 | lang:"ar", |
| 255 | required:true, |
| 256 | invalidMessage:"" '/> |
| 257 | </td> |
| 258 | </tr> |
| 259 | <tr> |
| 260 | <td > <font size=4 color=blue>RTL</font></td> |
| 261 | <td> |
| 262 | <input dir="RTL" id="q5" data-dojo-type="dijit/form/TimeTextBox" |
| 263 | data-dojo-props='type:"text", name:"time1a", value:"T10:30:00", textDir:"ltr", |
| 264 | constraints:{formatLength:"short"}, |
| 265 | required:true, |
| 266 | invalidMessage:"" '/> |
| 267 | </td> |
| 268 | <td> |
| 269 | <input dir="rtl" id="q6" data-dojo-type="dijit/form/TimeTextBox" |
| 270 | data-dojo-props='type:"text", name:"time1a", value:"T11:30:00", textDir:"rtl", |
| 271 | constraints:{formatLength:"short"}, |
| 272 | required:true, |
| 273 | invalidMessage:"" '/> |
| 274 | </td> |
| 275 | <td> |
| 276 | <input dir="rtl" id="q7" data-dojo-type="dijit/form/TimeTextBox" |
| 277 | data-dojo-props='type:"text", name:"time1a", value:"T12:30:00", textDir:"auto", |
| 278 | constraints:{formatLength:"short"}, |
| 279 | required:true, |
| 280 | invalidMessage:"" '/> |
| 281 | </td> |
| 282 | <td> |
| 283 | <input dir="rtl" id="q8" data-dojo-type="dijit/form/TimeTextBox" |
| 284 | data-dojo-props='type:"text", name:"time1a", value:"T12:30:00", textDir:"auto", |
| 285 | constraints:{formatLength:"short"}, |
| 286 | lang:"ar", |
| 287 | required:true, |
| 288 | invalidMessage:"" '/> |
| 289 | </td> |
| 290 | </tr> |
| 291 | </table> |
| 292 | |
| 293 | <br> |
| 294 | |
| 295 | <h4 class="testSubtitle">Buttons to change BTD dynamically (for LTR-LTR cell)</h4><br> |
| 296 | <button data-dojo-type="dijit/form/Button" id="btn1" data-dojo-props='label:"Set textDir to ltr"'></button> |
| 297 | <button data-dojo-type="dijit/form/Button" id="btn2" data-dojo-props='label:"Set textDir to rtl"'></button> |
| 298 | <button data-dojo-type="dijit/form/Button" id="btn3" data-dojo-props='label:"Set textDir to auto"'></button> |
| 299 | <br> |
| 300 | <br> |
| 301 | <br> |
| 302 | <hr> |
| 303 | <h4 class="testSubtitle">Widgets created programmatically:</h4><br> |
| 304 | |
| 305 | <span id="testProgramatic1">LTR: </span> |
| 306 | <span id="testProgramatic2"> RTL: </span> |
| 307 | <span id="testProgramatic3"> AUTO: </span> |
| 308 | |
| 309 | </body> |
| 310 | </html> |