11/*!
2- * Infinite Scroll PACKAGED v3.0.2
2+ * Infinite Scroll PACKAGED v3.0.3
33 * Automatically add next page
44 *
55 * Licensed GPLv3 for open source use
66 * or Infinite Scroll Commercial License for commercial use
77 *
88 * https://infinite-scroll.com
9- * Copyright 2017 Metafizzy
9+ * Copyright 2018 Metafizzy
1010 */
1111
1212/**
@@ -234,13 +234,14 @@ proto.emitEvent = function( eventName, args ) {
234234 if ( ! listeners || ! listeners . length ) {
235235 return ;
236236 }
237- var i = 0 ;
238- var listener = listeners [ i ] ;
237+ // copy over to avoid interference if .off() in listener
238+ listeners = listeners . slice ( 0 ) ;
239239 args = args || [ ] ;
240240 // once stuff
241241 var onceListeners = this . _onceEvents && this . _onceEvents [ eventName ] ;
242242
243- while ( listener ) {
243+ for ( var i = 0 ; i < listeners . length ; i ++ ) {
244+ var listener = listeners [ i ]
244245 var isOnce = onceListeners && onceListeners [ listener ] ;
245246 if ( isOnce ) {
246247 // remove listener
@@ -251,16 +252,12 @@ proto.emitEvent = function( eventName, args ) {
251252 }
252253 // trigger listener
253254 listener . apply ( this , args ) ;
254- // get next listener
255- i += isOnce ? 0 : 1 ;
256- listener = listeners [ i ] ;
257255 }
258256
259257 return this ;
260258} ;
261259
262- proto . allOff =
263- proto . removeAllListeners = function ( ) {
260+ proto . allOff = function ( ) {
264261 delete this . _events ;
265262 delete this . _onceEvents ;
266263} ;
@@ -985,7 +982,7 @@ InfiniteScroll.defaults.responseType = 'document';
985982InfiniteScroll . create . pageLoad = function ( ) {
986983 this . canLoad = true ;
987984 this . on ( 'scrollThreshold' , this . onScrollThresholdLoad ) ;
988- this . on ( 'append ' , this . checkLastPage ) ;
985+ this . on ( 'load ' , this . checkLastPage ) ;
989986 if ( this . options . outlayer ) {
990987 this . on ( 'append' , this . onAppendOutlayer ) ;
991988 }
@@ -1771,14 +1768,14 @@ return InfiniteScroll;
17711768} ) ) ;
17721769
17731770/*!
1774- * Infinite Scroll v3.0.2
1771+ * Infinite Scroll v3.0.3
17751772 * Automatically add next page
17761773 *
17771774 * Licensed GPLv3 for open source use
17781775 * or Infinite Scroll Commercial License for commercial use
17791776 *
17801777 * https://infinite-scroll.com
1781- * Copyright 2017 Metafizzy
1778+ * Copyright 2018 Metafizzy
17821779 */
17831780
17841781( function ( window , factory ) {
@@ -1811,7 +1808,7 @@ return InfiniteScroll;
18111808} ) ;
18121809
18131810/*!
1814- * imagesLoaded v4.1.3
1811+ * imagesLoaded v4.1.4
18151812 * JavaScript is all like "You images are done yet or what?"
18161813 * MIT License
18171814 */
@@ -1863,22 +1860,23 @@ function extend( a, b ) {
18631860 return a ;
18641861}
18651862
1863+ var arraySlice = Array . prototype . slice ;
1864+
18661865// turn element or nodeList into an array
18671866function makeArray ( obj ) {
1868- var ary = [ ] ;
18691867 if ( Array . isArray ( obj ) ) {
18701868 // use object if already an array
1871- ary = obj ;
1872- } else if ( typeof obj . length == 'number' ) {
1869+ return obj ;
1870+ }
1871+
1872+ var isArrayLike = typeof obj == 'object' && typeof obj . length == 'number' ;
1873+ if ( isArrayLike ) {
18731874 // convert nodeList to array
1874- for ( var i = 0 ; i < obj . length ; i ++ ) {
1875- ary . push ( obj [ i ] ) ;
1876- }
1877- } else {
1878- // array of single index
1879- ary . push ( obj ) ;
1875+ return arraySlice . call ( obj ) ;
18801876 }
1881- return ary ;
1877+
1878+ // array of single index
1879+ return [ obj ] ;
18821880}
18831881
18841882// -------------------------- imagesLoaded -------------------------- //
@@ -1894,13 +1892,19 @@ function ImagesLoaded( elem, options, onAlways ) {
18941892 return new ImagesLoaded ( elem , options , onAlways ) ;
18951893 }
18961894 // use elem as selector string
1895+ var queryElem = elem ;
18971896 if ( typeof elem == 'string' ) {
1898- elem = document . querySelectorAll ( elem ) ;
1897+ queryElem = document . querySelectorAll ( elem ) ;
1898+ }
1899+ // bail if bad element
1900+ if ( ! queryElem ) {
1901+ console . error ( 'Bad element for imagesLoaded ' + ( queryElem || elem ) ) ;
1902+ return ;
18991903 }
19001904
1901- this . elements = makeArray ( elem ) ;
1905+ this . elements = makeArray ( queryElem ) ;
19021906 this . options = extend ( { } , this . options ) ;
1903-
1907+ // shift arguments if no options set
19041908 if ( typeof options == 'function' ) {
19051909 onAlways = options ;
19061910 } else {
@@ -1919,9 +1923,7 @@ function ImagesLoaded( elem, options, onAlways ) {
19191923 }
19201924
19211925 // HACK check async to allow time to bind listeners
1922- setTimeout ( function ( ) {
1923- this . check ( ) ;
1924- } . bind ( this ) ) ;
1926+ setTimeout ( this . check . bind ( this ) ) ;
19251927}
19261928
19271929ImagesLoaded . prototype = Object . create ( EvEmitter . prototype ) ;
@@ -2089,7 +2091,9 @@ LoadingImage.prototype.check = function() {
20892091} ;
20902092
20912093LoadingImage . prototype . getIsImageComplete = function ( ) {
2092- return this . img . complete && this . img . naturalWidth !== undefined ;
2094+ // check for non-zero, non-undefined naturalWidth
2095+ // fixes Safari+InfiniteScroll+Masonry bug infinite-scroll#671
2096+ return this . img . complete && this . img . naturalWidth ;
20932097} ;
20942098
20952099LoadingImage . prototype . confirm = function ( isLoaded , message ) {
0 commit comments