1-
2-
3- ! function ( e , t ) { "function" == typeof define && define . amd ?define ( "ev-emitter/ev-emitter" , t ) :"object" == typeof module && module . exports ?module . exports = t ( ) :e . EvEmitter = t ( ) } ( "undefined" != typeof window ?window :this , function ( ) { function e ( ) { } var t = e . prototype ; return t . on = function ( e , t ) { if ( e && t ) { var i = this . _events = this . _events || { } , n = i [ e ] = i [ e ] || [ ] ; return - 1 == n . indexOf ( t ) && n . push ( t ) , this } } , t . once = function ( e , t ) { if ( e && t ) { this . on ( e , t ) ; var i = this . _onceEvents = this . _onceEvents || { } , n = i [ e ] = i [ e ] || { } ; return n [ t ] = ! 0 , this } } , t . off = function ( e , t ) { var i = this . _events && this . _events [ e ] ; if ( i && i . length ) { var n = i . indexOf ( t ) ; return - 1 != n && i . splice ( n , 1 ) , this } } , t . emitEvent = function ( e , t ) { var i = this . _events && this . _events [ e ] ; if ( i && i . length ) { var n = 0 , o = i [ n ] ; t = t || [ ] ; for ( var r = this . _onceEvents && this . _onceEvents [ e ] ; o ; ) { var s = r && r [ o ] ; s && ( this . off ( e , o ) , delete r [ o ] ) , o . apply ( this , t ) , n += s ?0 :1 , o = i [ n ] } return this } } , t . allOff = t . removeAllListeners = function ( ) { delete this . _events , delete this . _onceEvents } , e } ) , function ( e , t ) { "use strict" ; "function" == typeof define && define . amd ?define ( [ "ev-emitter/ev-emitter" ] , function ( i ) { return t ( e , i ) } ) :"object" == typeof module && module . exports ?module . exports = t ( e , require ( "ev-emitter" ) ) :e . imagesLoaded = t ( e , e . EvEmitter ) } ( "undefined" != typeof window ?window :this , function ( e , t ) { function i ( e , t ) { for ( var i in t ) e [ i ] = t [ i ] ; return e } function n ( e ) { var t = [ ] ; if ( Array . isArray ( e ) ) t = e ; else if ( "number" == typeof e . length ) for ( var i = 0 ; i < e . length ; i ++ ) t . push ( e [ i ] ) ; else t . push ( e ) ; return t } function o ( e , t , r ) { return this instanceof o ?( "string" == typeof e && ( e = document . querySelectorAll ( e ) ) , this . elements = n ( e ) , this . options = i ( { } , this . options ) , "function" == typeof t ?r = t :i ( this . options , t ) , r && this . on ( "always" , r ) , this . getImages ( ) , h && ( this . jqDeferred = new h . Deferred ) , void setTimeout ( function ( ) { this . check ( ) } . bind ( this ) ) ) :new o ( e , t , r ) } function r ( e ) { this . img = e } function s ( e , t ) { this . url = e , this . element = t , this . img = new Image } var h = e . jQuery , a = e . console ; o . prototype = Object . create ( t . prototype ) , o . prototype . options = { } , o . prototype . getImages = function ( ) { this . images = [ ] , this . elements . forEach ( this . addElementImages , this ) } , o . prototype . addElementImages = function ( e ) { "IMG" == e . nodeName && this . addImage ( e ) , this . options . background === ! 0 && this . addElementBackgroundImages ( e ) ; var t = e . nodeType ; if ( t && d [ t ] ) { for ( var i = e . querySelectorAll ( "img" ) , n = 0 ; n < i . length ; n ++ ) { var o = i [ n ] ; this . addImage ( o ) } if ( "string" == typeof this . options . background ) { var r = e . querySelectorAll ( this . options . background ) ; for ( n = 0 ; n < r . length ; n ++ ) { var s = r [ n ] ; this . addElementBackgroundImages ( s ) } } } } ; var d = { 1 :! 0 , 9 :! 0 , 11 :! 0 } ; return o . prototype . addElementBackgroundImages = function ( e ) { var t = getComputedStyle ( e ) ; if ( t ) for ( var i = / u r l \( ( [ ' " ] ) ? ( .* ?) \1\) / gi, n = i . exec ( t . backgroundImage ) ; null !== n ; ) { var o = n && n [ 2 ] ; o && this . addBackground ( o , e ) , n = i . exec ( t . backgroundImage ) } } , o . prototype . addImage = function ( e ) { var t = new r ( e ) ; this . images . push ( t ) } , o . prototype . addBackground = function ( e , t ) { var i = new s ( e , t ) ; this . images . push ( i ) } , o . prototype . check = function ( ) { function e ( e , i , n ) { setTimeout ( function ( ) { t . progress ( e , i , n ) } ) } var t = this ; return this . progressedCount = 0 , this . hasAnyBroken = ! 1 , this . images . length ?void this . images . forEach ( function ( t ) { t . once ( "progress" , e ) , t . check ( ) } ) :void this . complete ( ) } , o . prototype . progress = function ( e , t , i ) { this . progressedCount ++ , this . hasAnyBroken = this . hasAnyBroken || ! e . isLoaded , this . emitEvent ( "progress" , [ this , e , t ] ) , this . jqDeferred && this . jqDeferred . notify && this . jqDeferred . notify ( this , e ) , this . progressedCount == this . images . length && this . complete ( ) , this . options . debug && a && a . log ( "progress: " + i , e , t ) } , o . prototype . complete = function ( ) { var e = this . hasAnyBroken ?"fail" :"done" ; if ( this . isComplete = ! 0 , this . emitEvent ( e , [ this ] ) , this . emitEvent ( "always" , [ this ] ) , this . jqDeferred ) { var t = this . hasAnyBroken ?"reject" :"resolve" ; this . jqDeferred [ t ] ( this ) } } , r . prototype = Object . create ( t . prototype ) , r . prototype . check = function ( ) { var e = this . getIsImageComplete ( ) ; return e ?void this . confirm ( 0 !== this . img . naturalWidth , "naturalWidth" ) :( this . proxyImage = new Image , this . proxyImage . addEventListener ( "load" , this ) , this . proxyImage . addEventListener ( "error" , this ) , this . img . addEventListener ( "load" , this ) , this . img . addEventListener ( "error" , this ) , void ( this . proxyImage . src = this . img . src ) ) } , r . prototype . getIsImageComplete = function ( ) { return this . img . complete && void 0 !== this . img . naturalWidth } , r . prototype . confirm = function ( e , t ) { this . isLoaded = e , this . emitEvent ( "progress" , [ this , this . img , t ] ) } , r . prototype . handleEvent = function ( e ) { var t = "on" + e . type ; this [ t ] && this [ t ] ( e ) } , r . prototype . onload = function ( ) { this . confirm ( ! 0 , "onload" ) , this . unbindEvents ( ) } , r . prototype . onerror = function ( ) { this . confirm ( ! 1 , "onerror" ) , this . unbindEvents ( ) } , r . prototype . unbindEvents = function ( ) { this . proxyImage . removeEventListener ( "load" , this ) , this . proxyImage . removeEventListener ( "error" , this ) , this . img . removeEventListener ( "load" , this ) , this . img . removeEventListener ( "error" , this ) } , s . prototype = Object . create ( r . prototype ) , s . prototype . check = function ( ) { this . img . addEventListener ( "load" , this ) , this . img . addEventListener ( "error" , this ) , this . img . src = this . url ; var e = this . getIsImageComplete ( ) ; e && ( this . confirm ( 0 !== this . img . naturalWidth , "naturalWidth" ) , this . unbindEvents ( ) ) } , s . prototype . unbindEvents = function ( ) { this . img . removeEventListener ( "load" , this ) , this . img . removeEventListener ( "error" , this ) } , s . prototype . confirm = function ( e , t ) { this . isLoaded = e , this . emitEvent ( "progress" , [ this , this . element , t ] ) } , o . makeJQueryPlugin = function ( t ) { t = t || e . jQuery , t && ( h = t , h . fn . imagesLoaded = function ( e , t ) { var i = new o ( this , e , t ) ; return i . jqDeferred . promise ( h ( this ) ) } ) } , o . makeJQueryPlugin ( ) , o } ) ;
1+ ( function ( global , factory ) {
2+ if ( typeof define === 'function' && define . amd ) {
3+ define ( 'ev-emitter/ev-emitter' , factory ) ;
4+ } else if ( typeof module === 'object' && module . exports ) {
5+ module . exports = factory ( ) ;
6+ } else {
7+ global . EvEmitter = factory ( ) ;
8+ }
9+ } ( typeof window !== 'undefined' ? window : this , function ( ) {
10+ function EvEmitter ( ) { }
11+ var proto = EvEmitter . prototype ;
12+ proto . on = function ( eventName , listener ) {
13+ if ( ! eventName || ! listener ) return ;
14+ this . _events = this . _events || { } ;
15+ var listeners = ( this . _events [ eventName ] = this . _events [ eventName ] || [ ] ) ;
16+ if ( listeners . indexOf ( listener ) === 0 ) {
17+ listeners . push ( listener ) ;
18+ }
19+ return this ;
20+ } ;
21+ proto . once = function ( eventName , listener ) {
22+ if ( ! eventName || ! listener ) return ;
23+ this . on ( eventName , listener ) ;
24+ this . _onceEvents = this . _onceEvents || { } ;
25+ this . _onceEvents [ eventName ] = this . _onceEvents [ eventName ] || { } ;
26+ this . _onceEvents [ eventName ] [ listener ] = true ;
27+ return this ;
28+ } ;
29+ proto . off = function ( eventName , listener ) {
30+ var listeners = this . _events && this . _events [ eventName ] ;
31+ if ( ! listeners || ! listeners . length ) return ;
32+ var index = listeners . indexOf ( listener ) ;
33+ if ( index !== - 1 ) {
34+ listeners . splice ( index , 1 ) ;
35+ }
36+ return this ;
37+ } ;
38+ proto . emitEvent = function ( eventName , args ) {
39+ var listeners = this . _events && this . _events [ eventName ] ;
40+ if ( ! listeners || ! listeners . length ) return ;
41+ listeners = listeners . slice ( 0 ) ;
42+ args = args || [ ] ;
43+ var onceListeners = this . _onceEvents && this . _onceEvents [ eventName ] ;
44+ for ( var i = 0 ; i < listeners . length ; i ++ ) {
45+ var listener = listeners [ i ] ;
46+ var isOnce = onceListeners && onceListeners [ listener ] ;
47+ if ( isOnce ) {
48+ this . off ( eventName , listener ) ;
49+ delete onceListeners [ listener ] ;
50+ }
51+ listener . apply ( this , args ) ;
52+ }
53+ return this ;
54+ } ;
55+ proto . allOff = proto . removeAllListeners = function ( ) {
56+ delete this . _events ;
57+ delete this . _onceEvents ;
58+ } ;
59+ return EvEmitter ;
60+ } ) ) ;
61+
62+ ( function ( window , factory ) {
63+ 'use strict' ;
64+ if ( typeof define === 'function' && define . amd ) {
65+ define ( [ 'ev-emitter/ev-emitter' ] , function ( EvEmitter ) {
66+ return factory ( window , EvEmitter ) ;
67+ } ) ;
68+ } else if ( typeof module === 'object' && module . exports ) {
69+ module . exports = factory ( window , require ( 'ev-emitter' ) ) ;
70+ } else {
71+ window . imagesLoaded = factory ( window , window . EvEmitter ) ;
72+ }
73+ } ) ( typeof window !== 'undefined' ? window : this , function ( window , EvEmitter ) {
74+ function extend ( obj , extension ) {
75+ for ( var key in extension ) {
76+ obj [ key ] = extension [ key ] ;
77+ }
78+ return obj ;
79+ }
80+
81+ function makeArray ( obj ) {
82+ var arr = [ ] ;
83+ if ( Array . isArray ( obj ) ) {
84+ arr = obj ;
85+ } else if ( typeof obj . length === 'number' ) {
86+ for ( var i = 0 ; i < obj . length ; i ++ ) {
87+ arr . push ( obj [ i ] ) ;
88+ }
89+ } else {
90+ arr . push ( obj ) ;
91+ }
92+ return arr ;
93+ }
94+
95+ function ImageLoader ( elem , options , callback ) {
96+ if ( ! ( this instanceof ImageLoader ) ) {
97+ return new ImageLoader ( elem , options , callback ) ;
98+ }
99+ if ( typeof elem === 'string' ) {
100+ elem = document . querySelectorAll ( elem ) ;
101+ }
102+ this . elements = makeArray ( elem ) ;
103+ this . options = extend ( { } , this . options ) ;
104+ if ( typeof options === 'function' ) {
105+ callback = options ;
106+ } else {
107+ extend ( this . options , options ) ;
108+ }
109+ if ( callback ) {
110+ this . on ( 'always' , callback ) ;
111+ }
112+ this . getImages ( ) ;
113+ setTimeout ( function ( ) {
114+ this . check ( ) ;
115+ } . bind ( this ) ) ;
116+ }
117+
118+ extend ( ImageLoader . prototype , EvEmitter . prototype ) ;
119+
120+ ImageLoader . prototype . options = { } ;
121+
122+ ImageLoader . prototype . getImages = function ( ) {
123+ this . images = [ ] ;
124+ this . elements . forEach ( this . addElementImages , this ) ;
125+ } ;
126+
127+ ImageLoader . prototype . addElementImages = function ( element ) {
128+ if ( element . nodeName === 'IMG' ) {
129+ this . addImage ( element ) ;
130+ }
131+ if ( this . options . background === true ) {
132+ this . addElementBackgroundImages ( element ) ;
133+ }
134+ var nodeType = element . nodeType ;
135+ if ( nodeType && nodeTypes [ nodeType ] ) {
136+ var images = element . querySelectorAll ( 'img' ) ;
137+ for ( var i = 0 ; i < images . length ; i ++ ) {
138+ var img = images [ i ] ;
139+ this . addImage ( img ) ;
140+ }
141+ if ( typeof this . options . background === 'string' ) {
142+ var backgroundElems = element . querySelectorAll ( this . options . background ) ;
143+ for ( var j = 0 ; j < backgroundElems . length ; j ++ ) {
144+ var backgroundElem = backgroundElems [ j ] ;
145+ this . addElementBackgroundImages ( backgroundElem ) ;
146+ }
147+ }
148+ }
149+ } ;
150+
151+ var nodeTypes = { 1 : true , 9 : true , 11 : true } ;
152+
153+ ImageLoader . prototype . addElementBackgroundImages = function ( element ) {
154+ var style = window . getComputedStyle ( element ) ;
155+ if ( ! style ) return ;
156+ var backgroundImages = style . backgroundImage ;
157+ var urlMatch = backgroundUrlRegex . exec ( backgroundImages ) ;
158+ while ( urlMatch !== null ) {
159+ var imageUrl = urlMatch [ 2 ] ;
160+ this . addBackground ( imageUrl , element ) ;
161+ urlMatch = backgroundUrlRegex . exec ( backgroundImages ) ;
162+ }
163+ } ;
164+
165+ var backgroundUrlRegex = / u r l \( ( [ ' " ] ) ? ( .* ?) \1\) / gi;
166+
167+ ImageLoader . prototype . addImage = function ( img ) {
168+ var loader = new ImgLoader ( img ) ;
169+ this . images . push ( loader ) ;
170+ } ;
171+
172+ ImageLoader . prototype . addBackground = function ( url , element ) {
173+ var loader = new BgImgLoader ( url , element ) ;
174+ this . images . push ( loader ) ;
175+ } ;
176+
177+ ImageLoader . prototype . check = function ( ) {
178+ var progressCounter = 0 ;
179+ var hasAnyBroken = false ;
180+ var _this = this ;
181+
182+ function onProgress ( image , elem , message ) {
183+ setTimeout ( function ( ) {
184+ _this . progress ( image , elem , message ) ;
185+ } ) ;
186+ }
187+
188+ this . images . forEach ( function ( image ) {
189+ image . once ( 'progress' , onProgress ) ;
190+ image . check ( ) ;
191+ } ) ;
192+
193+ function progress ( image , elem , message ) {
194+ progressCounter ++ ;
195+ hasAnyBroken = hasAnyBroken || ! image . isLoaded ;
196+ _this . emitEvent ( 'progress' , [ image , elem , message ] ) ;
197+ if ( progressCounter === _this . images . length ) {
198+ _this . complete ( ) ;
199+ }
200+ }
201+
202+ this . progressedCount = progressCounter ;
203+ this . hasAnyBroken = hasAnyBroken ;
204+ if ( this . images . length === 0 ) {
205+ this . complete ( ) ;
206+ }
207+ } ;
208+
209+ ImageLoader . prototype . progress = function ( image , elem , message ) {
210+ this . progressedCount ++ ;
211+ this . hasAnyBroken = this . hasAnyBroken || ! image . isLoaded ;
212+ this . emitEvent ( 'progress' , [ this , image , elem , message ] ) ;
213+ if ( this . progressedCount === this . images . length ) {
214+ this . complete ( ) ;
215+ }
216+ } ;
217+
218+ ImageLoader . prototype . complete = function ( ) {
219+ var eventName = this . hasAnyBroken ? 'fail' : 'done' ;
220+ this . isComplete = true ;
221+ this . emitEvent ( eventName , [ this ] ) ;
222+ this . emitEvent ( 'always' , [ this ] ) ;
223+ if ( this . deferred ) {
224+ var method = this . hasAnyBroken ? 'reject' : 'resolve' ;
225+ this . deferred [ method ] ( this ) ;
226+ }
227+ } ;
228+
229+ function ImgLoader ( img ) {
230+ this . img = img ;
231+ }
232+
233+ extend ( ImgLoader . prototype , EvEmitter . prototype ) ;
234+
235+ ImgLoader . prototype . check = function ( ) {
236+ var _this = this ;
237+ this . getIsImageComplete ( )
238+ ? this . confirm ( this . img . naturalWidth !== 0 , 'naturalWidth' )
239+ : ( ( this . proxyImage = new Image ( ) ) ,
240+ this . proxyImage . addEventListener ( 'load' , function ( ) {
241+ _this . confirm ( true , 'proxyImage' ) ;
242+ } ) ,
243+ this . proxyImage . addEventListener ( 'error' , function ( ) {
244+ _this . confirm ( false , 'proxyImage' ) ;
245+ } ) ,
246+ ( this . img . addEventListener ( 'load' , function ( ) {
247+ _this . confirm ( true , 'img' ) ;
248+ } ) ,
249+ this . img . addEventListener ( 'error' , function ( ) {
250+ _this . confirm ( false , 'img' ) ;
251+ } ) ,
252+ ( this . proxyImage . src = this . img . src ) ) ) ;
253+ } ;
254+
255+ ImgLoader . prototype . getIsImageComplete = function ( ) {
256+ return this . img . complete && this . img . naturalWidth !== undefined ;
257+ } ;
258+
259+ ImgLoader . prototype . confirm = function ( isLoaded , message ) {
260+ this . isLoaded = isLoaded ;
261+ this . emitEvent ( 'progress' , [ this , this . img , message ] ) ;
262+ } ;
263+
264+ function BgImgLoader ( url , element ) {
265+ this . url = url ;
266+ this . element = element ;
267+ this . img = new Image ( ) ;
268+ }
269+
270+ extend ( BgImgLoader . prototype , ImgLoader . prototype ) ;
271+
272+ BgImgLoader . prototype . check = function ( ) {
273+ var _this = this ;
274+ this . img . addEventListener ( 'load' , function ( ) {
275+ _this . confirm ( true , 'img' ) ;
276+ } ) ;
277+ this . img . addEventListener ( 'error' , function ( ) {
278+ _this . confirm ( false , 'img' ) ;
279+ } ) ;
280+ this . img . src = this . url ;
281+ this . getIsImageComplete ( ) &&
282+ ( this . confirm ( this . img . naturalWidth !== 0 , 'naturalWidth' ) ,
283+ this . unbindEvents ( ) ) ;
284+ } ;
285+
286+ BgImgLoader . prototype . confirm = function ( isLoaded , message ) {
287+ this . isLoaded = isLoaded ;
288+ this . emitEvent ( 'progress' , [ this , this . element , message ] ) ;
289+ } ;
290+
291+ return ImageLoader ;
292+ } ) ;
293+
0 commit comments