|
148 | 148 | });
|
149 | 149 | }
|
150 | 150 |
|
151 |
| - function getEpisode(comicId, episode, dir, total, callback) { |
152 |
| - if (dir && total) { |
| 151 | + function getEpisode(comicId, episode, dir, pageCount, total, callback) { |
| 152 | + if (dir && total && 1 == total) { |
153 | 153 | var picList = [];
|
154 |
| - for (var i = 1; i <= total; i++) { |
| 154 | + for (var i = 1; i <= pageCount; i++) { |
155 | 155 | picList.push({
|
156 | 156 | url: picUrlPrefix + dir + '/' + episode + '/' + i + '.jpg',
|
157 | 157 | alt_url: i < 10 ? picUrlPrefix + dir + '/' + episode + '/0' + i + '.jpg' : null
|
|
240 | 240 | console.log(e);
|
241 | 241 | });
|
242 | 242 |
|
| 243 | + // NOTE: load next/prev page |
| 244 | + // TOOD: handle touch event |
| 245 | + var $window = $(window), |
| 246 | + $document = $(document), |
| 247 | + $prevPageLoader = $('#prev-page-loader'), |
| 248 | + $nextPageLoader = $('#next-page-loader'); |
| 249 | + $window.scroll(function() { |
| 250 | + var hash = location.hash.split('!'), |
| 251 | + fragParamString = hash[1], |
| 252 | + windowScrollTop, |
| 253 | + matches, |
| 254 | + fragParams, |
| 255 | + currnetPage; |
| 256 | + hash = hash[0]; |
| 257 | + matches = hash.match(/^(.*?\/)(\d+)$/); |
| 258 | + if (!matches) { |
| 259 | + return; |
| 260 | + } |
| 261 | + windowScrollTop = $window.scrollTop(); |
| 262 | + if (windowScrollTop + $window.height() == $document.height()) { |
| 263 | + if ($nextPageLoader.is(':visible')) { |
| 264 | + fragParams = getFragParams(); |
| 265 | + currnetPage = parseInt(matches[2], 10); |
| 266 | + if (fragParams.total == currnetPage) { |
| 267 | + return; |
| 268 | + } |
| 269 | + location.hash = matches[1] + (currnetPage + 1) + '!' + (fragParamString ? fragParamString : ''); |
| 270 | + $nextPageLoader.hide(); |
| 271 | + $('html, body').animate({scrollTop: '1px'}, 500, 'swing'); |
| 272 | + } else { |
| 273 | + $nextPageLoader.show(); |
| 274 | + } |
| 275 | + } |
| 276 | + if (0 == windowScrollTop) { |
| 277 | + if ($prevPageLoader.is(':visible')) { |
| 278 | + currnetPage = parseInt(matches[2], 10); |
| 279 | + if (currnetPage == 1) { |
| 280 | + return; |
| 281 | + } |
| 282 | + location.hash = matches[1] + (currnetPage - 1) + '!' + (fragParamString ? fragParamString : ''); |
| 283 | + $prevPageLoader.hide(); |
| 284 | + } else { |
| 285 | + $prevPageLoader.show(); |
| 286 | + $window.scrollTop(1); |
| 287 | + } |
| 288 | + |
| 289 | + } |
| 290 | + }); |
| 291 | + |
243 | 292 | /* routes */
|
244 | 293 | // index
|
245 | 294 | $.routes.add('/$', 'index', function() {
|
|
277 | 326 | $.routes.add('/comic/{id:int}/ep/{ep:int}', 'comicPicList', function() {
|
278 | 327 | console.log(this);
|
279 | 328 | var fragParams = getFragParams();
|
280 |
| - getEpisode(this.id, this.ep, fragParams.dir, fragParams.total, function(data) { |
| 329 | + getEpisode(this.id, this.ep, fragParams.dir, fragParams.pageCount, fragParams.total, function(data) { |
281 | 330 | renderContent(data, 'pic-list');
|
282 | 331 | // NOTE: hotfix for uncertain leading-zero
|
283 | 332 | $('img').on('error', function(e) {
|
284 |
| - var ele = $(e.target); |
285 |
| - ele.prop('src', ele.data('url')); |
| 333 | + var ele = $(e.target), |
| 334 | + altUrl = ele.data('url'), |
| 335 | + currentUrl = ele.prop('src'); |
| 336 | + if (altUrl && altUrl != currentUrl) { |
| 337 | + ele.prop('src', altUrl); |
| 338 | + } |
286 | 339 | });
|
287 | 340 | });
|
288 | 341 | });
|
|
0 commit comments