| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- import { Cache } from './Cache';
- import { DefaultLoadingManager } from './LoadingManager';
- function ImageLoader( manager ) {
- this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
- }
- Object.assign( ImageLoader.prototype, {
- load: function ( url, onLoad, onProgress, onError ) {
- if ( url === undefined ) url = '';
- if ( this.path !== undefined ) url = this.path + url;
- var scope = this;
- var cached = Cache.get( url );
- if ( cached !== undefined ) {
- scope.manager.itemStart( url );
- setTimeout( function () {
- if ( onLoad ) onLoad( cached );
- scope.manager.itemEnd( url );
- }, 0 );
- return cached;
- }
- var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
- image.addEventListener( 'load', function () {
- Cache.add( url, this );
- if ( onLoad ) onLoad( this );
- scope.manager.itemEnd( url );
- }, false );
- /*
- image.addEventListener( 'progress', function ( event ) {
- if ( onProgress ) onProgress( event );
- }, false );
- */
- image.addEventListener( 'error', function ( event ) {
- if ( onError ) onError( event );
- scope.manager.itemError( url );
- }, false );
- if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
- scope.manager.itemStart( url );
- image.src = url;
- return image;
- },
- setCrossOrigin: function ( value ) {
- this.crossOrigin = value;
- return this;
- },
- setPath: function ( value ) {
- this.path = value;
- return this;
- }
- } );
- export { ImageLoader };
|