UNPKG

2.25 kBHTMLView Raw
1<!-- the container -->
2<div id="app"></div>
3
4<!-- Regular template container(optional) -->
5<!-- if you need this component used in other component, you can specify name in the tag-->
6<script id="helloword" type="text/regular" name="helloword">
7 Hello
8 {{#if user}}
9 <strong> &cent; {{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<!-- include regular.js -->
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<!-- Define your Own Component -->
26<script>
27var LoginApp = Regular.extend({
28 // name: 'helloword', if this component need used in other component , you need specify name
29 // you can pass [String| preparsed AST | node selector]
30 template: '#helloword', //if es6 released, multi-line string is
31 login: function(){
32 // all data is store in the plain object `this.data`;
33 var data = this.data;
34 // just like angular, if trigger by the ui , the $digest phase will automate triggerd;
35 data.user = prompt("Please Enter you name", "");
36 }
37});
38
39var application = new LoginApp().inject('#app');
40// you can also inject the component at other position, for example `inject('#app', 'bottom' | 'top' | 'after' | 'before')`, the default is 'bottom'
41
42
43
44var author = function () { console.log("author"); };
45var books = function () { console.log("books"); };
46var viewBook = function (bookId) {
47 console.log("viewBook: bookId is populated: " + bookId);
48};
49
50var 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
66var 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
78router.init();
79
80
81
82
83</script>
84