history3js.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>History Demo JavaScript Page</title>
  10. </head>
  11. <body>
  12. <script src="../base.js"></script>
  13. <script>
  14. goog.require('goog.History');
  15. goog.require('goog.debug.DivConsole');
  16. goog.require('goog.dom');
  17. goog.require('goog.events');
  18. goog.require('goog.history.EventType');
  19. goog.require('goog.log');
  20. </script>
  21. <script>
  22. var logger = goog.log.getLogger('demo');
  23. var logconsole = new goog.debug.DivConsole(top.document.getElementById('log'));
  24. logconsole.setCapturing(true);
  25. var events = goog.object.getValues(goog.history.EventType);
  26. goog.log.info(logger, 'Listening for: ' + events.join(', ') + '.');
  27. var googHist = new goog.History(
  28. false, 'history_blank.html', top.document.getElementById('hist_state'));
  29. goog.events.listen(googHist, events, function(e) {
  30. goog.log.info(logger, goog.string.subs('dispatched: %s (token="%s", isNavigation=%s)',
  31. e.type, e.token, e.isNavigation));
  32. });
  33. goog.events.listen(googHist, goog.History.EventType.NAVIGATE, navCallback);
  34. googHist.setEnabled(true);
  35. function navCallback(e) {
  36. var output = top.document.getElementById('token_output');
  37. if (output) {
  38. var token = (e.token == null) ? 'null' : '\u201C' + e.token + '\u201D';
  39. goog.dom.setTextContent(output, token);
  40. }
  41. }
  42. </script>
  43. </body>
  44. </html>