| 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>Custom SpinWheel</title> |
| 8 | |
| 9 | <script type="text/javascript" src="../../../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base','SpinWheel']"></script> |
| 10 | <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script> |
| 11 | |
| 12 | <script type="text/javascript"> |
| 13 | require([ |
| 14 | "dojo/dom-construct", // dojo.place |
| 15 | "dojo/ready", // dojo.ready |
| 16 | "dijit/registry", // dijit.byId |
| 17 | "doh/runner", //doh functions |
| 18 | "dojox/mobile/SpinWheel", |
| 19 | "dojox/mobile/SpinWheelSlot", |
| 20 | "dojox/mobile", // This is a mobile app. |
| 21 | "dojox/mobile/View", // This mobile app uses mobile view |
| 22 | "dojox/mobile/compat", // This mobile app supports running on desktop browsers |
| 23 | "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser |
| 24 | ], function(domConst, ready, registry, runner, SpinWheel, SpinWheelSlot){ |
| 25 | ready(function(){ |
| 26 | var view = registry.byId("view1"); |
| 27 | var demoWidget = new SpinWheel({id:"spin1"}); |
| 28 | demoWidget.placeAt(view.containerNode); |
| 29 | |
| 30 | // No initial value specified |
| 31 | var slot0 = new SpinWheelSlot({labels:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'], |
| 32 | style:"text-align:center;width:40px;"}); |
| 33 | slot0._valueBeforeStartup = slot0.get("value"); |
| 34 | slot0._keyBeforeStartup = slot0.get("key"); |
| 35 | demoWidget.addChild(slot0); |
| 36 | |
| 37 | // Initial value: C |
| 38 | var slot1 = new SpinWheelSlot({labels:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'], |
| 39 | value:'C', style:"text-align:center;width:40px;"}); |
| 40 | demoWidget.addChild(slot1); |
| 41 | |
| 42 | // No initial value specified |
| 43 | var slot2 = new SpinWheelSlot({labelFrom:3000, labelTo:3100, style:"width:70px;"}); |
| 44 | demoWidget.addChild(slot2); |
| 45 | |
| 46 | // Initial value: 3009 |
| 47 | var slot3 = new SpinWheelSlot({labelFrom:3000, labelTo:3100, value:3009, style:"width:70px;"}); |
| 48 | demoWidget.addChild(slot3); |
| 49 | |
| 50 | domConst.create("div", {className: "mblSpinWheelSlot", id:"pt"}, demoWidget.containerNode); |
| 51 | domConst.create("div", {className: "mblSpinWheelSlot", id:"txt", innerHTML:"."}, demoWidget.containerNode); |
| 52 | |
| 53 | var slot4 = new SpinWheelSlot({labelFrom:0, labelTo:9, style:"width:30px;"}); |
| 54 | demoWidget.addChild(slot4); |
| 55 | |
| 56 | var slot5 = new SpinWheelSlot({labels:['pt','px','cm'], style:"width:50px;"}); |
| 57 | demoWidget.addChild(slot5); |
| 58 | |
| 59 | var slot6 = new SpinWheelSlot({ |
| 60 | labels:[ |
| 61 | '<img src=../../images/i-icon-1.png>', |
| 62 | '<img src=../../images/i-icon-2.png>', |
| 63 | '<img src=../../images/i-icon-3.png>', |
| 64 | '<img src=../../images/i-icon-4.png>', |
| 65 | '<img src=../../images/i-icon-5.png>', |
| 66 | '<img src=../../images/i-icon-6.png>', |
| 67 | '<img src=../../images/i-icon-7.png>', |
| 68 | '<img src=../../images/i-icon-8.png>', |
| 69 | '<img src=../../images/i-icon-9.png>', |
| 70 | '<img src=../../images/i-icon-10.png>' |
| 71 | ], |
| 72 | style:"width:70px;text-align: center;" |
| 73 | }); |
| 74 | demoWidget.addChild(slot6); |
| 75 | |
| 76 | var slot7 = new SpinWheelSlot({ |
| 77 | items:[ |
| 78 | ['key1', 'value1'], |
| 79 | ['key2', 'value2'], |
| 80 | ['key2', 'value2'] |
| 81 | ], |
| 82 | value:'value2', |
| 83 | style:"text-align:center;width:40px;"}); |
| 84 | demoWidget.addChild(slot7); |
| 85 | |
| 86 | demoWidget.reset(); |
| 87 | }); |
| 88 | }) |
| 89 | </script> |
| 90 | |
| 91 | <script type="text/javascript"> |
| 92 | require([ |
| 93 | "dojo/ready", // dojo.ready |
| 94 | "dijit/registry", // dijit.byId |
| 95 | "doh/runner", //doh functions |
| 96 | "dojox/mobile/SpinWheel", |
| 97 | "dojox/mobile/SpinWheelSlot", |
| 98 | "dojox/mobile", // This is a mobile app. |
| 99 | "dojox/mobile/View", // This mobile app uses mobile view |
| 100 | "dojox/mobile/compat", // This mobile app supports running on desktop browsers |
| 101 | "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser |
| 102 | ], function(ready, registry, runner, SpinWheel, SpinWheelSlot){ |
| 103 | ready(function(){ |
| 104 | |
| 105 | var testEmptySlot = function(emptySlot){ |
| 106 | // Test for the edge-case of slots with no items. |
| 107 | // Mainly checks that no error is thrown. |
| 108 | emptySlot.setInitialValue(); |
| 109 | emptySlot.resize(); |
| 110 | doh.assertEqual("", emptySlot.get("value")); |
| 111 | emptySlot.set("value", "some value"); // no-op for empty slot |
| 112 | doh.assertEqual("", emptySlot.get("value")); |
| 113 | }; |
| 114 | |
| 115 | runner.register("dojox.mobile.test.doh.SpinWheel", [ |
| 116 | { |
| 117 | name: "SpinWheel Verification", |
| 118 | timeout: 4000, |
| 119 | runTest: function(){ |
| 120 | var d = new runner.Deferred(); |
| 121 | setTimeout(d.getTestCallback(function(){ |
| 122 | var demoWidget = registry.byId("spin1"); |
| 123 | var slots = demoWidget.getSlots(); |
| 124 | doh.assertEqual('A', slots[0].get("value")); |
| 125 | doh.assertEqual('C', slots[1].get("value")); |
| 126 | doh.assertEqual('3000', slots[2].get("value")); |
| 127 | doh.assertEqual('3009', slots[3].get("value")); |
| 128 | doh.assertEqual('0', slots[4].get("value")); |
| 129 | doh.assertEqual('pt', slots[5].get("value")); |
| 130 | doh.assertEqual('<img src=../../images/i-icon-1.png>', slots[6].get("value")); |
| 131 | doh.assertEqual('value2', slots[7].get("value")); |
| 132 | doh.assertEqual('A', slots[0]._valueBeforeStartup); |
| 133 | doh.assertEqual(0, slots[0]._keyBeforeStartup); |
| 134 | |
| 135 | // Test case for #16519 |
| 136 | var noError = true; |
| 137 | var slot8 = new SpinWheelSlot({ |
| 138 | items:[ |
| 139 | ['key1', 'value1'], |
| 140 | ['key2', 'value2'], |
| 141 | ['key2', 'value2'] |
| 142 | ], |
| 143 | value:'value2', |
| 144 | style:"text-align:center;width:40px;"}); |
| 145 | try{ |
| 146 | slot8.disableValues(2); |
| 147 | }catch(error){ |
| 148 | noError = false; |
| 149 | } |
| 150 | doh.assertTrue(noError, "Calling SpinWheelSlot.disableValues shouldn't throw an exception!"); |
| 151 | |
| 152 | // Test case for #16701 (support for the edge-case of empty slots) |
| 153 | // (without the fix of #16701, leads to infinite loop) |
| 154 | testEmptySlot(new SpinWheelSlot({ |
| 155 | items:[] // empty |
| 156 | })); |
| 157 | testEmptySlot(new SpinWheelSlot({ |
| 158 | labels:[] // empty |
| 159 | })); |
| 160 | testEmptySlot(new SpinWheelSlot()); // empty |
| 161 | }),2000); |
| 162 | return d; |
| 163 | } |
| 164 | } |
| 165 | ]); |
| 166 | runner.run(); |
| 167 | }); |
| 168 | |
| 169 | }) |
| 170 | </script> |
| 171 | |
| 172 | <style> |
| 173 | #spin1 { |
| 174 | width: 304px; |
| 175 | margin: 10px auto; |
| 176 | } |
| 177 | #pt { |
| 178 | width: 20px; |
| 179 | } |
| 180 | #txt { |
| 181 | width: 10px; |
| 182 | margin-left: -15px; |
| 183 | padding-top: 85px; |
| 184 | font-size: 24px; |
| 185 | font-weight: bold; |
| 186 | border: none; |
| 187 | } |
| 188 | </style> |
| 189 | </head> |
| 190 | <body style="visibility:hidden;"> |
| 191 | <div id="view1" data-dojo-type="dojox.mobile.View"> |
| 192 | <h1 data-dojo-type="dojox.mobile.Heading">Custom SpinWheel</h1> |
| 193 | </div> |
| 194 | </body> |
| 195 | </html> |