1
|
-<!DOCTYPE html>
|
|
|
2
|
-<html>
|
|
|
3
|
- <head>
|
|
|
4
|
- <meta charset="utf-8">
|
|
|
5
|
- <title>A Gentle Introduction 2</title>
|
|
|
6
|
-
|
|
|
7
|
- <script
|
|
|
8
|
- src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">
|
|
|
9
|
- </script>
|
|
|
10
|
-
|
|
|
11
|
- <script
|
|
|
12
|
- src="https://rawgit.com/flatiron/director/master/build/director.min.js">
|
|
|
13
|
- </script>
|
|
|
14
|
-
|
|
|
15
|
- <script>
|
|
|
16
|
- $('document').ready(function() {
|
|
|
17
|
- //
|
|
|
18
|
- // create some functions to be executed when
|
|
|
19
|
- // the correct route is issued by the user.
|
|
|
20
|
- //
|
|
|
21
|
- var showAuthorInfo = function () { console.log("showAuthorInfo"); };
|
|
|
22
|
- var listBooks = function () { console.log("listBooks"); };
|
|
|
23
|
-
|
|
|
24
|
- var allroutes = function() {
|
|
|
25
|
- var route = window.location.hash.slice(2);
|
|
|
26
|
- var sections = $('section');
|
|
|
27
|
- var section;
|
|
|
28
|
-
|
|
|
29
|
- section = sections.filter('[data-route=' + route + ']');
|
|
|
30
|
-
|
|
|
31
|
- if (section.length) {
|
|
|
32
|
- sections.hide(250);
|
|
|
33
|
- section.show(250);
|
|
|
34
|
- }
|
|
|
35
|
- };
|
|
|
36
|
-
|
|
|
37
|
- //
|
|
|
38
|
- // define the routing table.
|
|
|
39
|
- //
|
|
|
40
|
- var routes = {
|
|
|
41
|
- '/author': showAuthorInfo,
|
|
|
42
|
- '/books': listBooks
|
|
|
43
|
- };
|
|
|
44
|
-
|
|
|
45
|
- //
|
|
|
46
|
- // instantiate the router.
|
|
|
47
|
- //
|
|
|
48
|
- var router = Router(routes);
|
|
|
49
|
-
|
|
|
50
|
- //
|
|
|
51
|
- // a global configuration setting.
|
|
|
52
|
- //
|
|
|
53
|
- router.configure({
|
|
|
54
|
- on: allroutes
|
|
|
55
|
- });
|
|
|
56
|
-
|
|
|
57
|
- router.init();
|
|
|
58
|
- });
|
|
|
59
|
- </script>
|
|
|
60
|
- </head>
|
|
|
61
|
-
|
|
|
62
|
- <body>
|
|
|
63
|
- <section data-route="author">Author Name</section>
|
|
|
64
|
- <section data-route="books">Book1, Book2, Book3</section>
|
|
|
65
|
- <ul>
|
|
|
66
|
- <li><a href="#/author">#/author</a></li>
|
|
|
67
|
- <li><a href="#/books">#/books</a></li>
|
|
|
68
|
- </ul>
|
|
|
69
|
- </body>
|
|
|
70
|
-</html> |
|
|