| 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>IconContainer and IconItem 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 | var ICON_ITEM_CLASSNAME1 = "mblIconItem"; |
| 12 | var ICON_ITEM_CLASSNAME2 = "mblIconArea"; |
| 13 | var WIDGET_CLASSNAME = "mblIconContainer"; |
| 14 | var ICON_ITEM_SRC_REGEXP = /icon-1.png/i; |
| 15 | var CHILD_ITEM_PROPS = [{label:"app1", icon:"../../images/icon-1.png", lazy:"true"}, |
| 16 | {label:"app2", icon:"../../images/icon-1.png", lazy:"true"}, |
| 17 | {label:"app3", icon:"../../images/icon-1.png", lazy:"true"}, |
| 18 | {label:"moveTo", icon:"../../images/icon-1.png", moveTo:"about", transition:"slide"}, |
| 19 | {label:"href", icon:"../../images/icon-1.png", href:"../../test_iPhone-RoundRectList.html", transition:"slide"}, |
| 20 | {label:"url" , icon:"../../images/icon-1.png", url:"../../view-sample.html", transition:"slide"}]; |
| 21 | |
| 22 | var CHILD_ITEM_CONTAINERS = ['<div class="box"></div>', |
| 23 | '<div class="box"></div>', |
| 24 | '<div class="box"></div>', |
| 25 | '', |
| 26 | '', |
| 27 | '']; |
| 28 | |
| 29 | require([ |
| 30 | "dojo/_base/array", // dojo.forEach |
| 31 | "dojo/sniff", |
| 32 | "dojo/dom-construct", // dojo.place |
| 33 | "dojo/ready", // dojo.ready |
| 34 | "dijit/registry", // dijit.byId |
| 35 | "doh/runner", //doh functions |
| 36 | "dojox/mobile/IconContainer", |
| 37 | "dojox/mobile/IconItem", |
| 38 | "dojox/mobile", // This is a mobile app. |
| 39 | "dojox/mobile/compat", // This mobile app supports running on desktop browsers |
| 40 | "dojox/mobile/parser", // This mobile app uses declarative programming with fast mobile parser |
| 41 | "dojox/mobile/View" // This mobile app uses mobile view |
| 42 | ], function(array, has, domConst, ready, registry, runner, IconContainer, IconItem){ |
| 43 | function _createIconContainerDeclaratively(widgetId) { |
| 44 | return registry.byId(widgetId); |
| 45 | } |
| 46 | function _createIconContainerProgrammatically(placeHolderId, widgetId){ |
| 47 | // Create IconContainer |
| 48 | var r = new IconContainer({id:widgetId}); |
| 49 | runner.assertNotEqual(null, r); |
| 50 | domConst.place(r.domNode, placeHolderId, "replace"); |
| 51 | |
| 52 | // Create IconItems |
| 53 | for(var i = 0, len = CHILD_ITEM_PROPS.length; i < len; i++){ |
| 54 | var childWidget = new IconItem(CHILD_ITEM_PROPS[i]); |
| 55 | r.addChild(childWidget); |
| 56 | if(CHILD_ITEM_CONTAINERS[i]){ |
| 57 | childWidget.set("content", CHILD_ITEM_CONTAINERS[i]); |
| 58 | } |
| 59 | } |
| 60 | r.startup(); |
| 61 | return r; |
| 62 | } |
| 63 | function _createIconContainerProgrammaticallyWithSourceNodeReference(widgetId){ |
| 64 | // Create IconContainer |
| 65 | var r = new IconContainer({}, widgetId); |
| 66 | |
| 67 | // Create IconItems |
| 68 | var index = 0; |
| 69 | for(var i = 0, len = r.domNode.childNodes.length; i < len; i++){ |
| 70 | var n = r.domNode.childNodes[i]; |
| 71 | if(n.nodeType === 1 && n.id){ |
| 72 | new IconItem(CHILD_ITEM_PROPS[index++], n.id); |
| 73 | } |
| 74 | } |
| 75 | r.startup(); |
| 76 | return r; |
| 77 | } |
| 78 | function _assertCorrectIconContainer(widget){ |
| 79 | runner.assertNotEqual(null, widget, "IconContainer: Did not instantiate."); |
| 80 | runner.assertEqual(WIDGET_CLASSNAME, widget.domNode.className, "id=" + widget.domNode.id); |
| 81 | array.forEach(widget.getChildren(), function(iconItem){ |
| 82 | _assertCorrectIconItem(iconItem); |
| 83 | }); |
| 84 | |
| 85 | } |
| 86 | function _assertCorrectIconItem(widget){ |
| 87 | runner.assertNotEqual(null, widget, "IconItem: Did not instantiate."); |
| 88 | runner.assertEqual(ICON_ITEM_CLASSNAME1, widget.domNode.className, "id=" + widget.domNode.id); |
| 89 | runner.assertEqual(ICON_ITEM_CLASSNAME2, widget.domNode.childNodes[0].className, "id=" + widget.domNode.id); |
| 90 | if(!has("ie") || has("ie") > 6){ |
| 91 | runner.assertTrue(widget.domNode.childNodes[0].childNodes[0].childNodes[0].src.search(ICON_ITEM_SRC_REGEXP) != -1, ICON_ITEM_SRC_REGEXP.toString() + " id=" + widget.domNode.id); |
| 92 | } |
| 93 | runner.assertEqual(widget.label, widget.domNode.childNodes[0].childNodes[1].childNodes[0].nodeValue, "id=" + widget.domNode.id); |
| 94 | } |
| 95 | function _assertCorrectIconItemPos(widgetId1, widgetId2, widgetId3, widgetId4){ |
| 96 | var widget1 = registry.byId(widgetId1); |
| 97 | var widget2 = registry.byId(widgetId2); |
| 98 | var widget3 = registry.byId(widgetId3); |
| 99 | var widget4 = registry.byId(widgetId4); |
| 100 | |
| 101 | |
| 102 | runner.assertNotEqual(null, widget1, "Widget (Id=" + widgetId1 + ") dose not exist."); |
| 103 | runner.assertNotEqual(null, widget2, "Widget (Id=" + widgetId2 + ") dose not exist."); |
| 104 | runner.assertNotEqual(null, widget3, "Widget (Id=" + widgetId3 + ") dose not exist."); |
| 105 | runner.assertNotEqual(null, widget4, "Widget (Id=" + widgetId4 + ") dose not exist."); |
| 106 | runner.assertEqual(widget2.domNode.offsetTop, widget1.domNode.offsetTop, "id=" + widgetId1); |
| 107 | runner.assertEqual(widget3.domNode.offsetLeft, widget1.domNode.offsetLeft, "left id=" + widgetId1); |
| 108 | runner.assertEqual(widget3.domNode.offsetTop, widget4.domNode.offsetTop, "id=" + widgetId3); |
| 109 | runner.assertEqual(widget2.domNode.offsetLeft, widget4.domNode.offsetLeft, "left id=" + widgetId4); |
| 110 | } |
| 111 | function _showView2(){ |
| 112 | var view1 = registry.byId("view1"); |
| 113 | view1.performTransition("view2", 1, "none"); |
| 114 | } |
| 115 | dojo.ready(function(){ |
| 116 | doh.register("dojox.mobile.test.doh.IconContainerTests", [ |
| 117 | function testInView1(){ |
| 118 | var widget1 = _createIconContainerDeclaratively("dojox_mobile_IconContainer_0"); |
| 119 | var widget2 = _createIconContainerProgrammatically("view1-IconContainer2place", "view1-IconContainer2"); |
| 120 | var widget3 = _createIconContainerProgrammaticallyWithSourceNodeReference("view1-IconContainer3"); |
| 121 | |
| 122 | _assertCorrectIconContainer(widget1); |
| 123 | if(!has("ie")){ |
| 124 | _assertCorrectIconItemPos("dojox_mobile_IconItem_0", "dojox_mobile_IconItem_2", "dojox_mobile_IconItem_3", "dojox_mobile_IconItem_5"); |
| 125 | } |
| 126 | _assertCorrectIconContainer(widget2); |
| 127 | if(!has("ie")){ |
| 128 | _assertCorrectIconItemPos("dojox_mobile_IconItem_12", "dojox_mobile_IconItem_14", "dojox_mobile_IconItem_15", "dojox_mobile_IconItem_17"); |
| 129 | } |
| 130 | _assertCorrectIconContainer(widget3); |
| 131 | if(!has("ie")){ |
| 132 | _assertCorrectIconItemPos("view1-IconContainer3-IconItem1", "view1-IconContainer3-IconItem3", "view1-IconContainer3-IconItem4", "view1-IconContainer3-IconItem6"); |
| 133 | } |
| 134 | }, |
| 135 | function testInView2(){ |
| 136 | var widget1 = _createIconContainerDeclaratively("dojox_mobile_IconContainer_1"); |
| 137 | var widget2 = _createIconContainerProgrammatically("view2-IconContainer2place", "view2-IconContainer2"); |
| 138 | var widget3 = _createIconContainerProgrammaticallyWithSourceNodeReference("view2-IconContainer3"); |
| 139 | |
| 140 | _showView2(); |
| 141 | |
| 142 | _assertCorrectIconContainer(widget1); |
| 143 | if(!has("ie")){ |
| 144 | _assertCorrectIconItemPos("dojox_mobile_IconItem_6", "dojox_mobile_IconItem_8", "dojox_mobile_IconItem_9", "dojox_mobile_IconItem_11"); |
| 145 | } |
| 146 | _assertCorrectIconContainer(widget2); |
| 147 | if(!has("ie")){ |
| 148 | _assertCorrectIconItemPos("dojox_mobile_IconItem_18", "dojox_mobile_IconItem_20", "dojox_mobile_IconItem_21", "dojox_mobile_IconItem_23"); |
| 149 | } |
| 150 | _assertCorrectIconContainer(widget3); |
| 151 | if(!has("ie")){ |
| 152 | _assertCorrectIconItemPos("view2-IconContainer3-IconItem1", "view2-IconContainer3-IconItem3", "view2-IconContainer3-IconItem4", "view2-IconContainer3-IconItem6"); |
| 153 | } |
| 154 | } |
| 155 | ]); |
| 156 | runner.run(); |
| 157 | }); |
| 158 | }) |
| 159 | </script> |
| 160 | </head> |
| 161 | <body> |
| 162 | <div id="view1" data-dojo-type="dojox.mobile.View" selected="true"> |
| 163 | <h1>View 1</h1> |
| 164 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 165 | <ul data-dojo-type="dojox.mobile.IconContainer"> |
| 166 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app1", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 167 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app2", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 168 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app3", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 169 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"moveTo", icon:"../../images/icon-1.png", moveTo:"about", transition:"slide"'></li> |
| 170 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"href", icon:"../../images/icon-1.png", href:"../../test_iPhone-RoundRectList.html", transition:"slide"'></li> |
| 171 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"url" , icon:"../../images/icon-1.png", url:"../../view-sample.html", transition:"slide"'></li> |
| 172 | </ul> |
| 173 | </td></tr></tbody></table> |
| 174 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 175 | <div id="view1-IconContainer2place"></div> |
| 176 | </td></tr></tbody></table> |
| 177 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 178 | <ul id="view1-IconContainer3"> |
| 179 | <li id="view1-IconContainer3-IconItem1"><div class="box"></div></li> |
| 180 | <li id="view1-IconContainer3-IconItem2"><div class="box"></div></li> |
| 181 | <li id="view1-IconContainer3-IconItem3"><div class="box"></div></li> |
| 182 | <li id="view1-IconContainer3-IconItem4"></li> |
| 183 | <li id="view1-IconContainer3-IconItem5"></li> |
| 184 | <li id="view1-IconContainer3-IconItem6"></li> |
| 185 | </ul> |
| 186 | </td></tr></tbody></table> |
| 187 | </div> |
| 188 | <div id="view2" data-dojo-type="dojox.mobile.View"> |
| 189 | <h1>View 2</h1> |
| 190 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 191 | <ul data-dojo-type="dojox.mobile.IconContainer"> |
| 192 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app1", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 193 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app2", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 194 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"app3", icon:"../../images/icon-1.png", lazy:"true"'><div class="box"></div></li> |
| 195 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"moveTo", icon:"../../images/icon-1.png", moveTo:"about", transition:"slide"'></li> |
| 196 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"href", icon:"../../images/icon-1.png", href:"../../test_iPhone-RoundRectList.html", transition:"slide"'></li> |
| 197 | <li data-dojo-type="dojox.mobile.IconItem" data-dojo-props='label:"url" , icon:"../../images/icon-1.png", url:"../../view-sample.html", transition:"slide"'></li> |
| 198 | </ul> |
| 199 | </td></tr></tbody></table> |
| 200 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 201 | <div id="view2-IconContainer2place"></div> |
| 202 | </td></tr></tbody></table> |
| 203 | <table style="position:relative"><tbody><tr><td style="width:310px;"><img src="../../../images/blank.png" width="310" height="1" alt=""/> |
| 204 | <ul id="view2-IconContainer3"> |
| 205 | <li id="view2-IconContainer3-IconItem1"><div class="box"></div></li> |
| 206 | <li id="view2-IconContainer3-IconItem2"><div class="box"></div></li> |
| 207 | <li id="view2-IconContainer3-IconItem3"><div class="box"></div></li> |
| 208 | <li id="view2-IconContainer3-IconItem4"></li> |
| 209 | <li id="view2-IconContainer3-IconItem5"></li> |
| 210 | <li id="view2-IconContainer3-IconItem6"></li> |
| 211 | </ul> |
| 212 | </td></tr></tbody></table> |
| 213 | </div> |
| 214 | </body> |
| 215 | </html> |