aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/history3js.html
blob: a575a047306db2c1ef5abd42c988dbbe8beb78b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>History Demo JavaScript Page</title>
</head>
<body>
<script src="../base.js"></script>
<script>
goog.require('goog.History');
goog.require('goog.debug.DivConsole');
goog.require('goog.debug.Logger');
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.history.EventType');
</script>
<script>
var logger = goog.debug.Logger.getLogger('demo');
var logconsole = new goog.debug.DivConsole(top.document.getElementById('log'));
logconsole.setCapturing(true);

var events = goog.object.getValues(goog.history.EventType);
logger.info('Listening for: ' + events.join(', ') + '.');

var googHist = new goog.History(
    false, 'history_blank.html', top.document.getElementById('hist_state'));
goog.events.listen(googHist, events, function(e) {
  logger.info(goog.string.subs('dispatched: %s (token="%s", isNavigation=%s)',
      e.type, e.token, e.isNavigation));
});
goog.events.listen(googHist, goog.History.EventType.NAVIGATE, navCallback);
googHist.setEnabled(true);

function navCallback(e) {
  var output = top.document.getElementById('token_output');
  if (output) {
    var token = (e.token == null) ? 'null' : '\u201C' + e.token + '\u201D';
    goog.dom.setTextContent(output, token);
  }
}
</script>
</body>
</html>