-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (67 loc) · 1.5 KB
/
app.js
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
var Model = Backbone.Model.extend({
defaults: {
state: "start"
}
});
var model = new Model();
var Steps = Backbone.View.extend({
el: '#steps',
model: model,
initialize: function(){
this.model.bind('change', this.render, this);
},
templates: {
'start':_.template($('#start').html()),
'step-two':_.template($('#step-two').html()),
'step-three':_.template($('#step-three').html())
},
events: {
'click .step-one button' : "check",
'keypress' : "checkKey"
},
checkKey: function(e){
if(e.keyCode == 13) {
this.check();
}
},
check: function(){
if($(this.el).find(".step-one input").val()){
this.model.set('state', 'step-two');
} else {
this.model.set('state', 'step-three');
}
},
render: function () {
var state = this.model.get('state');
$(this.el).html(this.templates[state](this.model.toJSON()));
return this;
}
});
var steps = new Steps();
model.trigger('change');
model.bind('change:state', function(){
var state = this.get('state');
if(state == 'start')
controller.navigate('');
else
controller.navigate('!/' + state);
});
var Controller = Backbone.Router.extend({
routes: {
"" : "start",
"!/step-one" : "start",
"!/step-two" : "stepTwo",
"!/step-three" : "stepThree",
},
start: function(){
model.set({ state: "start" });
},
stepTwo: function(){
model.set({ state: "step-two" });
},
stepThree: function(){
model.set({ state: "step-three" });
}
});
var controller = new Controller();
Backbone.history.start();