| 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>EdgeToEdgeStoreList - Auto Load</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/Deferred", |
| 15 | "dojo/dom-class", |
| 16 | "dojo/store/Cache", |
| 17 | "dojo/store/JsonRest", |
| 18 | "dojo/store/Memory", |
| 19 | "dojo/store/Observable", |
| 20 | "dojo/ready", |
| 21 | "dijit/registry", |
| 22 | "dojox/mobile/ProgressIndicator", |
| 23 | "dojox/mobile/parser", |
| 24 | "dojox/mobile", |
| 25 | "dojox/mobile/compat", |
| 26 | "dojox/mobile/ScrollableView", |
| 27 | "dojox/mobile/EdgeToEdgeStoreList" |
| 28 | ], function(Deferred, domClass, Cache, JsonRest, Memory, Observable, ready, registry, ProgressIndicator){ |
| 29 | //var url = "data/fruits.json"; |
| 30 | var url = "data/fake_service.php"; |
| 31 | var memoryStore = new Memory({idProperty:"label"}); |
| 32 | var restStore = new JsonRest({idProperty:"label", target: url}); |
| 33 | store = new Cache(restStore, memoryStore); |
| 34 | |
| 35 | var start = 1, |
| 36 | count = 5, |
| 37 | prog1 = null, |
| 38 | list = null; |
| 39 | function loadMore(){ |
| 40 | busy(true); |
| 41 | setTimeout(function(){ // to simulate network latency |
| 42 | Deferred.when(list.setQuery({start:start, count:count}), function(){ |
| 43 | busy(false); |
| 44 | }); |
| 45 | start += count; |
| 46 | return false; |
| 47 | }, 1000); |
| 48 | }; |
| 49 | |
| 50 | function busy(flag){ |
| 51 | if(!prog1){ |
| 52 | prog1 = new ProgressIndicator({size:30, center:false}); |
| 53 | prog1.domNode.style.position = "absolute"; |
| 54 | prog1.domNode.style.margin = "5px"; |
| 55 | domClass.add(prog1.domNode, "mblProgWhite"); |
| 56 | } |
| 57 | if(flag){ |
| 58 | var head1 = registry.byId("head1"); |
| 59 | prog1.placeAt(head1.domNode); |
| 60 | prog1.start(); |
| 61 | }else{ |
| 62 | prog1.stop(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | adjustDestination = function(to, pos, dim){ |
| 67 | var dim = this.getDim(); |
| 68 | var h = dim.c.h; // container height |
| 69 | var disp = dim.d.h; // display height |
| 70 | if(to.y < disp - h){ |
| 71 | loadMore(); |
| 72 | to.y = disp - h; |
| 73 | } |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | ready(function(){ |
| 78 | list = registry.byId("list"); |
| 79 | list.setStore(store, {start:start, count:count}); |
| 80 | start += count; |
| 81 | }); |
| 82 | }); |
| 83 | </script> |
| 84 | </head> |
| 85 | <body style="visibility:hidden;"> |
| 86 | <div data-dojo-type="dojox.mobile.ScrollableView" data-dojo-props='adjustDestination:adjustDestination'> |
| 87 | <h1 data-dojo-type="dojox.mobile.Heading" id="head1" data-dojo-props='fixed:"top"'>EdgeToEdgeStoreList</h1> |
| 88 | <ul data-dojo-type="dojox.mobile.EdgeToEdgeStoreList" id="list" data-dojo-props='append:true'></ul> |
| 89 | </div> |
| 90 | </body> |
| 91 | </html> |