@@ -12,6 +12,7 @@ var winType = 0,
12
12
max_count = 0 ,
13
13
total_count = 0 ,
14
14
current_page = 1 ,
15
+ threads = 0 ,
15
16
scroll_busy = false ,
16
17
filters = { countryCode : '' , seen : true , active : false } ,
17
18
MAX_PAGE_SIZE = 10 ;
@@ -72,34 +73,18 @@ $(function(){
72
73
$ ( 'header h1' ) . html ( user . user_info . uname + ( winType == 0 ? ' Fans' : ' Followings' ) ) ;
73
74
} ) ;
74
75
75
- setTimeout ( function ( ) { startLoad ( ) ; } , 100 ) ;
76
- setTimeout ( function ( ) { $ ( 'main' ) . show ( ) ; } , 250 ) ;
76
+ setTimeout ( function ( ) { startLoad ( ) ; } , 200 ) ;
77
+
78
+ setImmediate ( function ( ) { $ ( 'main' ) . show ( ) ; } ) ;
77
79
78
80
filters . countryCode = '' ;
79
81
filters . seen = true ;
80
82
81
- setTimeout ( function ( ) {
83
+ setImmediate ( function ( ) {
82
84
$ ( '#countryCode' ) . empty ( ) ;
83
85
for ( i = 0 ; i < cclist . length ; i ++ ) {
84
86
$ ( '#countryCode' ) . append ( `<option value="${ cclist [ i ] [ 1 ] } ">${ cclist [ i ] [ 0 ] } </option>` )
85
87
}
86
- } , 5 ) ;
87
-
88
- $ ( 'main' ) . scroll ( function ( ) {
89
- if ( ( $ ( this ) . scrollTop ( ) + $ ( this ) . height ( ) ) > ( $ ( 'table' ) . height ( ) - 128 ) ) {
90
-
91
- if ( has_more == false ) return ;
92
- if ( scroll_busy == true ) return ;
93
-
94
- scroll_busy = true ;
95
- current_page ++ ;
96
-
97
- if ( winType == 1 ) {
98
- doFollowings ( ) ;
99
- } else {
100
- doFans ( ) ;
101
- }
102
- }
103
88
} ) ;
104
89
105
90
} ) ;
@@ -108,8 +93,35 @@ function startLoad() {
108
93
109
94
$ ( 'table.fflist tbody' ) . html ( '' ) ;
110
95
96
+ scroll_busy = true ;
111
97
current_page = 1 ;
112
98
total_count = 0 ;
99
+ threads = 0 ;
100
+
101
+ switch ( winType ) {
102
+ case 1 : // Followers/Fans
103
+ doFollowings ( ) ;
104
+ break ;
105
+
106
+ case 0 : // Followings
107
+ doFans ( ) ;
108
+ break ;
109
+
110
+ }
111
+ }
112
+
113
+ function loadMore ( ) {
114
+
115
+ if ( threads > 0 ) {
116
+ setTimeout ( function ( ) {
117
+ loadMore ( ) ;
118
+ } , 100 ) ;
119
+ return ;
120
+ }
121
+
122
+ scroll_busy = true ;
123
+ threads = 0 ;
124
+ current_page ++ ;
113
125
114
126
switch ( winType ) {
115
127
case 1 : // Followers/Fans
@@ -155,38 +167,37 @@ function doFollowings() {
155
167
156
168
for ( var i = 0 ; i < results . length ; i ++ ) {
157
169
if ( ( filters . seen == true ) && ( filters . countryCode . length < 2 ) ) {
170
+ threads ++ ;
158
171
addEntry ( results [ i ] ) ;
159
172
} if ( ( filters . countryCode . length > 1 ) && ( results [ i ] . countryCode == filters . countryCode ) ) {
160
173
if ( filters . seen == true ) {
174
+ threads ++ ;
161
175
addEntry ( results [ i ] ) ;
162
176
} else if ( ( filters . seen == false ) && ( DataManager . wasProfileViewed ( results [ i ] . uid ) != false ) ) {
177
+ threads ++ ;
163
178
addEntry ( results [ i ] ) ;
164
179
}
165
180
} else if ( filters . countryCode . length < 2 ) {
166
181
if ( ( filters . seen == false ) && ( DataManager . wasProfileViewed ( results [ i ] . uid ) == false ) ) {
182
+ threads ++ ;
167
183
addEntry ( results [ i ] ) ;
168
184
}
169
185
}
170
186
}
171
187
172
- setTimeout ( function ( ) { scroll_busy = false ; } , 250 ) ;
173
-
174
188
has_more = results . length >= MAX_PAGE_SIZE ;
175
189
176
190
var c = $ ( 'table.fflist tbody tr' ) . length ;
177
191
if ( filters . seen == false || filters . countryCode . length > 1 ) {
178
- $ ( 'footer h1' ) . html ( `Showing ${ c } filtered from ${ total_count } of ${ max_count } accounts, scroll to load more .` ) ;
192
+ $ ( 'footer h1' ) . html ( `Showing ${ c } filtered from ${ total_count } of ${ max_count } accounts.` ) ;
179
193
} else {
180
- $ ( 'footer h1' ) . html ( `Showing ${ total_count } of ${ max_count } accounts, scroll to load more .` ) ;
194
+ $ ( 'footer h1' ) . html ( `Showing ${ total_count } of ${ max_count } accounts.` ) ;
181
195
}
182
196
183
- // $('footer h1').html($('table.fflist tbody tr').length + ' of ' + max_count + ' accounts loaded' + (filters.seen == false || filters.countryCode.length > 1 ? ' and filtered' : '') + '.');
184
-
185
- if ( has_more && ( $ ( 'table.fflist tbody tr' ) . length < ( MAX_PAGE_SIZE * 3 ) ) ) {
186
- setTimeout ( function ( ) {
187
- current_page ++ ;
188
- doFollowings ( ) ;
189
- } , filters . active ? 150 : 250 )
197
+ if ( has_more && ( $ ( 'table.fflist tbody tr' ) . length < max_count ) ) {
198
+ setTimeout ( function ( ) {
199
+ loadMore ( ) ;
200
+ } , 100 ) ;
190
201
}
191
202
} ) ;
192
203
@@ -204,52 +215,53 @@ function doFans() {
204
215
205
216
for ( var i = 0 ; i < results . length ; i ++ ) {
206
217
if ( ( filters . seen == true ) && ( filters . countryCode . length < 2 ) ) {
218
+ threads ++ ;
207
219
addEntry ( results [ i ] ) ;
208
220
} if ( ( filters . countryCode . length > 1 ) && ( results [ i ] . countryCode == filters . countryCode ) ) {
209
221
if ( filters . seen == true ) {
222
+ threads ++ ;
210
223
addEntry ( results [ i ] ) ;
211
224
} else if ( ( filters . seen == false ) && ( DataManager . wasProfileViewed ( results [ i ] . uid ) != false ) ) {
225
+ threads ++ ;
212
226
addEntry ( results [ i ] ) ;
213
227
}
214
228
} else if ( filters . countryCode . length < 2 ) {
215
229
if ( ( filters . seen == false ) && ( DataManager . wasProfileViewed ( results [ i ] . uid ) == false ) ) {
230
+ threads ++ ;
216
231
addEntry ( results [ i ] ) ;
217
232
}
218
233
}
219
234
}
220
235
221
- setTimeout ( function ( ) { scroll_busy = false ; } , 250 ) ;
222
-
223
236
has_more = results . length >= MAX_PAGE_SIZE ;
237
+
224
238
var c = $ ( 'table.fflist tbody tr' ) . length ;
225
239
if ( filters . seen == false || filters . countryCode . length > 1 ) {
226
- $ ( 'footer h1' ) . html ( `Showing ${ c } filtered from ${ total_count } of ${ max_count } accounts, scroll to load more .` ) ;
240
+ $ ( 'footer h1' ) . html ( `Showing ${ c } filtered from ${ total_count } of ${ max_count } accounts.` ) ;
227
241
} else {
228
- $ ( 'footer h1' ) . html ( `Showing ${ total_count } of ${ max_count } accounts, scroll to load more .` ) ;
242
+ $ ( 'footer h1' ) . html ( `Showing ${ total_count } of ${ max_count } accounts.` ) ;
229
243
}
230
244
231
-
232
- if ( has_more && ( $ ( 'table.fflist tbody tr' ) . length < ( MAX_PAGE_SIZE * 3 ) ) ) {
233
- setTimeout ( function ( ) {
234
- current_page ++ ;
235
- doFans ( ) ;
236
- } , filters . active ? 150 : 250 )
245
+ if ( has_more && ( $ ( 'table.fflist tbody tr' ) . length < max_count ) ) {
246
+ setTimeout ( function ( ) {
247
+ loadMore ( ) ;
248
+ } , 100 ) ;
237
249
}
238
250
} ) ;
239
251
}
240
252
241
253
function addEntry ( entry ) {
242
254
var prettydate = require ( 'pretty-date' ) ;
243
- var sex = entry . sex < 0 ? '' : ( entry . sex == 0 ? 'female' : 'male' ) ,
255
+ var sex = entry . sex < 0 ? '' : ( entry . sex == 0 ? 'is- female' : 'is- male' ) ,
244
256
seenRaw = DataManager . wasProfileViewed ( entry . uid ) ,
245
257
seenDate = seenRaw != false ? prettydate . format ( seenRaw ) : '' ,
246
258
seen = seenRaw != false ? 'bright blue' : 'dim' ,
247
259
bookmarked = DataManager . isBookmarked ( entry ) ? 'star-full bright yellow' : 'star-empty dim' ;
248
260
249
261
$ ( "table.fflist tbody" ) . append ( `
250
- <tr id="entry-${ entry . uid } " class="entry-${ entry . uid } ">
262
+ <tr id="entry-${ entry . uid } " class="entry-${ entry . uid } ${ sex } ">
251
263
<td width="64">
252
- <img src="${ entry . face } " style="height: 64px; width: 64px;" onError="$(this).hide()" align="bottom">
264
+ <img src="${ entry . face } " style="height: 64px; width: 64px;" onError="$(this).hide()" align="bottom" class="avatar" >
253
265
</td>
254
266
<td width="90%">
255
267
<div class="seen" title="Last seen ${ seenDate } "><i class="icon icon-eye ${ seen } "></i></div>
@@ -290,6 +302,7 @@ function addEntry(entry) {
290
302
$ ( '#user-' + user . user_info . uid + '-buttons a.fans' ) . html ( user . count_info . follower_count + ' Fans' ) ;
291
303
$ ( '#user-' + user . user_info . uid + '-buttons a.following' ) . html ( 'Following ' + user . count_info . following_count ) ;
292
304
}
305
+ threads -- ;
293
306
} ) ;
294
307
295
308
/*
0 commit comments