Skip to content

Commit 3c2636d

Browse files
committed
Merge pull request thomasdavis#62 from headwinds/gh-pages
Animating the podiums plus odd duplicate rendering
2 parents 65e371c + e3697f1 commit 3c2636d

File tree

6 files changed

+261
-41
lines changed

6 files changed

+261
-41
lines changed

examples/modular-backbone/css/style.css

+36-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ h1{
5252
}
5353

5454
#page {
55-
55+
width: 960px;
5656
}
5757

5858
#page .main {
@@ -138,6 +138,36 @@ h1{
138138

139139
}
140140

141+
#page #contributors-list .podium {
142+
display: block;
143+
position: relative;
144+
float: left;
145+
height: 100%;
146+
width: 320px;
147+
}
148+
149+
#page #contributors-list .podium .top {
150+
display: block;
151+
position: relative;
152+
float: left;
153+
}
154+
155+
#page #contributors-list .podium .base {
156+
display: block;
157+
position: relative;
158+
float: left;
159+
background-color: rgba(214, 214, 214, 0.38);
160+
width: 100%;
161+
}
162+
163+
#page #contributors-list .podium .base p {
164+
text-align: left;
165+
color: #666;
166+
font-weight: normal;
167+
font-size: 12px;
168+
margin-left: 10px;
169+
}
170+
141171
#page #contributors-list ul.contributors {
142172
list-style: none;
143173
margin: 0px;
@@ -161,7 +191,6 @@ h1{
161191
padding: 0px;
162192
top: 0px;
163193
left: 0px;
164-
border: 1px solid #CCC;
165194
}
166195

167196
#page #contributors-list ul.contributors li div.contributor ul {
@@ -195,16 +224,15 @@ h1{
195224
left: 0px;
196225
width: 100%;
197226
height: 14px;
198-
background-color: #CCC;
199227
text-align: center;
200228
font-size: 10px;
201-
font-weight: bold;
202-
color:#999;
229+
font-weight: normal;
230+
color:#333;
203231
line-height: 14px !important;
204232
}
205233

206234
#page #contributors-list ul.contributors li div.contributor ul li.username p a {
207-
color:#999;
235+
color:#333;
208236
text-decoration: none;
209237
}
210238

@@ -249,12 +277,11 @@ h1{
249277
width:100%;
250278
height: 15%;
251279
top: 85%;
252-
background-color: #333;
253280
text-align: center;
254281
line-height: 14px !important;
255282
font-size: 10px;
256-
font-weight: bold;
257-
color:#666;
283+
font-weight: normal;
284+
color:#333;
258285
margin:0px;
259286
padding:0px;
260287
}

examples/modular-backbone/js/router.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ define([
88
'views/contributors/ContributorsView',
99
'views/footer/FooterView'
1010
], function($, _, Backbone, HomeView, ProjectsView, ContributorsView, FooterView) {
11+
12+
var contributorsView;
13+
1114
var AppRouter = Backbone.Router.extend({
1215
routes: {
1316
// Define some URL routes
@@ -18,7 +21,9 @@ define([
1821
'*actions': 'defaultAction'
1922
}
2023
});
24+
2125
var initialize = function(){
26+
2227
var app_router = new AppRouter;
2328

2429
app_router.on('route:showProjects', function(){
@@ -31,12 +36,15 @@ define([
3136

3237
app_router.on('route:showContributors', function () {
3338

39+
// there is a problem here -- when it draws the first everything is fine
40+
// but when it returns to this view, it adds the items to the list again
41+
// even though the collection has the same number of models
42+
// why won't it empty the divs?! I can do it in the console...
43+
if ( String(contributorsView) !== "undefined" ) contributorsView.clearListView();
44+
3445
// Like above, call render but know that this view has nested sub views which
3546
// handle loading and displaying data from the GitHub API
36-
var contributorsView = new ContributorsView();
37-
//contributorsView.initialize();
38-
//contributorsView.render();
39-
47+
contributorsView = new ContributorsView();
4048
});
4149

4250
app_router.on('route:defaultAction', function (actions) {

examples/modular-backbone/js/views/contributors/ContributorsListView.js

+169-6
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,104 @@ define([
77
], function($, _, Backbone, ContributorsCollection, contributorListTemplate){
88

99
var ContributorsListView = Backbone.View.extend({
10+
11+
goldContributors : [],
12+
silverContributors : [],
13+
bronzeContributors : [],
14+
1015
el : $("#contributors-list"),
1116
tagName:"ul",
12-
render : function() {
17+
18+
initialize : function() {
19+
20+
var that = this;
21+
that.bind("reset", that.clearView);
22+
},
23+
24+
clearListView : function(){
1325

26+
console.log("clearing sub sub view");
27+
28+
$("#gold-podium").empty();
29+
$("#silver-podium").empty();
30+
$("#bronze-podium").empty();
31+
32+
},
33+
34+
render : function() {
35+
36+
// when it returns to this view, why does it redraw without clearing the lists?!
37+
// something to do with how it's animating I think...not sure
1438
var that = this;
39+
40+
that.clearListView();
41+
1542
that.awardMedals(this.collection.models);
1643

44+
// hide the container list while adding contributors
45+
$('#contributors-list').hide();
46+
47+
// there are 3 podiums for each group
48+
var podium;
49+
50+
var goldPodium = {
51+
baseHeight: '80px',
52+
baseWidth: '120px',
53+
achievement: 'Over 50 Contributions'
54+
};
55+
56+
var silverPodium = {
57+
baseHeight: '60px',
58+
baseWidth: '160px',
59+
achievement: '5 - 50 Contributions'
60+
}
61+
62+
var bronzePodium = {
63+
baseHeight: '40px',
64+
baseWidth: '680px',
65+
achievement: '1 - 5 Contributions'
66+
}
67+
68+
1769
var data = {
18-
contributors: this.collection.models,
19-
_: _
70+
contributors: that.goldContributors,
71+
_: _,
72+
podium : goldPodium
2073
};
2174

75+
// render gold list
76+
data.contributors = that.goldContributors;
77+
data.podium = goldPodium;
2278
var compiledTemplate = _.template( contributorListTemplate, data );
23-
$("#contributors-list").html( compiledTemplate );
79+
$("#gold-podium").html( compiledTemplate );
2480

81+
// render silver list
82+
data.contributors = that.silverContributors;
83+
data.podium = silverPodium;
84+
var compiledTemplate = _.template( contributorListTemplate, data );
85+
$("#silver-podium").html( compiledTemplate );
86+
87+
// render bronze list
88+
data.contributors = that.bronzeContributors;
89+
data.podium = bronzePodium;
90+
var compiledTemplate = _.template( contributorListTemplate, data );
91+
$("#bronze-podium").html( compiledTemplate );
92+
93+
that.animate();
94+
2595
return this;
2696
},
2797

2898
awardMedals : function(aModels) {
99+
100+
var that = this;
101+
29102
var goldMedalHex = '#CFB52B';
30103
var silverMedalHex = '#E6E8FA';
31104
var bronzeMedalHex = '#A67D3D';
32105
var githubPath;
106+
var contributors;
107+
var count = 0;
33108

34109
_.each(aModels, function(contributor) {
35110

@@ -39,22 +114,110 @@ define([
39114

40115
if ( contributions >= 50 ) {
41116
medalHex = goldMedalHex;
42-
picWidth = '160px';
117+
picWidth = '120px';
118+
contributors = that.goldContributors;
43119
} else if ( contributions < 50 && contributions >= 5) {
44120
medalHex = silverMedalHex;
45-
picWidth = '120px';
121+
picWidth = '100px';
122+
contributors = that.silverContributors;
46123
} else {
47124
medalHex = bronzeMedalHex;
48125
picWidth = '80px';
126+
contributors = that.bronzeContributors;
49127
}
50128

51129
githubPath = "https://github.com/" + contributor.get('login');
52130

53131
contributor.set( 'medalHex', medalHex);
54132
contributor.set( 'picWidth', picWidth);
55133
contributor.set( 'githubPath', githubPath);
134+
contributor.set( 'name', 'contributor' + count );
135+
contributors.push(contributor);
136+
137+
count++;
138+
139+
});
140+
},
56141

142+
animate : function() {
143+
144+
var that = this;
145+
146+
console.log("animating...");
147+
148+
$("#gold-podium").hide();
149+
$("#silver-podium").hide();
150+
$("#bronze-podium").hide();
151+
152+
153+
// hide the container list while adding contributors
154+
$('#contributors-list').show();
155+
156+
// animate in bronze
157+
$("#bronze-podium").find(".base").hide();
158+
$("#bronze-podium").find(".base").slideDown('slow').delay(0);
159+
160+
_.each(that.bronzeContributors, function(contributor) {
161+
var hideId = '#' + contributor.get('name');
162+
163+
$( hideId ).hide();
164+
165+
});
166+
167+
var bronzeDelayCount = 1000;
168+
var bronzeDelayInc = 200;
169+
_.each(that.bronzeContributors, function(contributor) {
170+
var animateId = '#' + contributor.get('name');
171+
172+
$( animateId ).delay(bronzeDelayCount).slideDown('slow');
173+
bronzeDelayCount += bronzeDelayInc;
174+
});
175+
176+
177+
console.log(bronzeDelayCount);
178+
179+
// animate in silver
180+
$("#silver-podium").find(".base").hide();
181+
$("#silver-podium").find(".base").slideDown('slow').delay(bronzeDelayCount);
182+
_.each(that.silverContributors, function(contributor) {
183+
var hideId = '#' + contributor.get('name');
184+
185+
$( hideId ).hide();
186+
57187
});
188+
189+
var silverDelayCount = bronzeDelayCount;
190+
var silverDelayInc = 400;
191+
_.each(that.silverContributors, function(contributor) {
192+
var animateId = '#' + contributor.get('name');
193+
194+
$( animateId ).delay(silverDelayCount).slideDown('slow');
195+
silverDelayCount += silverDelayInc;
196+
});
197+
198+
// animate in gold
199+
$("#gold-podium").find(".base").hide();
200+
$("#gold-podium").find(".base").slideDown('slow').delay(silverDelayCount);
201+
_.each(that.goldContributors, function(contributor) {
202+
var hideId = '#' + contributor.get('name');
203+
204+
$( hideId ).hide();
205+
206+
});
207+
208+
var goldDelayCount = silverDelayCount;
209+
var goldDelayInc = 600;
210+
_.each(that.goldContributors, function(contributor) {
211+
var animateId = '#' + contributor.get('name');
212+
213+
$( animateId ).delay(goldDelayCount).slideDown('slow');
214+
goldDelayCount += goldDelayInc;
215+
});
216+
217+
$("#bronze-podium").show();
218+
$("#silver-podium").show();
219+
$("#gold-podium").show();
220+
58221
}
59222

60223
});

examples/modular-backbone/js/views/contributors/ContributorsView.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ define([
77
'text!templates/contributors/contributorsTemplate.html'
88
], function($, _, Backbone, ContributorsCollection, ContributorsListView, contributorsTemplate){
99

10+
var contributorsListView;
11+
1012
var ContributorsView = Backbone.View.extend({
1113

1214
el: $("#page"),
@@ -21,7 +23,7 @@ define([
2123

2224
this.collection = new ContributorsCollection([]);
2325
this.collection.fetch({ success : onDataHandler, dataType: "jsonp" });
24-
26+
2527
},
2628

2729
render: function(){
@@ -39,7 +41,7 @@ define([
3941
this.$el.html( compiledTemplate );
4042

4143
// sub view
42-
var contributorsListView = new ContributorsListView({ collection: this.collection});
44+
contributorsListView = new ContributorsListView({ collection: this.collection});
4345
contributorsListView.render();
4446

4547
},
@@ -54,9 +56,15 @@ define([
5456
});
5557

5658
return total;
59+
},
60+
61+
clearListView: function() {
62+
console.log("clearing sub view");
63+
contributorsListView.clearListView();
5764
}
5865

5966

67+
6068
});
6169
return ContributorsView;
6270
});

0 commit comments

Comments
 (0)