index.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!-- This is an example of using the same template with different data -->
  2. <head>
  3. <!-- include our libraries and css files -->
  4. <script src="js/jquery-2.1.4.min.js"></script>
  5. <script src="js/handlebars-v3.0.3.js"></script>
  6. <script src="js/bootstrap.min.js"></script>
  7. <link href="css/bootstrap.css" rel="stylesheet">
  8. <link href="css/gallery.css" rel="stylesheet">
  9. </head>
  10. <body role="document">
  11. <div class="container">
  12. <div class="page-header">
  13. <h1>My photo albums </h1>
  14. </div>
  15. <!-- this is a simple nav bar for selecting between images -->
  16. <ul class="nav nav-tabs">
  17. <li role="" id="image1btn">
  18. <a href="#">Image 1</a>
  19. </li>
  20. <li role="" id="image2btn">
  21. <a href="#">Image 2</a>
  22. </li>
  23. </ul>
  24. <br /><br />
  25. <!-- the content of the web page starts off empty
  26. because we will fill it later from the template -->
  27. <div id="content" class="container-fluid" role="main">
  28. </div>
  29. </div>
  30. <!-- this is our template
  31. it displays an image with a title and author headings
  32. the bits in curly brackets {{}} are template expressions.
  33. This code uses Bootstrap to provide a grid based layout
  34. -->
  35. <script id="detail-template" type="text/x-handlebars-template">
  36. <br />
  37. <div class="row-fluid">
  38. <div class="col-sm-5">
  39. <img style="width:100%" src="{{src}}" />
  40. </div>
  41. <div class="col-sm-7">
  42. <h1>{{title}}</h1>
  43. <h3 class="author">
  44. {{author}}
  45. </h3>
  46. </div>
  47. </div>
  48. </script>
  49. <!-- javascript code to fill the template -->
  50. <script type="text/javascript">
  51. var data = {
  52. image1btn: {
  53. src: "images/The_Earth_seen_from_Apollo_17.jpg",
  54. title: "The Earth seen from Apollo 17",
  55. author: "Ed g2s"
  56. },
  57. image2btn: {
  58. src: "images/Shopping_Center_Magna_Plaza_Amsterdam_2014.jpg",
  59. title: "Shopping Center Magna Plaza Amsterdam 2014",
  60. author: "Tuxyso"
  61. }
  62. };
  63. // Get the template and compile it once when the page loads.
  64. var source = $("#detail-template").html();
  65. var detail_template = Handlebars.compile(source);
  66. // Instantiate the template with data whenever you click
  67. // There is only one handler on only one element.
  68. $('ul.nav.nav-tabs').click(function (event) {
  69. var id = $(event.originalEvent.target).parent().attr('id');
  70. var html = detail_template(data[id]);
  71. $('#content').html(html);
  72. });
  73. </script>
  74. </body>