| 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>ListItem Actions</title> |
| 8 | |
| 9 | <script type="text/javascript" src="../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base']"></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/_base/connect", |
| 15 | "dojo/_base/window", |
| 16 | "dojo/dom-construct", |
| 17 | "dojo/ready", |
| 18 | "dijit/registry", |
| 19 | "dojo/data/ItemFileReadStore", |
| 20 | "dojox/mobile/ProgressIndicator", |
| 21 | "dojox/mobile/ListItem", |
| 22 | "dojox/mobile/parser", |
| 23 | "dojox/mobile", |
| 24 | "dojox/mobile/compat", |
| 25 | "dojox/mobile/ScrollableView", |
| 26 | "dojox/mobile/RoundRectDataList", |
| 27 | "dojox/mobile/ContentPane" |
| 28 | ], function(connect, win, domConstruct, ready, registry, ItemFileReadStore, ProgressIndicator, ListItem, parser){ |
| 29 | var static_data = { |
| 30 | items: [ |
| 31 | {label: "Apple", moveTo: "home", icon: "images/i-icon-1.png"}, |
| 32 | {label: "Banana", moveTo: "home", icon: "images/i-icon-2.png"}, |
| 33 | {label: "Cherry", moveTo: "home", icon: "images/i-icon-3.png"}, |
| 34 | {label: "Grape", moveTo: "home", icon: "images/i-icon-4.png"}, |
| 35 | {label: "Kiwi", moveTo: "home", icon: "images/i-icon-5.png"}, |
| 36 | {label: "Lemon", moveTo: "home", icon: "images/i-icon-6.png"}, |
| 37 | {label: "Melon", moveTo: "home", icon: "images/i-icon-7.png"}, |
| 38 | {label: "Orange", moveTo: "home", icon: "images/i-icon-8.png"}, |
| 39 | {label: "Peach", moveTo: "home", icon: "images/i-icon-9.png"} |
| 40 | ] |
| 41 | }; |
| 42 | |
| 43 | // Update existing view content and make transition |
| 44 | myAction1 = function(){ |
| 45 | var rect = registry.byId("rect1"); |
| 46 | rect.containerNode.innerHTML = new Date(); |
| 47 | this.transitionTo("view1"); |
| 48 | } |
| 49 | |
| 50 | // Load content into existing view and make transition |
| 51 | myAction2 = function(){ |
| 52 | var view2 = registry.byId("view2"); // destination view |
| 53 | var listItem = this; |
| 54 | var prog = ProgressIndicator.getInstance(); |
| 55 | win.body().appendChild(prog.domNode); |
| 56 | prog.start(); |
| 57 | view2.destroyDescendants(); |
| 58 | |
| 59 | /* |
| 60 | var url = "http://..."; // or var url = listItem.url; |
| 61 | dojo.xhrGet({ |
| 62 | url: url, |
| 63 | handleAs: "text", |
| 64 | load: function(response, ioArgs){ |
| 65 | var container = view2.containerNode; |
| 66 | container.innerHTML = response; |
| 67 | parser.parse(container); |
| 68 | prog.stop(); |
| 69 | listItem.transitionTo("view2"); |
| 70 | } |
| 71 | }); |
| 72 | */ |
| 73 | setTimeout(function(){ // network latency simulation |
| 74 | var markup = '<h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props=\'back:"Home", moveTo:"home"\'>Loaded View 1</h1>' + |
| 75 | '<div data-dojo-type="dojox.mobile.RoundRect" data-dojo-props=\'shadow:true\'>Thank you!</div>'; |
| 76 | var container = view2.containerNode; |
| 77 | container.innerHTML = markup; |
| 78 | parser.parse(container); |
| 79 | prog.stop(); |
| 80 | listItem.transitionTo("view2"); |
| 81 | }, 5000); |
| 82 | } |
| 83 | |
| 84 | // Make transition and load content into existing view |
| 85 | myAction3 = function(){ |
| 86 | var view3 = registry.byId("view3"); // destination view |
| 87 | var listItem = this; |
| 88 | var prog = ProgressIndicator.getInstance(); |
| 89 | win.body().appendChild(prog.domNode); |
| 90 | prog.start(); |
| 91 | view3.destroyDescendants(); |
| 92 | listItem.transitionTo("view3"); |
| 93 | |
| 94 | /* |
| 95 | var url = "http://..."; // or var url = listItem.url; |
| 96 | dojo.xhrGet({ |
| 97 | url: url, |
| 98 | handleAs: "text", |
| 99 | load: function(response, ioArgs){ |
| 100 | var container = view3.containerNode; |
| 101 | container.innerHTML = response; |
| 102 | parser.parse(container); |
| 103 | prog.stop(); |
| 104 | } |
| 105 | }); |
| 106 | */ |
| 107 | setTimeout(function(){ // network latency simulation |
| 108 | var markup = '<h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props=\'back:"Home", moveTo:"home"\'>Loaded View 2</h1>' + |
| 109 | '<div data-dojo-type="dojox.mobile.RoundRect" data-dojo-props=\'shadow:true\'>Gracias!</div>'; |
| 110 | var container = view3.containerNode; |
| 111 | container.innerHTML = markup; |
| 112 | parser.parse(container); |
| 113 | prog.stop(); |
| 114 | }, 5000); |
| 115 | } |
| 116 | |
| 117 | // Create a new view and make transition |
| 118 | myAction4 = function(){ |
| 119 | if(!registry.byId("view4")){ |
| 120 | var view4 = new dojox.mobile.View({ |
| 121 | id: "view4", |
| 122 | selected: true |
| 123 | }, domConstruct.create("DIV", null, win.body())); |
| 124 | view4.startup(); |
| 125 | |
| 126 | var heading1 = new dojox.mobile.Heading({ |
| 127 | label: "Dynamic View", |
| 128 | back: "Home", |
| 129 | moveTo: "home" |
| 130 | }); |
| 131 | heading1.placeAt(view4.containerNode); |
| 132 | heading1.startup(); |
| 133 | |
| 134 | var categ1 = new dojox.mobile.RoundRectCategory({ |
| 135 | label: "Documents" |
| 136 | }); |
| 137 | categ1.placeAt(view4.containerNode); |
| 138 | categ1.startup(); |
| 139 | |
| 140 | var list1 = new dojox.mobile.RoundRectList(); |
| 141 | list1.placeAt(view4.containerNode); |
| 142 | list1.startup(); |
| 143 | |
| 144 | var counter = 4; |
| 145 | for(var i = 1; i <= 3; i++){ |
| 146 | var item1 = new dojox.mobile.ListItem({ |
| 147 | icon: "images/i-icon-"+i+".png", |
| 148 | label: "Document 000"+counter |
| 149 | }); |
| 150 | item1.placeAt(list1.containerNode); |
| 151 | item1.startup(); |
| 152 | counter++; |
| 153 | } |
| 154 | } |
| 155 | this.transitionTo("view4"); |
| 156 | } |
| 157 | |
| 158 | // Update DataList |
| 159 | myAction5 = function(){ |
| 160 | var list1 = registry.byId("list1"); |
| 161 | if(!list1.store){ |
| 162 | var store1 = new ItemFileReadStore({data: static_data}); |
| 163 | list1.setStore(store1, {label: '*e'}); // items whose label ends with 'e' |
| 164 | } |
| 165 | this.transitionTo("view5"); |
| 166 | } |
| 167 | |
| 168 | // Partial Update using dojox.mobile.ContentPane |
| 169 | myAction6 = function(){ |
| 170 | var pane1 = registry.byId("pane1"); |
| 171 | if(!pane1.domNode.innerHTML){ // nothing has been loaded yet |
| 172 | connect.connect(pane1, "onLoad", this, function(){ |
| 173 | // onLoad fires when the content is ready |
| 174 | this.transitionTo("view6"); |
| 175 | }); |
| 176 | pane1.set("href", "data/fragment1.html"); |
| 177 | }else{ |
| 178 | this.transitionTo("view6"); |
| 179 | } |
| 180 | } |
| 181 | }); |
| 182 | </script> |
| 183 | </head> |
| 184 | <body style="visibility:hidden;"> |
| 185 | <div id="home" data-dojo-type="dojox.mobile.View" data-dojo-props='selected:true'> |
| 186 | <h1 data-dojo-type="dojox.mobile.Heading">Action and Transition</h1> |
| 187 | <h2 data-dojo-type="dojox.mobile.RoundRectCategory">ListItem Actions</h2> |
| 188 | <ul data-dojo-type="dojox.mobile.RoundRectList"> |
| 189 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-1.png", moveTo:"#", transition:"slide", onClick:myAction1'> |
| 190 | Update View |
| 191 | </li> |
| 192 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-2.png", moveTo:"#", transition:"slide", onClick:myAction2'> |
| 193 | Load and Move (async) |
| 194 | </li> |
| 195 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-3.png", moveTo:"#", transition:"slide", onClick:myAction3'> |
| 196 | Move and Load (async) |
| 197 | </li> |
| 198 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-4.png", moveTo:"#", transition:"slide", onClick:myAction4'> |
| 199 | Create View |
| 200 | </li> |
| 201 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-5.png", moveTo:"#", transition:"slide", onClick:myAction5'> |
| 202 | Data List |
| 203 | </li> |
| 204 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-6.png", moveTo:"#", transition:"slide", onClick:myAction6'> |
| 205 | Partial Update (async) |
| 206 | </li> |
| 207 | </ul> |
| 208 | </div> |
| 209 | |
| 210 | <div id="view1" data-dojo-type="dojox.mobile.View"> |
| 211 | <h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props='back:"Home", moveTo:"home"'>Current Status</h1> |
| 212 | Local Time: |
| 213 | <div id="rect1" data-dojo-type="dojox.mobile.RoundRect" data-dojo-props='shadow:true'></div> |
| 214 | </div> |
| 215 | |
| 216 | <div id="view2" data-dojo-type="dojox.mobile.View"> |
| 217 | </div> |
| 218 | |
| 219 | <div id="view3" data-dojo-type="dojox.mobile.View"> |
| 220 | </div> |
| 221 | |
| 222 | <div id="view5" data-dojo-type="dojox.mobile.View"> |
| 223 | <h1 data-dojo-type="dojox.mobile.Heading">RoundRectDataList</h1> |
| 224 | <ul id="list1" data-dojo-type="dojox.mobile.RoundRectDataList"></ul> |
| 225 | </div> |
| 226 | |
| 227 | <div id="view6" data-dojo-type="dojox.mobile.ScrollableView"> |
| 228 | <h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props='back:"Home", moveTo:"home", fixed:"top"'>Partial Update</h1> |
| 229 | Dynamic Content: |
| 230 | <div id="pane1" data-dojo-type="dojox.mobile.ContentPane"></div> |
| 231 | <ul data-dojo-type="dojox.mobile.RoundRectList"> |
| 232 | <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='icon:"images/i-icon-1.png", moveTo:"home", transitionDir:-1'> |
| 233 | Home |
| 234 | </li> |
| 235 | </ul> |
| 236 | </div> |
| 237 | </body> |
| 238 | </html> |