-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_compositeview.html
144 lines (127 loc) · 3.17 KB
/
no_compositeview.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
<html>
<head>
<meta charset="UTF-8">
<title>Marionette.CompoundView</title>
<link rel="stylesheet" type="text/css" href="assets/scripts/bower/bootstrap/dist/css/bootstrap.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Marionette.CompoundView</h1>
</div>
</div>
<div id="compound-view-container">
</div>
</div>
<script type="text/handlebars" id="compound-view">
<div class="row">
<div class="col-sm-4 list-view-container">
</div>
<div class="col-sm-8 single-element-container">
</div>
</div>
</script>
<script type="text/handlebars" id="list-item-view">
<%= name %>
</script>
<script type="text/handlebars" id="item-view">
<div class="panel-heading"><%= name %></div>
<div class="panel-body">
Population: <%= showNumber(population) %>
Land Area: <%= showNumber(landArea) %>
</div>
</script>
<script src="assets/scripts/bower/jquery/dist/jquery.js"></script>
<script src="assets/scripts/bower/underscore/underscore.js"></script>
<script src="assets/scripts/bower/backbone/backbone.js"></script>
<script src="assets/scripts/bower/backbone.marionette/lib/backbone.marionette.js"></script>
<script src="build/CompoundView.js"></script>
<script>
var showNumber = function(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + "'" + '$2');
}
return x1 + x2;
};
MyApp = new Backbone.Marionette.Application();
MyApp.addRegions(
{
compoundViewContainer: "#compound-view-container"
}
);
var ListItemView = Backbone.Marionette.ItemView.extend(
{
tagName: 'li',
className: 'list-group-item',
template: '#list-item-view',
initialize: function()
{
this.listenTo(this, 'list-element:selected', this.selected);
this.listenTo(this, 'list-element:unselected', this.unselected);
},
selected: function()
{
this.$el.addClass('selected');
},
unselected: function()
{
this.$el.removeClass('selected');
}
}
);
var ItemView = Backbone.Marionette.ItemView.extend(
{
template: '#item-view',
className: 'panel panel-default'
}
);
var Model = Backbone.Model.extend();
var Collection = Backbone.Collection.extend(
{
model: Model,
comparator: function(model)
{
return model.get('name');
}
}
);
var collection = new Collection(
[
{name: 'Australia', population: 22.68e6, landArea: 7.618e6},
{name: 'Switzerland', population: 7.997e6, landArea: 39997},
{name: 'Italy', population: 60.92e6, landArea: 294140},
{name: 'Argentina', population: 41.09e6, landArea: 2.737e6},
{name: 'South Korea', population: 48.8e6, landArea: 98190}
]
);
var cV = new Marionette.CompoundView(
{
itemView: ItemView,
listItemView: ListItemView,
collection: collection,
template: '#compound-view',
breakWidth: 750
}
);
console.log(cV);
$(document).ready(function()
{
MyApp.compoundViewContainer.show(cV);
}
);
</script>
<style>
.selected
{
background-color: #F5F5F5;
}
</style>
</body>
</html>