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