example08_calendar.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!--
  2. http://code.google.com/apis/gdata/samples/cal_sample.html
  3. -->
  4. <html>
  5. <head>
  6. <title>Timeline demo</title>
  7. <style>
  8. body {font: 10pt arial;}
  9. </style>
  10. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  11. <script type="text/javascript" src="../timeline.js"></script>
  12. <link rel="stylesheet" type="text/css" href="../timeline.css">
  13. <script type="text/javascript">
  14. var cal;
  15. // load the google calendar feed
  16. function insertAgenda(calendar) {
  17. cal = calendar;
  18. }
  19. </script>
  20. <script type="text/javascript" src="http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=20&singleevents=true&sortorder=ascending&futureevents=true"></script>
  21. <script type="text/javascript">
  22. var timeline;
  23. google.load("visualization", "1");
  24. // Set callback to run when API is loaded
  25. google.setOnLoadCallback(drawVisualization);
  26. /**
  27. * Parse a date like "2010-10-07T17:00:00.000-07:00" or "2010-10-07"
  28. * @param {string} googledate
  29. * @return {Date}
  30. */
  31. function parseGoogleDate(googledate) {
  32. var year = parseInt(googledate.substr(0,4), 10);
  33. var month = parseInt(googledate.substr(5,2), 10) - 1;
  34. var date = parseInt(googledate.substr(8,2), 10);
  35. if (googledate.length <= 10) {
  36. var date = new Date(year, month, date);
  37. } else {
  38. var hour = parseInt(googledate.substr(11,2), 10) - parseInt(googledate.substr(25,2), 10);
  39. var minute = parseInt(googledate.substr(14,2), 10) - parseInt(googledate.substr(28,2), 10);
  40. var second = parseInt(googledate.substr(17,2), 10);
  41. var date = new Date(year, month, date, hour, minute, second);
  42. date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
  43. }
  44. return date;
  45. }
  46. // Called when the Visualization API is loaded.
  47. function drawVisualization() {
  48. // Create and populate a data table.
  49. var data = new google.visualization.DataTable();
  50. data.addColumn('datetime', 'start');
  51. data.addColumn('datetime', 'end');
  52. data.addColumn('string', 'content');
  53. for (i = 0; i < cal.feed.entry.length; i++) {
  54. var start = parseGoogleDate(cal.feed.entry[i].gd$when[0].startTime);
  55. var end = parseGoogleDate(cal.feed.entry[i].gd$when[0].endTime);
  56. var title = cal.feed.entry[i].title.$t;
  57. var content = cal.feed.entry[i].content.$t;
  58. var href = cal.feed.entry[i].link[0].href;
  59. var eventcontent = "<a href='" + href + "'>" + title + "</a>";
  60. data.addRow([start, undefined, eventcontent]);
  61. }
  62. // specify options
  63. var options = {
  64. 'width': "100%",
  65. 'height': "auto",
  66. 'style': "dot"
  67. };
  68. // Instantiate our timeline object.
  69. timeline = new links.Timeline(document.getElementById('mytimeline'));
  70. // Draw our timeline with the created data and options
  71. timeline.draw(data, options);
  72. }
  73. </script>
  74. </head>
  75. <body>
  76. <h1>Google upcoming events</h1>
  77. <div id="mytimeline"></div>
  78. </body>
  79. </html>