-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
82 lines (77 loc) · 2.4 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>backbone.router.fsm</title>
</head>
<body>
<div id="wrapper">
<div id="container">
<div id="content">
<h1>Backbone Router FSM</h1>
<div class="console">state: <span id="state"></span></div>
<button data-state="st1">st1</button>
<button data-state="st2">st2</button>
<button data-state="st3">st3</button>
<div id="result"></div>
</div>
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="./backbone.router.fsm.js"></script>
<script>
$(function() {
var $state = $('#state'),
$btn = $('button'),
$result = $('#result'),
default_state = 'st1';
$state.html('st1');
$btn.click(function(e) {
var $trg = $(e.target),
st = $trg.data('state');
$state.html(st);
location.hash = st;
});
var MyRouter = Backbone.FSMRouter.extend({
default_state: 'st1',
routes: {
st1: "st1",
st2: "st2",
st3: "st3"
},
st1_st2: function() {
$result.html('st1_to_st2');
},
st2_st3: function() {
$result.html('st2_to_st3');
},
st3_st1: function() {
$result.html('st3_to_st1');
},
st1_st1: function() {
$result.html('st1_to_st1');
},
st2_st2: function() {
$result.html('st2_to_st2');
},
st3_st3: function() {
$result.html('st3_to_st3');
},
st1_st3: function() {
$result.html('st1_to_st3');
},
st2_st1: function() {
$result.html('st2_to_st1');
},
st3_st2: function() {
$result.html('st3_to_st2');
}
});
router = new MyRouter();
Backbone.history.start();
});
</script>
</body>
</html>