| 1 | <!DOCTYPE HTML> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
| 5 | <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" /> |
| 6 | <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 7 | <title>Switch Tests</title> |
| 8 | <script type="text/javascript" src="../../../deviceTheme.js"></script> |
| 9 | <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script> |
| 10 | <script language="JavaScript" type="text/javascript"> |
| 11 | require([ |
| 12 | "dojo/dom-construct", // dojo.place |
| 13 | "dojo/ready", // dojo.ready |
| 14 | "dijit/registry", // dijit.byId |
| 15 | "doh/runner", //doh functions |
| 16 | "dojox/mobile/Switch", |
| 17 | "dojox/mobile", // This is a mobile app. |
| 18 | "dojox/mobile/View", // This mobile app uses mobile view |
| 19 | "dojox/mobile/compat", // This mobile app supports running on desktop browsers |
| 20 | "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser |
| 21 | ], function(domConst, ready, registry, runner, Switch){ |
| 22 | function _createSwitchDeclaratively(id) { |
| 23 | return registry.byId(id); |
| 24 | }; |
| 25 | |
| 26 | function _createSwitchProgrammatically(placeHolderId){ |
| 27 | var widget = new Switch(); |
| 28 | runner.assertNotEqual(null, widget); |
| 29 | domConst.place(widget.domNode, placeHolderId, "replace"); |
| 30 | widget.startup(); |
| 31 | return widget; |
| 32 | }; |
| 33 | |
| 34 | function _createSwitchProgrammaticallyWithSourceNodeReference(id){ |
| 35 | var widget = new Switch({}, id); |
| 36 | widget.startup(); |
| 37 | return widget; |
| 38 | }; |
| 39 | |
| 40 | function _assertCorrectSwitch(switchButton){ |
| 41 | runner.assertNotEqual(null, switchButton); |
| 42 | runner.assertEqual("on", switchButton.value); |
| 43 | switchButton.set("value", "off"); |
| 44 | runner.assertEqual("off", switchButton.value); |
| 45 | }; |
| 46 | |
| 47 | function _showView2(){ |
| 48 | var view1 = registry.byId("view1"); |
| 49 | view1.performTransition("view2", 1, "none"); |
| 50 | }; |
| 51 | |
| 52 | ready(function(){ |
| 53 | runner.register("dojox.mobile.test.doh.SwitchTests", [ |
| 54 | function testInView1(){ |
| 55 | var switch1 = _createSwitchDeclaratively("view1-switch1"); |
| 56 | var switch2 = _createSwitchProgrammatically("view1-switch2"); |
| 57 | var switch3 = _createSwitchProgrammaticallyWithSourceNodeReference("view1-switch3"); |
| 58 | |
| 59 | _assertCorrectSwitch(switch1); |
| 60 | _assertCorrectSwitch(switch2); |
| 61 | _assertCorrectSwitch(switch3); |
| 62 | }, |
| 63 | function testInView2(){ |
| 64 | var switch1 = _createSwitchDeclaratively("view2-switch1"); |
| 65 | var switch2 = _createSwitchProgrammatically("view2-switch2"); |
| 66 | var switch3 = _createSwitchProgrammaticallyWithSourceNodeReference("view2-switch3"); |
| 67 | |
| 68 | _showView2(); |
| 69 | |
| 70 | _assertCorrectSwitch(switch1); |
| 71 | _assertCorrectSwitch(switch2); |
| 72 | _assertCorrectSwitch(switch3); |
| 73 | } |
| 74 | ]); |
| 75 | runner.run(); |
| 76 | }); |
| 77 | }) |
| 78 | </script> |
| 79 | </head> |
| 80 | <body> |
| 81 | <div id="view1" data-dojo-type="dojox.mobile.View" selected="true"> |
| 82 | <h1>View 1</h1> |
| 83 | <div id="view1-switch1" data-dojo-type="dojox.mobile.Switch"></div> |
| 84 | <div id="view1-switch2"></div> |
| 85 | <div id="view1-switch3"></div> |
| 86 | </div> |
| 87 | <div id="view2" data-dojo-type="dojox.mobile.View"> |
| 88 | <h1>View 2</h1> |
| 89 | <div id="view2-switch1" data-dojo-type="dojox.mobile.Switch"></div> |
| 90 | <div id="view2-switch2"></div> |
| 91 | <div id="view2-switch3"></div> |
| 92 | </div> |
| 93 | </body> |
| 94 | </html> |