-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexampleBackbone.html
More file actions
260 lines (246 loc) · 7.18 KB
/
exampleBackbone.html
File metadata and controls
260 lines (246 loc) · 7.18 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<html>
<head>
<meta charset='utf-8'>
<link href='http://fonts.googleapis.com/css?family=Crete+Round' rel='stylesheet' type='text/css'>
<style>
body {
background: #333;
color: #eee;
padding: 5%;
font-family: 'Crete Round', serif;
}
h1 {
color: #C80;
text-shadow: 2px 2px 2px #000000;
}
.half {
width: 40%;
float: left;
}
a {
color: #DFA;
}
.view {
background-color: #EEA;
width: 20%;
margin:3%;
padding:2%;
color: #333;
border-radius: 10px;
float: left;
}
.view a {
color: #033;
}
section {
width: 100%;
display: inline-block;
}
</style>
</head>
<body>
<h1>
SeedJs - Backbone Integration
</h1>
<h3>
Each one of the backbone views defined after the yellow containers points to one of them. Use your javascript console to create new classes and test SeedJs!
</h3>
<section>
Some <a href="readme.html">info</a>
</section>
<section>
<div class="view container">Hello world</div>
<div class="view containerClio">Hello world</div>
<div class="view containerYamaha">Hello world</div>
</section>
<section>
<div class="half">
<pre>
var Vehicle = SeedModel.extend({engine:{cylinders:0, pistons:0},
wheels:0,
puertas:0,
speed: 0,
name: 'Vehicle',
sound: "rrrrrrrr",
run: function() {
this.trigger('run');
},
accelerate: function() {
this.speed += 10;
console.log('new speed:' + this.speed);
},
brake: function() {
this.speed -= 10;
}
});
var Coche = Vehicle.extend({wheels: 4,
puertas:4,
sound: "brrum brrrum"
});
var Motorbike = Vehicle.extend({wheels: 2});
var Clio = Coche.extend({
name: "little car",
engine:{cylinders:8, pistons:16},
accelerate: function() {
this.parent('accelerate');
if(this.speed > 50) {
this.speed = 0;
alert('CRASH');
}
},
run: function() {
this.accelerate();
this.parent('run');
}
});
</pre>
</div>
<div class="half">
<pre>
var Yamaha = Motorbike.extend({
name: "Yamaha",
engine:{cylinders:4, pistons:10},
run: function() {
this.accelerate();
this.accelerate();
this.parent('run');
}
});
var VehicleView = SeedView.extend({
model: Vehicle,
events: {
'click a':'run'
},
initialize: function() {
this.run = _.bind(this.run,this);
this.render = _.bind(this.render, this);
this.model.bind('run', this.render);
},
render: function() {
$(this.el).html("The " + this.model.name + ' goes at ' + this.model.speed);
$(this.el).append("<br/><a href='#'>Run run run!</a>");
},
run: function(e) {
e.preventDefault();
this.model.run();
}
})
var MotorbikeView = VehicleView.extend({
render: function() {
this.parent('render');
$(this.el).append(" <- click this to brrrrrrrroum");
}
})
</pre>
</div>
</section>
<section>
<div class="half">
Get it at <a href="https://github.com/johnHackworth/SeedJs">https://github.com/johnHackworth/SeedJs</a>
</div>
<div class="half">
Check the <a href="index.html">plain inheritance system example</a>
</div>
</section>
<script src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="src/seed.js"></script>
<script src="src/backboneAdapter.js"></script>
<script>
window.Vehicle = SeedModel.extend({engine:{cylinders:0, pistons:0},
wheels:0,
puertas:0,
speed: 0,
name: 'Vehicle',
sound: "rrrrrrrr",
run: function() {
this.trigger('run');
},
accelerate: function() {
this.speed += 10;
console.log('new speed:' + this.speed);
},
brake: function() {
this.speed -= 10;
}
});
window.Coche = Vehicle.extend({wheels: 4,
puertas:4,
sound: "brrum brrrum"
});
window.Motorbike = Vehicle.extend({wheels: 2});
window.Clio = Coche.extend({
name: "little car",
engine:{cylinders:8, pistons:16},
accelerate: function() {
this.parent('accelerate');
if(this.speed > 50) {
this.speed = 0;
alert('CRASH');
}
},
run: function() {
this.accelerate();
this.parent('run');
}
});
window.Yamaha = Motorbike.extend({
name: "Yamaha",
engine: {cylinders:4, pistons:10},
run: function() {
this.accelerate();
this.accelerate();
this.parent('run');
}
});
window.VehicleView = SeedView.extend({
model: Vehicle,
events: {
'click a':'run'
},
initialize: function() {
this.run = _.bind(this.run,this);
this.render = _.bind(this.render, this);
this.model.bind('run', this.render);
},
render: function() {
$(this.el).html("The " + this.model.name + ' has ' +
this.model.engine.cylinders + ' cylinders and ' + this.model.engine.pistons +
'pistons, and currently is running at ' + this.model.speed + ' km/h');
$(this.el).append("<br/><a href='#'>Run run run!</a>");
},
run: function(e) {
e.preventDefault();
this.model.run();
}
})
window.MotorbikeView = VehicleView.extend({
render: function() {
this.parent('render');
$(this.el).append(" <- click this to brrrrrrrroum");
}
})
$(document).ready(function() {
window.v = new Vehicle();
window.vView = new VehicleView({
el: $('.container'),
model: v
});
vView.render();
window.c = new Clio();
window.cView = new VehicleView({
el: $('.containerClio'),
model: c
});
cView.render();
window.y = new Yamaha();
window.yView = new MotorbikeView({
el: $('.containerYamaha '),
model: y
});
yView.render();
})
</script>
</body>
</html>