-
Notifications
You must be signed in to change notification settings - Fork 1
/
backbone.scene.js
109 lines (86 loc) · 2.16 KB
/
backbone.scene.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*!
* backbone.scene.js v0.1
* Copyright 2012, Jason Kadrmas (@itooamaneatguy)
*/
(function(Backbone, _) {
Backbone.Scene = Backbone.View.extend({});
_.extend(Backbone.Scene.prototype, {
children: {},
transition: null,
// Can be overridden by extended class.
initialize: function() {},
// Can be overridden by extended class.
show: function() {
this.el.show();
return this;
},
// Can be overridden by extended class.
hide: function() {
this.el.hide();
return this;
},
/*
Renders an underscore template and appends it to a container.
@method : renderTemplate
@param : template : underscore template
@param : data : the data to combine with the template
@param : container : container to append generated template to
*/
renderTemplate: function(template, data, container) {
this.el = $(this.el).html( this.compileTemplate( template, data ) );
container.append( this.el );
},
/*
Compiles an underscore template and returns the generated html.
@method : compileTemplate
@param : template : underscore template
@param : data : the data to combine with the template
*/
compileTemplate: function(template, data) {
var compiledTemplate = _.template( template, data );
return compiledTemplate;
},
/*
Adds a view to our scene object.
@method : addView
@param : key : unique key for the added view
@param : child : actual view to add
*/
addView: function(key, child) {
this.children[key] = child;
},
/*
Removes a view from our scene object.
@method : removeView
@param : key : unique key for the view to remove
*/
removeView: function(key) {
this.children[key].remove();
delete this.children[key];
},
/*
Removes all views from scene
@method : removeAll
*/
removeAll: function() {
children = null;
},
/*
Gets a view based on the key
@method : get
@param : key : unique key for the view to retrieve
*/
get: function(key) {
return this.children[key];
},
/*
Destroys a scene
@method : destroy
*/
destroy: function() {
this.remove();
this.unbind();
this.removeAll();
}
});
})(this.Backbone, this._);