Debian Codegraph @

closure-library/closure/goog/demos/history1.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>goog.History</title>
11 <link rel="stylesheet" href="css/demo.css">
12 <style>
13 table {
14 border: 1px solid #666;
15 background: lightblue;
16 margin: 1em auto;
17 }
18 td {
19 text-align: center;
20 padding: 0 0.5em 0.5em 0.5em;
21 }
22 </style>
23 <script src="../base.js"></script>
24 <script>
25 goog.require('goog.History');
26 goog.require('goog.debug.DivConsole');
27 goog.require('goog.dom');
28 goog.require('goog.events');
29 goog.require('goog.history.EventType');
30 goog.require('goog.log');
31 goog.require('goog.object');
32 goog.require('goog.string');
33 </script>
34 </head>
35
36 <body>
37 <h1>goog.History</h1>
38 <p>This page demonstrates the goog.History object which can create new browser
39 history entries without leaving the page. This version uses the hash portion of
40 the URL to make the history state available to the user. These URLs can be
41 bookmarked, edited, pasted in emails, etc., just like normal URLs. The browser's
42 back and forward buttons will navigate between the visited history states.</p>
43
44 <p>Try following the hash links below, or updating the location with your own
45 tokens. Replacing the token will update the page address without appending a
46 new history entry.</p>
47
48 <p>
49 Set #fragment<br>
50 <a href="#first">first</a><br>
51 <a href="#second">second</a><br>
52 <a href="#third">third</a>
53 </p>
54
55 <p>
56 Set Token<br>
57 <button onclick="setToken('//\\\\/\\/\\');">//\\/\/\</button>
58 <button onclick="setToken('{\'a\': \'123\', \'b\': \'456\'}');">
59 {'a': '123', 'b': '456'}
60 </button>
61 <button onclick="setToken('!@#$%^&*()_+-={}[]\\|;\':&quot;,./<>?');">
62 !@#$%^&*()_+-={}[]\|;':",./&lt;&gt;
63 </button>
64 <button onclick="setToken('%2F/foo');">%2F/foo</button>
65 <button onclick="setToken('%20 02%');">%20&nbsp;&nbsp;&nbsp;02%</button>
66 </p>
67
68 <p>
69 <input type="text" id="token_input" />
70 <button onclick="setToken()">Set Token</button>
71 <button onclick="replaceToken()">Replace Current Token</button>
72 </p>
73
74 <table><tr><td>
75 <h3>The current history state:</h3>
76 <div id="token_output"></div>
77 </td></tr></table>
78
79 <p>The state should be correctly restored after you
80 <a href="http://www.google.com/">leave the page</a> and hit the back button.</p>
81
82 <p>The history object can also be created so that the history state is not
83 user-visible/modifiable.
84 See <a href="history2.html#came from history 1">history2.html</a> for a demo.
85 To see visible/modifiable history work when the goog.History code itself is
86 loaded inside a hidden iframe,
87 see <a href="history3.html#came from history 1">history3.html</a>.
88 </p>
89
90 <fieldset class="goog-debug-panel">
91 <legend>Event Log</legend>
92 <div id="log"></div>
93 </fieldset>
94
95 <script>
96 var logger = goog.log.getLogger('demo');
97 var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
98 logconsole.setCapturing(true);
99
100 var events = goog.object.getValues(goog.history.EventType);
101 goog.log.info(logger, 'Listening for: ' + events.join(', ') + '.');
102
103 var h = new goog.History();
104 goog.events.listen(h, events, function(e) {
105 goog.log.info(logger, goog.string.subs('dispatched: %s (token="%s", isNavigation=%s)',
106 e.type, e.token, e.isNavigation));
107 });
108 goog.events.listen(h, goog.history.EventType.NAVIGATE, navCallback);
109 h.setEnabled(true);
110
111 function setToken(opt_val) {
112 var input = goog.dom.getElement('token_input');
113 h.setToken(opt_val || input.value);
114 return false;
115 }
116
117 function replaceToken() {
118 var input = goog.dom.getElement('token_input');
119 h.replaceToken(input.value);
120 }
121
122 function navCallback(e) {
123 var output = goog.dom.getElement('token_output');
124 if (output) {
125 var token = (e.token == null) ? 'null' : '\u201C' + e.token + '\u201D';
126 goog.dom.setTextContent(output, token);
127 }
128 }
129 </script>
130
131 </body>
132 </html>