@@ -7,29 +7,104 @@ define([
7
7
] , function ( $ , _ , Backbone , ContributorsCollection , contributorListTemplate ) {
8
8
9
9
var ContributorsListView = Backbone . View . extend ( {
10
+
11
+ goldContributors : [ ] ,
12
+ silverContributors : [ ] ,
13
+ bronzeContributors : [ ] ,
14
+
10
15
el : $ ( "#contributors-list" ) ,
11
16
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 ( ) {
13
25
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
14
38
var that = this ;
39
+
40
+ that . clearListView ( ) ;
41
+
15
42
that . awardMedals ( this . collection . models ) ;
16
43
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
+
17
69
var data = {
18
- contributors : this . collection . models ,
19
- _ : _
70
+ contributors : that . goldContributors ,
71
+ _ : _ ,
72
+ podium : goldPodium
20
73
} ;
21
74
75
+ // render gold list
76
+ data . contributors = that . goldContributors ;
77
+ data . podium = goldPodium ;
22
78
var compiledTemplate = _ . template ( contributorListTemplate , data ) ;
23
- $ ( "#contributors-list " ) . html ( compiledTemplate ) ;
79
+ $ ( "#gold-podium " ) . html ( compiledTemplate ) ;
24
80
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
+
25
95
return this ;
26
96
} ,
27
97
28
98
awardMedals : function ( aModels ) {
99
+
100
+ var that = this ;
101
+
29
102
var goldMedalHex = '#CFB52B' ;
30
103
var silverMedalHex = '#E6E8FA' ;
31
104
var bronzeMedalHex = '#A67D3D' ;
32
105
var githubPath ;
106
+ var contributors ;
107
+ var count = 0 ;
33
108
34
109
_ . each ( aModels , function ( contributor ) {
35
110
@@ -39,22 +114,110 @@ define([
39
114
40
115
if ( contributions >= 50 ) {
41
116
medalHex = goldMedalHex ;
42
- picWidth = '160px' ;
117
+ picWidth = '120px' ;
118
+ contributors = that . goldContributors ;
43
119
} else if ( contributions < 50 && contributions >= 5 ) {
44
120
medalHex = silverMedalHex ;
45
- picWidth = '120px' ;
121
+ picWidth = '100px' ;
122
+ contributors = that . silverContributors ;
46
123
} else {
47
124
medalHex = bronzeMedalHex ;
48
125
picWidth = '80px' ;
126
+ contributors = that . bronzeContributors ;
49
127
}
50
128
51
129
githubPath = "https://github.com/" + contributor . get ( 'login' ) ;
52
130
53
131
contributor . set ( 'medalHex' , medalHex ) ;
54
132
contributor . set ( 'picWidth' , picWidth ) ;
55
133
contributor . set ( 'githubPath' , githubPath ) ;
134
+ contributor . set ( 'name' , 'contributor' + count ) ;
135
+ contributors . push ( contributor ) ;
136
+
137
+ count ++ ;
138
+
139
+ } ) ;
140
+ } ,
56
141
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
+
57
187
} ) ;
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
+
58
221
}
59
222
60
223
} ) ;
0 commit comments