1 |
|
2 | <div id="app"></div>
|
3 |
|
4 |
|
5 |
|
6 | <script id="helloword" type="text/regular" name="helloword">
|
7 | Hello
|
8 | {{#if user}}
|
9 | <strong> ¢ {{user}}</strong>, <a href='#' on-click={{user = null}}>logout</a>
|
10 | {{#else}}
|
11 | Friend, please <a href='#' on-click={{this.login()}}>login</a>
|
12 | {{/if}}
|
13 | </script>
|
14 |
|
15 | <script src="../dist/regular.js"></script>
|
16 | <script src="https://rawgit.com/flatiron/director/master/build/director.js"></script>
|
17 |
|
18 | <ul>
|
19 | <li><a href="#/author">#/author</a></li>
|
20 | <li><a href="#/books/books">#/books</a></li>
|
21 | <li><a href="#/books/view/1">#/books/view/1</a></li>
|
22 | </ul>
|
23 |
|
24 |
|
25 |
|
26 | <script>
|
27 | var LoginApp = Regular.extend({
|
28 |
|
29 |
|
30 | template: '#helloword',
|
31 | login: function(){
|
32 |
|
33 | var data = this.data;
|
34 |
|
35 | data.user = prompt("Please Enter you name", "");
|
36 | }
|
37 | });
|
38 |
|
39 | var application = new LoginApp().inject('#app');
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var author = function () { console.log("author"); };
|
45 | var books = function () { console.log("books"); };
|
46 | var viewBook = function (bookId) {
|
47 | console.log("viewBook: bookId is populated: " + bookId);
|
48 | };
|
49 |
|
50 | var routes = {
|
51 | '/author': author,
|
52 | '/books' :{
|
53 | books:function(){
|
54 | console.log('hahaha')
|
55 | },
|
56 | },
|
57 | "/:id/books": function(){
|
58 | console.log(arguments, "haha")
|
59 | },
|
60 | '/books/:bookId': viewBook,
|
61 | 'notfound': function(){
|
62 |
|
63 | }
|
64 | };
|
65 |
|
66 | var router = Router(routes).configure({
|
67 | after: function(){
|
68 | console.log(arguments, 'after')
|
69 | },
|
70 | before: function(){
|
71 | console.log(arguments, 'before')
|
72 | },
|
73 | notfound: function(){
|
74 | console.log(arguments, 'notfound')
|
75 | }
|
76 | });
|
77 |
|
78 | router.init();
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | </script>
|
84 |
|