dist/joint.nowrap.js
function(url, callback) {

            if (!url || url.substr(0, 'data:'.length) === 'data:') {
                // No need to convert to data uri if it is already in data uri.

                // This not only convenient but desired. For example,
                // IE throws a security error if data:image/svg+xml is used to render
                // an image to the canvas and an attempt is made to read out data uri.
                // Now if our image is already in data uri, there is no need to render it to the canvas
                // and so we can bypass this error.

                // Keep the async nature of the function.
                return setTimeout(function() {
                    callback(null, url);
                }, 0);
            }

            // chrome, IE10+
            var modernHandler = function(xhr, callback) {

                if (xhr.status === 200) {

                    var reader = new FileReader();

                    reader.onload = function(evt) {
                        var dataUri = evt.target.result;
                        callback(null, dataUri);
                    };

                    reader.onerror = function() {
                        callback(new Error('Failed to load image ' + url));
                    };

                    reader.readAsDataURL(xhr.response);
                } else {
                    callback(new Error('Failed to load image ' + url));
                }
            };

            var legacyHandler = function(xhr, callback) {

                var Uint8ToString = function(u8a) {
                    var CHUNK_SZ = 0x8000;
                    var c = [];
                    for (var i = 0; i < u8a.length; i += CHUNK_SZ) {
                        c.push(String.fromCharCode.apply(null, u8a.subarray(i, i + CHUNK_SZ)));
                    }
                    return c.join('');
                };

                if (xhr.status === 200) {

                    var bytes = new Uint8Array(xhr.response);

                    var suffix = (url.split('.').pop()) || 'png';
                    var map = {
                        'svg': 'svg+xml'
                    };
                    var meta = 'data:image/' + (map[suffix] || suffix) + ';base64,';
                    var b64encoded = meta + btoa(Uint8ToString(bytes));
                    callback(null, b64encoded);
                } else {
                    callback(new Error('Failed to load image ' + url));
                }
            };

            var xhr = new XMLHttpRequest();

            xhr.open('GET', url, true);
            xhr.addEventListener('error', function() {
                callback(new Error('Failed to load image ' + url));
            });

            xhr.responseType = window.FileReader ? 'blob' : 'arraybuffer';

            xhr.addEventListener('load', function() {
                if (window.FileReader) {
                    modernHandler(xhr, callback);
                } else {
                    legacyHandler(xhr, callback);
                }
            });

            xhr.send();
        }
function(url, callback) {

            if (!url || url.substr(0, 'data:'.length) === 'data:') {
                // No need to convert to data uri if it is already in data uri.

                // This not only convenient but desired. For example,
                // IE throws a security error if data:image/svg+xml is used to render
                // an image to the canvas and an attempt is made to read out data uri.
                // Now if our image is already in data uri, there is no need to render it to the canvas
                // and so we can bypass this error.

                // Keep the async nature of the function.
                return setTimeout(function() {
                    callback(null, url);
                }, 0);
            }

            // chrome, IE10+
            var modernHandler = function(xhr, callback) {

                if (xhr.status === 200) {

                    var reader = new FileReader();

                    reader.onload = function(evt) {
                        var dataUri = evt.target.result;
                        callback(null, dataUri);
                    };

                    reader.onerror = function() {
                        callback(new Error('Failed to load image ' + url));
                    };

                    reader.readAsDataURL(xhr.response);
                } else {
                    callback(new Error('Failed to load image ' + url));
                }
            };

            var legacyHandler = function(xhr, callback) {

                var Uint8ToString = function(u8a) {
                    var CHUNK_SZ = 0x8000;
                    var c = [];
                    for (var i = 0; i < u8a.length; i += CHUNK_SZ) {
                        c.push(String.fromCharCode.apply(null, u8a.subarray(i, i + CHUNK_SZ)));
                    }
                    return c.join('');
                };

                if (xhr.status === 200) {

                    var bytes = new Uint8Array(xhr.response);

                    var suffix = (url.split('.').pop()) || 'png';
                    var map = {
                        'svg': 'svg+xml'
                    };
                    var meta = 'data:image/' + (map[suffix] || suffix) + ';base64,';
                    var b64encoded = meta + btoa(Uint8ToString(bytes));
                    callback(null, b64encoded);
                } else {
                    callback(new Error('Failed to load image ' + url));
                }
            };

            var xhr = new XMLHttpRequest();

            xhr.open('GET', url, true);
            xhr.addEventListener('error', function() {
                callback(new Error('Failed to load image ' + url));
            });

            xhr.responseType = window.FileReader ? 'blob' : 'arraybuffer';

            xhr.addEventListener('load', function() {
                if (window.FileReader) {
                    modernHandler(xhr, callback);
                } else {
                    legacyHandler(xhr, callback);
                }
            });

            xhr.send();
        }
function ( url , callback ) { if ( ! url || url . substr ( 0 , 'data:' . length ) === 'data:' ) { // No need to convert to data uri if it is already in data uri. // This not only convenient but desired. For example, // IE throws a security error if data:image/svg+xml is used to render // an image to the canvas and an attempt is made to read out data uri. // Now if our image is already in data uri, there is no need to render it to the canvas // and so we can bypass this error. // Keep the async nature of the function. return setTimeout ( function ( ) { callback ( null , url ) ; } , 0 ) ; } // chrome, IE10+ var modernHandler = function ( xhr , callback ) { if ( xhr . status === 200 ) { var reader = new FileReader ( ) ; reader . onload = function ( evt ) { var dataUri = evt . target . result ; callback ( null , dataUri ) ; } ; reader . onerror = function ( ) { callback ( new Error ( 'Failed to load image ' + url ) ) ; } ; reader . readAsDataURL ( xhr . response ) ; } else { callback ( new Error ( 'Failed to load image ' + url ) ) ; } } ; var legacyHandler = function ( xhr , callback ) { var Uint8ToString = function ( u8a ) { var CHUNK_SZ = 0x8000 ; var c = [ ] ; for ( var i = 0 ; i < u8a . length ; i += CHUNK_SZ ) { c . push ( String . fromCharCode . apply ( null , u8a . subarray ( i , i + CHUNK_SZ ) ) ) ; } return c . join ( '' ) ; } ; if ( xhr . status === 200 ) { var bytes = new Uint8Array ( xhr . response ) ; var suffix = ( url . split ( '.' ) . pop ( ) ) || 'png' ; var map = { 'svg' : 'svg+xml' } ; var meta = 'data:image/' + ( map [ suffix ] || suffix ) + ';base64,' ; var b64encoded = meta + btoa ( Uint8ToString ( bytes ) ) ; callback ( null , b64encoded ) ; } else { callback ( new Error ( 'Failed to load image ' + url ) ) ; } } ; var xhr = new XMLHttpRequest ( ) ; xhr . open ( 'GET' , url , true ) ; xhr . addEventListener ( 'error' , function ( ) { callback ( new Error ( 'Failed to load image ' + url ) ) ; } ) ; xhr . responseType = window . FileReader ? 'blob' : 'arraybuffer' ; xhr . addEventListener ( 'load' , function ( ) { if ( window . FileReader ) { modernHandler ( xhr , callback ) ; } else { legacyHandler ( xhr , callback ) ; } } ) ; xhr . send ( ) ; }
Read an image at `url` and return it as base64-encoded data uri. The mime type of the image is inferred from the `url` file extension. If data uri is provided as `url`, it is returned back unchanged. `callback` is a method with `err` as first argument and `dataUri` as second argument. Works with IE9.
Read an image at url and return it as base64 - encoded data uri . The mime type of the image is inferred from the url file extension . If data uri is provided as url it is returned back unchanged . callback is a method with err as first argument and dataUri as second argument . Works with IE9 .