All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bsf.js.image-loader.js Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
Image.prototype.load = function( url, onLoadStartCallback, onProgressCallback, onLoadEndCallback ) {
    var thisImg = this,
        xmlHTTP = new XMLHttpRequest();

    thisImg.completedPercentage = 0;

    xmlHTTP.open( 'GET', url , true );
    xmlHTTP.responseType = 'arraybuffer';

    xmlHTTP.onload = function( e ) {
        var h = xmlHTTP.getAllResponseHeaders(),
            m = h.match( /^Content-Type\:\s*(.*?)$/mi ),
            mimeType = m[ 1 ] || 'image/png';

        var blob = new Blob( [ this.response ], { type: mimeType } );
        thisImg.src = window.URL.createObjectURL( blob );
    };

    xmlHTTP.onprogress = function( e ) {
        if ( e.lengthComputable )
            thisImg.completedPercentage = parseInt( ( e.loaded / e.total ) * 100 );
        if ( onProgressCallback ) onProgressCallback( thisImg );
    };

    xmlHTTP.onloadstart = function() {
        thisImg.completedPercentage = 0;
        if ( onLoadStartCallback ) onLoadStartCallback( thisImg );
    };

    xmlHTTP.onloadend = function() {
        thisImg.completedPercentage = 100;
        if ( onLoadEndCallback ) onLoadEndCallback( thisImg );
    }

    xmlHTTP.send();
};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy