|
1 | 1 | /*! |
2 | | - * Infinite Scroll PACKAGED v3.0.3 |
| 2 | + * Infinite Scroll PACKAGED v3.0.4 |
3 | 3 | * Automatically add next page |
4 | 4 | * |
5 | 5 | * Licensed GPLv3 for open source use |
@@ -321,7 +321,7 @@ return EvEmitter; |
321 | 321 | })); |
322 | 322 |
|
323 | 323 | /** |
324 | | - * Fizzy UI utils v2.0.5 |
| 324 | + * Fizzy UI utils v2.0.7 |
325 | 325 | * MIT license |
326 | 326 | */ |
327 | 327 |
|
@@ -376,23 +376,27 @@ utils.modulo = function( num, div ) { |
376 | 376 |
|
377 | 377 | // ----- makeArray ----- // |
378 | 378 |
|
| 379 | +var arraySlice = Array.prototype.slice; |
| 380 | + |
379 | 381 | // turn element or nodeList into an array |
380 | 382 | utils.makeArray = function( obj ) { |
381 | | - var ary = []; |
382 | 383 | if ( Array.isArray( obj ) ) { |
383 | 384 | // use object if already an array |
384 | | - ary = obj; |
385 | | - } else if ( obj && typeof obj == 'object' && |
386 | | - typeof obj.length == 'number' ) { |
| 385 | + return obj; |
| 386 | + } |
| 387 | + // return empty array if undefined or null. #6 |
| 388 | + if ( obj === null || obj === undefined ) { |
| 389 | + return []; |
| 390 | + } |
| 391 | + |
| 392 | + var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number'; |
| 393 | + if ( isArrayLike ) { |
387 | 394 | // convert nodeList to array |
388 | | - for ( var i=0; i < obj.length; i++ ) { |
389 | | - ary.push( obj[i] ); |
390 | | - } |
391 | | - } else { |
392 | | - // array of single index |
393 | | - ary.push( obj ); |
| 395 | + return arraySlice.call( obj ); |
394 | 396 | } |
395 | | - return ary; |
| 397 | + |
| 398 | + // array of single index |
| 399 | + return [ obj ]; |
396 | 400 | }; |
397 | 401 |
|
398 | 402 | // ----- removeFrom ----- // |
@@ -471,22 +475,21 @@ utils.filterFindElements = function( elems, selector ) { |
471 | 475 | // ----- debounceMethod ----- // |
472 | 476 |
|
473 | 477 | utils.debounceMethod = function( _class, methodName, threshold ) { |
| 478 | + threshold = threshold || 100; |
474 | 479 | // original method |
475 | 480 | var method = _class.prototype[ methodName ]; |
476 | 481 | var timeoutName = methodName + 'Timeout'; |
477 | 482 |
|
478 | 483 | _class.prototype[ methodName ] = function() { |
479 | 484 | var timeout = this[ timeoutName ]; |
480 | | - if ( timeout ) { |
481 | | - clearTimeout( timeout ); |
482 | | - } |
483 | | - var args = arguments; |
| 485 | + clearTimeout( timeout ); |
484 | 486 |
|
| 487 | + var args = arguments; |
485 | 488 | var _this = this; |
486 | 489 | this[ timeoutName ] = setTimeout( function() { |
487 | 490 | method.apply( _this, args ); |
488 | 491 | delete _this[ timeoutName ]; |
489 | | - }, threshold || 100 ); |
| 492 | + }, threshold ); |
490 | 493 | }; |
491 | 494 | }; |
492 | 495 |
|
@@ -650,8 +653,9 @@ proto.create = function() { |
650 | 653 | this.pageIndex = 1; // default to first page |
651 | 654 | this.loadCount = 0; |
652 | 655 | this.updateGetPath(); |
653 | | - // bail if getPath not set |
654 | | - if ( !this.getPath ) { |
| 656 | + // bail if getPath not set, or returns falsey #776 |
| 657 | + var hasPath = this.getPath && this.getPath(); |
| 658 | + if ( !hasPath ) { |
655 | 659 | console.error('Disabling InfiniteScroll'); |
656 | 660 | return; |
657 | 661 | } |
@@ -798,7 +802,7 @@ proto.updateGetPathTemplate = function( optPath ) { |
798 | 802 | var match = location.href.match( templateRe ); |
799 | 803 | if ( match ) { |
800 | 804 | this.pageIndex = parseInt( match[1], 10 ); |
801 | | - this.log( 'pageIndex', this.pageIndex, 'template string' ); |
| 805 | + this.log( 'pageIndex', [ this.pageIndex, 'template string' ] ); |
802 | 806 | } |
803 | 807 | }; |
804 | 808 |
|
@@ -1078,6 +1082,8 @@ function refreshScripts( fragment ) { |
1078 | 1082 | var script = scripts[i]; |
1079 | 1083 | var freshScript = document.createElement('script'); |
1080 | 1084 | copyAttributes( script, freshScript ); |
| 1085 | + // copy inner script code. #718, #782 |
| 1086 | + freshScript.innerHTML = script.innerHTML; |
1081 | 1087 | script.parentNode.replaceChild( freshScript, script ); |
1082 | 1088 | } |
1083 | 1089 | } |
@@ -1200,7 +1206,7 @@ proto.getPrefillDistance = function() { |
1200 | 1206 | }; |
1201 | 1207 |
|
1202 | 1208 | proto.stopPrefill = function() { |
1203 | | - console.log('stopping prefill'); |
| 1209 | + this.log('stopPrefill'); |
1204 | 1210 | this.off( 'append', this.prefill ); |
1205 | 1211 | }; |
1206 | 1212 |
|
@@ -1462,6 +1468,10 @@ proto.destroyHistory = function() { |
1462 | 1468 | // ----- append history ----- // |
1463 | 1469 |
|
1464 | 1470 | proto.onAppendHistory = function( response, path, items ) { |
| 1471 | + // do not proceed if no items. #779 |
| 1472 | + if ( !items || !items.length ) { |
| 1473 | + return; |
| 1474 | + } |
1465 | 1475 | var firstItem = items[0]; |
1466 | 1476 | var elemScrollY = this.getElementScrollY( firstItem ); |
1467 | 1477 | // resolve path |
@@ -1538,7 +1548,7 @@ proto.setHistory = function( title, path ) { |
1538 | 1548 | }; |
1539 | 1549 |
|
1540 | 1550 | // scroll to top to prevent initial scroll-reset after page refresh |
1541 | | -// http://stackoverflow.com/a/18633915/182183 |
| 1551 | +// https://stackoverflow.com/a/18633915/182183 |
1542 | 1552 | proto.onUnload = function() { |
1543 | 1553 | var pageIndex = this.scrollPageIndex; |
1544 | 1554 | if ( pageIndex === 0 ) { |
@@ -1768,7 +1778,7 @@ return InfiniteScroll; |
1768 | 1778 | })); |
1769 | 1779 |
|
1770 | 1780 | /*! |
1771 | | - * Infinite Scroll v3.0.3 |
| 1781 | + * Infinite Scroll v3.0.4 |
1772 | 1782 | * Automatically add next page |
1773 | 1783 | * |
1774 | 1784 | * Licensed GPLv3 for open source use |
|
0 commit comments