12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import { FileLoader } from './FileLoader';
- import { DefaultLoadingManager } from './LoadingManager';
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- function ImageLoader( manager ) {
- this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
- }
- Object.assign( ImageLoader.prototype, {
- load: function ( url, onLoad, onProgress, onError ) {
- var scope = this;
- var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
- image.onload = function () {
- image.onload = null;
- URL.revokeObjectURL( image.src );
- if ( onLoad ) onLoad( image );
- scope.manager.itemEnd( url );
- };
- image.onerror = onError;
- if ( url.indexOf( 'data:' ) === 0 ) {
- image.src = url;
- } else {
- var loader = new FileLoader();
- loader.setPath( this.path );
- loader.setResponseType( 'blob' );
- loader.setWithCredentials( this.withCredentials );
- loader.load( url, function ( blob ) {
- image.src = URL.createObjectURL( blob );
- }, onProgress, onError );
- }
- scope.manager.itemStart( url );
- return image;
- },
- setCrossOrigin: function ( value ) {
- this.crossOrigin = value;
- return this;
- },
- setWithCredentials: function ( value ) {
- this.withCredentials = value;
- return this;
- },
- setPath: function ( value ) {
- this.path = value;
- return this;
- }
- } );
- export { ImageLoader };
|