-
Notifications
You must be signed in to change notification settings - Fork 10
/
route-transitions-jsx.html
146 lines (118 loc) · 3.36 KB
/
route-transitions-jsx.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="jquery-2.0.3/build/jquery.js"></script>
<script type="text/javascript" src="underscore-1.5.2/build/underscore.js"></script>
<script type="text/javascript" src="backbone-1.1.0/build/backbone.js"></script>
<script type="text/javascript" src="react-0.8.0/build/react-with-addons.js"></script>
<script type="text/javascript" src="react-0.8.0/build/JSXTransformer.js"></script>
<style type="text/css">
.animate-enter {
opacity : 0.01;
transition : opacity .5s ease-in;
}
.animate-enter.animate-enter-active {
opacity : 1;
}
.animate-leave {
opacity : 1;
transition : opacity .5s ease-in;
}
.animate-leave.animate-leave-active {
opacity : 0.01;
}
a {
cursor : pointer;
color : blue;
}
</style>
</head>
<body>
<script type="text/jsx">
/**
* @jsx React.DOM
*/
var RouterMixin = {
componentWillMount : function() {
this.callback = (function() {
this.forceUpdate();
}).bind(this);
this.props.router.on("route", this.callback);
},
componentWillUnmount : function() {
this.props.router.off("route", this.callback);
}
};
var FooComponent = React.createClass({
mixins : [RouterMixin],
handle : function() {
this.props.router.navigate("bar", {
trigger : true
});
},
render : function() {
var className = "animate-leave animate-leave-active";
if (this.props.router.current == "foo") {
className = "animate-enter animate-enter-active";
}
return (
<div className={className}>
in foo,
<a onClick={this.handle}>go to bar</a>
</div>
);
}
});
var BarComponent = React.createClass({
mixins : [RouterMixin],
handle : function() {
this.props.router.navigate("foo", {
trigger : true
});
},
render : function() {
var className = "animate-leave animate-leave-active";
if (this.props.router.current == "bar") {
className = "animate-enter animate-enter-active";
}
return (
<div className={className}>
in bar,
<a onClick={this.handle}>go to foo</a>
</div>
);
}
});
var InterfaceComponent = React.createClass({
mixins : [RouterMixin],
render : function() {
var router = this.props.router;
return (
<div>
<FooComponent router={router} />
<BarComponent router={router} />
</div>
);
}
});
var Router = Backbone.Router.extend({
routes : {
"foo" : "foo",
"bar" : "bar"
},
foo : function() {
this.current = "foo";
},
bar : function() {
this.current = "bar";
}
});
var router = new Router();
React.renderComponent(
<InterfaceComponent router={router} />,
document.body
);
Backbone.history.start();
</script>
</body>
</html>