goog.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>RequireJS Google Ajax API plugin</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <style>
  8. .info{background-color:#cfc; border:2px solid #ada; padding:10px 20px; margin:2em 0}
  9. </style>
  10. </head>
  11. <body>
  12. <div id="wrapper">
  13. <h1>RequireJS + Google Ajax API plugin</h1>
  14. <div class="info">
  15. <p>
  16. This plugin depends on the Async plugin and loads files using the <code>google.load</code> method from the <a href="http://code.google.com/apis/loader/">Google Loader</a>.
  17. </p>
  18. <p>
  19. Notice that it can only load the libraries listed on the <a href="http://code.google.com/apis/loader/#AvailableAPIs">Available APIs section</a>.
  20. </p>
  21. </div>
  22. <h2>Google Charts - corechart</h2>
  23. <div id="chart_div"></div>
  24. <h2>Google Charts - geochart</h2>
  25. <div id="map_canvas" style="width:500px"></div>
  26. <h2>Google Search API</h2>
  27. <div id="branding"></div>
  28. <div id="search_results"> </div>
  29. </div>
  30. <script src="../lib/require.js"></script>
  31. <script>
  32. require({
  33. waitSeconds : 15, //make sure it is enough to load all scripts
  34. paths : {
  35. //alias to plugins
  36. async : '../src/async',
  37. goog : '../src/goog',
  38. propertyParser : '../src/propertyParser'
  39. }
  40. });
  41. //To load google libraries you should follow the format "goog!moduleName,version,packages:[packages],language:en,anotherOption:value"
  42. require(['goog!visualization,1,packages:[corechart,geochart]', 'goog!search,1'], function(){
  43. // visualization + corechart + geochart + search are loaded
  44. // code copied from google charts docs:
  45. // http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html
  46. var data = new google.visualization.DataTable();
  47. data.addColumn('string', 'Task');
  48. data.addColumn('number', 'Hours per Day');
  49. data.addRows(5);
  50. data.setValue(0, 0, 'Work');
  51. data.setValue(0, 1, 11);
  52. data.setValue(1, 0, 'Eat');
  53. data.setValue(1, 1, 2);
  54. data.setValue(2, 0, 'Commute');
  55. data.setValue(2, 1, 2);
  56. data.setValue(3, 0, 'Watch TV');
  57. data.setValue(3, 1, 2);
  58. data.setValue(4, 0, 'Sleep');
  59. data.setValue(4, 1, 7);
  60. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  61. chart.draw(data, {width: 450, height: 300, title: 'My Daily Activities'});
  62. // code copied from google charts docs:
  63. // http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html
  64. var data = new google.visualization.DataTable();
  65. data.addRows(6);
  66. data.addColumn('string', 'Country');
  67. data.addColumn('number', 'Popularity');
  68. data.setValue(0, 0, 'Germany');
  69. data.setValue(0, 1, 200);
  70. data.setValue(1, 0, 'United States');
  71. data.setValue(1, 1, 300);
  72. data.setValue(2, 0, 'Brazil');
  73. data.setValue(2, 1, 400);
  74. data.setValue(3, 0, 'Canada');
  75. data.setValue(3, 1, 500);
  76. data.setValue(4, 0, 'France');
  77. data.setValue(4, 1, 600);
  78. data.setValue(5, 0, 'RU');
  79. data.setValue(5, 1, 700);
  80. var options = {};
  81. var container = document.getElementById('map_canvas');
  82. var geochart = new google.visualization.GeoChart(container);
  83. geochart.draw(data, options);
  84. //code copied from http://code.google.com/apis/ajax/playground/?exp=libraries#the_hello_world_of_news_search
  85. //and slightly modified
  86. var newsSearch = new google.search.WebSearch(),
  87. resultHolder = document.getElementById('search_results');
  88. function searchComplete() {
  89. resultHolder.innerHTML = '';
  90. if (newsSearch.results && newsSearch.results.length > 0) {
  91. for (var i = 0; i < newsSearch.results.length; i++) {
  92. var p = document.createElement('p');
  93. var a = document.createElement('a');
  94. a.href = newsSearch.results[i].url;
  95. a.innerHTML = newsSearch.results[i].title;
  96. p.appendChild(a);
  97. resultHolder.appendChild(p);
  98. }
  99. }
  100. }
  101. newsSearch.setSearchCompleteCallback(this, searchComplete, null);
  102. newsSearch.execute('RequireJS plugins');
  103. // Include the required Google branding
  104. google.search.Search.getBranding('branding');
  105. });
  106. </script>
  107. </body>
  108. </html>