Debian Codegraph @

closure-library/closure/goog/demos/html5history.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.Html5History Demo</title>
11 <script src="../base.js"></script>
12 <script>
13 goog.require('goog.events');
14 goog.require('goog.history.EventType');
15 goog.require('goog.history.Html5History');
16 goog.require('goog.Uri');
17 </script>
18 <style>
19 .section {
20 display: none;
21 }
22
23 .active {
24 display: block;
25 }
26 </style>
27 <link rel="stylesheet" href="css/demo.css">
28 </head>
29 <body>
30 <h1>goog.history.Html5History</h1>
31
32 <p id="links">
33 <a href="kittens/" token="kittens" title="Kittens">Kittens</a> |
34 <a href="puppies/" token="puppies" title="Puppies">Puppies</a> |
35 <a href="pandas/" token="pandas" title="Pandas">Pandas</a> |
36 <a href="bucket/" token="bucket" title="Bucket">Bucket</a>
37 </p>
38
39 <div id="kittens" class="section active">
40 <img src="http://farm4.static.flickr.com/3045/2481490798_bba0c585b4.jpg">
41 </div>
42 <div id="puppies" class="section">
43 <img src="http://farm4.static.flickr.com/3178/2976942142_7f5be73d21.jpg">
44 </div>
45 <div id="pandas" class="section">
46 <img src="http://farm1.static.flickr.com/106/303160549_49917ba1b7.jpg">
47 </div>
48 <div id="bucket" class="section">
49 <img src="http://farm1.static.flickr.com/146/421093356_6bbefa304e.jpg">
50 </div>
51
52 <script>
53 var h;
54 try {
55 h = new goog.history.Html5History();
56 } catch (e) {
57 document.write(e.message);
58 }
59
60 if (h) {
61 var cur = 'kittens';
62
63 goog.events.listen(h, goog.history.EventType.NAVIGATE, function(e) {
64 var token = e.token || 'kittens';
65 var next = document.getElementById(token);
66 if (next) {
67 document.getElementById(cur).className = 'section';
68 next.className = 'section active';
69 cur = token;
70 }
71 });
72
73 h.setUseFragment(false);
74 h.setPathPrefix(new goog.Uri(document.location.href).getPath() + '/');
75 h.setEnabled(true);
76
77 goog.events.listen(
78 document.getElementById('links'), 'click', function(e) {
79 if (e.target.tagName == 'A') {
80 h.setToken(e.target.getAttribute('token'), e.target.title);
81 e.preventDefault();
82 }
83 });
84 }
85 </script>
86 </body>
87 </html>