/index_08.html

https://bitbucket.org/makbulkhan/drupal_mobile_backend · HTML · 98 lines · 83 code · 12 blank · 3 comment · 0 complexity · 8a90ccf118616e5a1c5bc42b15ece0e3 MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Bird Sightings</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
  8. <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  9. <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
  10. <script src="http://twitter.github.com/hogan.js/builds/2.0.0/hogan-2.0.0.js"></script>
  11. <!-- bird list template -->
  12. <script type="text/template" id="bird-li-tpl">
  13. {{#list}}
  14. <li><a href="#bird?nid={{nid}}" data-ajax="false"><h4>{{title}}</h4></a></li>
  15. {{/list}}
  16. </script>
  17. <!-- bird detail page template -->
  18. <script type="text/template" id="bird-detail-tpl">
  19. <h2>{{title}}</h2>
  20. <p id="bird-image"></p>
  21. <p>{{#body}}{{value}}{{/body}}</p>
  22. </script>
  23. <!-- image template -->
  24. <script type="text/template" id="image-tpl">
  25. <img style="max-width: 100%;" src="{{url}}"/>
  26. </script>
  27. </head>
  28. <body>
  29. <div data-role="page" id="birds">
  30. <div data-role="header">
  31. <h1>Birds</h1>
  32. </div><!-- /header -->
  33. <div data-role="content">
  34. <ul id="bird-list" data-role="listview"></ul>
  35. </div><!-- /content -->
  36. </div><!-- /page -->
  37. <div data-role="page" id="bird">
  38. <div data-role="header">
  39. <a href="#" data-role="button" data-rel="back" data-icon="arrow-l">Back</a>
  40. <h1>Bird details</h1>
  41. </div><!-- /header -->
  42. <div data-role="content">
  43. <p>Content goes here...</p>
  44. </div><!-- /content -->
  45. </div><!-- /page -->
  46. <script>
  47. var bird_server = 'birds.mamp.chandima.info';
  48. var birdListTpl = Hogan.compile($("#bird-li-tpl").html());
  49. var birdDetailTpl = Hogan.compile($("#bird-detail-tpl").html());
  50. var imageTpl = Hogan.compile($("#image-tpl").html());
  51. // bird list page
  52. $('#birds').on('pageshow', function(event, ui){
  53. $.getJSON('http://'+bird_server+'/node.json?type=bird', function(data) {
  54. var html = birdListTpl.render(data);
  55. $('#bird-list').html(html);
  56. $('#bird-list').listview('refresh');
  57. });
  58. });
  59. // bird detail page before show
  60. $('#bird').on('pagebeforeshow', function(event, ui){
  61. $("#bird div[data-role='content']").html('<p>Loading...</p>');
  62. });
  63. // bird detail page show
  64. $('#bird').on('pageshow', function(event, ui){
  65. if (nid = $.urlParam('nid')) {
  66. $.getJSON('http://'+bird_server+'/node/'+nid+'.json', function(node_data) {
  67. var html = birdDetailTpl.render(node_data);
  68. $("#bird div[data-role='content']").html(html).trigger('create');
  69. if (node_data.field_image) {
  70. $.getJSON('http://'+bird_server+'/file/'+node_data.field_image.file.id+'.json', function(file_data) {
  71. html = imageTpl.render(file_data);
  72. $("#bird #bird-image").html(html);
  73. });
  74. }
  75. });
  76. }
  77. });
  78. // return query param
  79. // @see http://stackoverflow.com/questions/11388700/passing-data-between-pages-in-jquery-mobile
  80. $.urlParam = function(name){
  81. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  82. return (results) ? results[1] : null;
  83. }
  84. </script>
  85. </body>
  86. </html>