event.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <script type="text/javascript" src="../build/jsMotif.js"></script>
  6. <title>jsMotif event example</title>
  7. <style>
  8. .replica{
  9. cursor: pointer;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <div id="replica1" style="background-color: red" class="replica"></div>
  15. <div id="replica2" style="background-color: green" class="replica"></div>
  16. <div id="replica3" style="background-color: black; color: lawngreen" class="replica"></div>
  17. <div id="action"></div>
  18. <script id="template" type="text/template">
  19. <div rel="click-me">
  20. <div>
  21. <label>Name:</label>
  22. <span fill="{name}"></span><br>
  23. </div>
  24. <p>
  25. <label>Address:</label><br>
  26. <span fill="{location.address.houseNumber}"></span>
  27. <span fill="{location.address.street}"></span><br>
  28. <span fill="{location.address.city}"></span>,
  29. <span fill="{location.address.countryName}"></span>
  30. </p>
  31. </div>
  32. </script>
  33. <script type="text/javascript">
  34. var place =
  35. {
  36. name: 'Le Marfil',
  37. contacts: [
  38. {
  39. description: 'Info',
  40. type: 'email',
  41. value: 'info@lemarfil.fr'
  42. }
  43. ],
  44. location: {
  45. address: {
  46. city: 'Paris',
  47. street: 'Rue Auguste Vacquerie',
  48. houseNumber: '4',
  49. countryName: 'France'
  50. }
  51. },
  52. media: [
  53. {
  54. sourceName: 'provider',
  55. URL: 'http://image.com/image.jpg'
  56. },
  57. {
  58. sourceName: 'orange',
  59. URL: 'http://image.com/image.png'
  60. },
  61. {
  62. sourceName: 'orange',
  63. URL: 'http://image.com/image.gif'
  64. }
  65. ]
  66. };
  67. var tpl = new jsMotif.Template({
  68. template: 'template',
  69. targetNode: 'replica1',
  70. events: [
  71. {
  72. rel: "click-me", // This has to match the value of the respective HTML element's rel attribute
  73. name: "click", // This is the event type
  74. handler: function (jsonObject) {
  75. var actionDiv = document.getElementById("action");
  76. // HTML element on which the event was triggered can be accessed using "this"
  77. actionDiv.innerHTML = "You clicked on " + this.parentNode.id + " (" + this.parentNode.style.backgroundColor + "): "
  78. // JSON object is passed as a parameter to the event handler
  79. + jsonObject.name + ", " + jsonObject.location.address.houseNumber + " " + jsonObject.location.address.street + ", "
  80. + jsonObject.location.address.city;
  81. }
  82. }
  83. ]
  84. });
  85. // Render place object to a default node (replica1 specified in targetNode)
  86. tpl.render(place);
  87. // Render place object to other nodes (replica2, replica3)
  88. tpl.render(place, 'replica2');
  89. tpl.render(place, 'replica3');
  90. </script>
  91. </body>
  92. </html>