vendor: 12,480 bytes, lines 1-493
1/*! 2 * imagesLoaded PACKAGED v4.1.3 3 * JavaScript is all like "You images are done yet or what?" 4 * MIT License 5 */ 6 7/** 8 * EvEmitter v1.1.0 9 * Lil' event emitter 10 * MIT License 11 */ 12 13/* jshint unused: true, undef: true, strict: true */ 14 15( function( global, factory ) { 16 // universal module definition 17 /* jshint strict: false */ /* globals define, module, window */ 18 if ( typeof define == 'function' && define.amd ) { 19 // AMD - RequireJS 20 define( 'ev-emitter/ev-emitter',factory ); 21 } else if ( typeof module == 'object' && module.exports ) { 22 // CommonJS - Browserify, Webpack 23 module.exports = factory(); 24 } else { 25 // Browser globals 26 global.EvEmitter = factory(); 27 } 28 29}( typeof window != 'undefined' ? window : this, function() { 30 31 32 33function EvEmitter() {} 34 35var proto = EvEmitter.prototype; 36 37proto.on = function( eventName, listener ) { 38 if ( !eventName || !listener ) { 39 return; 40 } 41 // set events hash 42 var events = this._events = this._events || {}; 43 // set listeners array 44 var listeners = events[ eventName ] = events[ eventName ] || []; 45 // only add once 46 if ( listeners.indexOf( listener ) == -1 ) { 47 listeners.push( listener ); 48 } 49 50 return this; 51}; 52 53proto.once = function( eventName, listener ) { 54 if ( !eventName || !listener ) { 55 return; 56 } 57 // add event 58 this.on( eventName, listener ); 59 // set once flag 60 // set onceEvents hash 61 var onceEvents = this._onceEvents = this._onceEvents || {}; 62 // set onceListeners object 63 var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {}; 64 // set flag 65 onceListeners[ listener ] = true; 66 67 return this; 68}; 69 70proto.off = function( eventName, listener ) { 71 var listeners = this._events && this._events[ eventName ]; 72 if ( !listeners || !listeners.length ) { 73 return; 74 } 75 var index = listeners.indexOf( listener ); 76 if ( index != -1 ) { 77 listeners.splice( index, 1 ); 78 } 79 80 return this; 81}; 82 83proto.emitEvent = function( eventName, args ) { 84 var listeners = this._events && this._events[ eventName ]; 85 if ( !listeners || !listeners.length ) { 86 return; 87 } 88 var i = 0; 89 var listener = listeners[i]; 90 args = args || []; 91 // once stuff 92 var onceListeners = this._onceEvents && this._onceEvents[ eventName ]; 93 94 while ( listener ) { 95 var isOnce = onceListeners && onceListeners[ listener ]; 96 if ( isOnce ) { 97 // remove listener 98 // remove before trigger to prevent recursion 99 this.off( eventName, listener ); 100 // unset once flag 101 delete onceListeners[ listener ]; 102 } 103 // trigger listener 104 listener.apply( this, args ); 105 // get next listener 106 i += isOnce ? 0 : 1; 107 listener = listeners[i]; 108 } 109 110 return this; 111}; 112 113proto.allOff = 114proto.removeAllListeners = function() { 115 delete this._events; 116 delete this._onceEvents; 117}; 118 119return EvEmitter; 120 121})); 122 123/*! 124 * imagesLoaded v4.1.3 125 * JavaScript is all like "You images are done yet or what?" 126 * MIT License 127 */ 128 129( function( window, factory ) { 'use strict'; 130 // universal module definition 131 132 /*global define: false, module: false, require: false */ 133 134 if ( typeof define == 'function' && define.amd ) { 135 // AMD 136 define( [ 137 'ev-emitter/ev-emitter' 138 ], function( EvEmitter ) { 139 return factory( window, EvEmitter ); 140 }); 141 } else if ( typeof module == 'object' && module.exports ) { 142 // CommonJS 143 module.exports = factory( 144 window, 145 require('ev-emitter') 146 ); 147 } else { 148 // browser global 149 window.imagesLoaded = factory( 150 window, 151 window.EvEmitter 152 ); 153 } 154 155})( typeof window !== 'undefined' ? window : this, 156 157// -------------------------- factory -------------------------- // 158 159function factory( window, EvEmitter ) { 160 161 162 163var $ = window.jQuery; 164var console = window.console; 165 166// -------------------------- helpers -------------------------- // 167 168// extend objects 169function extend( a, b ) { 170 for ( var prop in b ) { 171 a[ prop ] = b[ prop ]; 172 } 173 return a; 174} 175 176// turn element or nodeList into an array 177function makeArray( obj ) { 178 var ary = []; 179 if ( Array.isArray( obj ) ) { 180 // use object if already an array 181 ary = obj; 182 } else if ( typeof obj.length == 'number' ) { 183 // convert nodeList to array 184 for ( var i=0; i < obj.length; i++ ) { 185 ary.push( obj[i] ); 186 } 187 } else { 188 // array of single index 189 ary.push( obj ); 190 } 191 return ary; 192} 193 194// -------------------------- imagesLoaded -------------------------- // 195 196/** 197 * @param {Array, Element, NodeList, String} elem 198 * @param {Object or Function} options - if function, use as callback 199 * @param {Function} onAlways - callback function 200 */ 201function ImagesLoaded( elem, options, onAlways ) { 202 // coerce ImagesLoaded() without new, to be new ImagesLoaded() 203 if ( !( this instanceof ImagesLoaded ) ) { 204 return new ImagesLoaded( elem, options, onAlways ); 205 } 206 // use elem as selector string 207 if ( typeof elem == 'string' ) { 208 elem = document.querySelectorAll( elem ); 209 } 210 211 this.elements = makeArray( elem ); 212 this.options = extend( {}, this.options ); 213 214 if ( typeof options == 'function' ) { 215 onAlways = options; 216 } else { 217 extend( this.options, options ); 218 } 219 220 if ( onAlways ) { 221 this.on( 'always', onAlways ); 222 } 223 224 this.getImages(); 225 226 if ( $ ) { 227 // add jQuery Deferred object 228 this.jqDeferred = new $.Deferred(); 229 } 230 231 // HACK check async to allow time to bind listeners 232 setTimeout( function() { 233 this.check(); 234 }.bind( this )); 235} 236 237ImagesLoaded.prototype = Object.create( EvEmitter.prototype ); 238 239ImagesLoaded.prototype.options = {}; 240 241ImagesLoaded.prototype.getImages = function() { 242 this.images = []; 243 244 // filter & find items if we have an item selector 245 this.elements.forEach( this.addElementImages, this ); 246}; 247 248/** 249 * @param {Node} element 250 */ 251ImagesLoaded.prototype.addElementImages = function( elem ) { 252 // filter siblings 253 if ( elem.nodeName == 'IMG' ) { 254 this.addImage( elem ); 255 } 256 // get background image on element 257 if ( this.options.background === true ) { 258 this.addElementBackgroundImages( elem ); 259 } 260 261 // find children 262 // no non-element nodes, #143 263 var nodeType = elem.nodeType; 264 if ( !nodeType || !elementNodeTypes[ nodeType ] ) { 265 return; 266 } 267 var childImgs = elem.querySelectorAll('img'); 268 // concat childElems to filterFound array 269 for ( var i=0; i < childImgs.length; i++ ) { 270 var img = childImgs[i]; 271 this.addImage( img ); 272 } 273 274 // get child background images 275 if ( typeof this.options.background == 'string' ) { 276 var children = elem.querySelectorAll( this.options.background ); 277 for ( i=0; i < children.length; i++ ) { 278 var child = children[i]; 279 this.addElementBackgroundImages( child ); 280 } 281 } 282}; 283 284var elementNodeTypes = { 285 1: true, 286 9: true, 287 11: true 288}; 289 290ImagesLoaded.prototype.addElementBackgroundImages = function( elem ) { 291 var style = getComputedStyle( elem ); 292 if ( !style ) { 293 // Firefox returns null if in a hidden iframe https://bugzil.la/548397 294 return; 295 } 296 // get url inside url("...") 297 var reURL = /url\((['"])?(.*?)\1\)/gi; 298 var matches = reURL.exec( style.backgroundImage ); 299 while ( matches !== null ) { 300 var url = matches && matches[2]; 301 if ( url ) { 302 this.addBackground( url, elem ); 303 } 304 matches = reURL.exec( style.backgroundImage ); 305 } 306}; 307 308/** 309 * @param {Image} img 310 */ 311ImagesLoaded.prototype.addImage = function( img ) { 312 var loadingImage = new LoadingImage( img ); 313 this.images.push( loadingImage ); 314}; 315 316ImagesLoaded.prototype.addBackground = function( url, elem ) { 317 var background = new Background( url, elem ); 318 this.images.push( background ); 319}; 320 321ImagesLoaded.prototype.check = function() { 322 var _this = this; 323 this.progressedCount = 0; 324 this.hasAnyBroken = false; 325 // complete if no images 326 if ( !this.images.length ) { 327 this.complete(); 328 return; 329 } 330 331 function onProgress( image, elem, message ) { 332 // HACK - Chrome triggers event before object properties have changed. #83 333 setTimeout( function() { 334 _this.progress( image, elem, message ); 335 }); 336 } 337 338 this.images.forEach( function( loadingImage ) { 339 loadingImage.once( 'progress', onProgress ); 340 loadingImage.check(); 341 }); 342}; 343 344ImagesLoaded.prototype.progress = function( image, elem, message ) { 345 this.progressedCount++; 346 this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded; 347 // progress event 348 this.emitEvent( 'progress', [ this, image, elem ] ); 349 if ( this.jqDeferred && this.jqDeferred.notify ) { 350 this.jqDeferred.notify( this, image ); 351 } 352 // check if completed 353 if ( this.progressedCount == this.images.length ) { 354 this.complete(); 355 } 356 357 if ( this.options.debug && console ) { 358 console.log( 'progress: ' + message, image, elem ); 359 } 360}; 361 362ImagesLoaded.prototype.complete = function() { 363 var eventName = this.hasAnyBroken ? 'fail' : 'done'; 364 this.isComplete = true; 365 this.emitEvent( eventName, [ this ] ); 366 this.emitEvent( 'always', [ this ] ); 367 if ( this.jqDeferred ) { 368 var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve'; 369 this.jqDeferred[ jqMethod ]( this ); 370 } 371}; 372 373// -------------------------- -------------------------- // 374 375function LoadingImage( img ) { 376 this.img = img; 377} 378 379LoadingImage.prototype = Object.create( EvEmitter.prototype ); 380 381LoadingImage.prototype.check = function() { 382 // If complete is true and browser supports natural sizes, 383 // try to check for image status manually. 384 var isComplete = this.getIsImageComplete(); 385 if ( isComplete ) { 386 // report based on naturalWidth 387 this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' ); 388 return; 389 } 390 391 // If none of the checks above matched, simulate loading on detached element. 392 this.proxyImage = new Image(); 393 this.proxyImage.addEventListener( 'load', this ); 394 this.proxyImage.addEventListener( 'error', this ); 395 // bind to image as well for Firefox. #191 396 this.img.addEventListener( 'load', this ); 397 this.img.addEventListener( 'error', this ); 398 this.proxyImage.src = this.img.src; 399}; 400 401LoadingImage.prototype.getIsImageComplete = function() { 402 return this.img.complete && this.img.naturalWidth !== undefined; 403}; 404 405LoadingImage.prototype.confirm = function( isLoaded, message ) { 406 this.isLoaded = isLoaded; 407 this.emitEvent( 'progress', [ this, this.img, message ] ); 408}; 409 410// ----- events ----- // 411 412// trigger specified handler for event type 413LoadingImage.prototype.handleEvent = function( event ) { 414 var method = 'on' + event.type; 415 if ( this[ method ] ) { 416 this[ method ]( event ); 417 } 418}; 419 420LoadingImage.prototype.onload = function() { 421 this.confirm( true, 'onload' ); 422 this.unbindEvents(); 423}; 424 425LoadingImage.prototype.onerror = function() { 426 this.confirm( false, 'onerror' ); 427 this.unbindEvents(); 428}; 429 430LoadingImage.prototype.unbindEvents = function() { 431 this.proxyImage.removeEventListener( 'load', this ); 432 this.proxyImage.removeEventListener( 'error', this ); 433 this.img.removeEventListener( 'load', this ); 434 this.img.removeEventListener( 'error', this ); 435}; 436 437// -------------------------- Background -------------------------- // 438 439function Background( url, element ) { 440 this.url = url; 441 this.element = element; 442 this.img = new Image(); 443} 444 445// inherit LoadingImage prototype 446Background.prototype = Object.create( LoadingImage.prototype ); 447 448Background.prototype.check = function() { 449 this.img.addEventListener( 'load', this ); 450 this.img.addEventListener( 'error', this ); 451 this.img.src = this.url; 452 // check if image is already complete 453 var isComplete = this.getIsImageComplete(); 454 if ( isComplete ) { 455 this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' ); 456 this.unbindEvents(); 457 } 458}; 459 460Background.prototype.unbindEvents = function() { 461 this.img.removeEventListener( 'load', this ); 462 this.img.removeEventListener( 'error', this ); 463}; 464 465Background.prototype.confirm = function( isLoaded, message ) { 466 this.isLoaded = isLoaded; 467 this.emitEvent( 'progress', [ this, this.element, message ] ); 468}; 469 470// -------------------------- jQuery -------------------------- // 471 472ImagesLoaded.makeJQueryPlugin = function( jQuery ) { 473 jQuery = jQuery || window.jQuery; 474 if ( !jQuery ) { 475 return; 476 } 477 // set local variable 478 $ = jQuery; 479 // $().imagesLoaded() 480 $.fn.imagesLoaded = function( options, callback ) { 481 var instance = new ImagesLoaded( this, options, callback ); 482 return instance.jqDeferred.promise( $(this) ); 483 }; 484}; 485// try making plugin 486ImagesLoaded.makeJQueryPlugin(); 487 488// -------------------------- -------------------------- // 489 490return ImagesLoaded; 491 492}); 493
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.