From 05ebc540801eb5265faf972531d47ffcc767cb6c Mon Sep 17 00:00:00 2001 From: Tim Martin Date: Sat, 22 Sep 2018 14:44:44 -0400 Subject: [PATCH] Minor formatting tweaks --- src/core/loader.js | 9 +++------ src/core/utility.js | 19 +++++-------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/core/loader.js b/src/core/loader.js index 5096b373..0d60b44d 100644 --- a/src/core/loader.js +++ b/src/core/loader.js @@ -257,14 +257,12 @@ module.exports = { isAsset = function(a) { return Crafty.asset(a) || null; }, - isSupportedAudio = function(f) { return Crafty.support.audio && Crafty.audio.supports( Utility.fileTypeOf( f ).type ); }, - isValidImage = function(f) { return -1 < Crafty.imageWhitelist.indexOf( @@ -284,7 +282,6 @@ module.exports = { }; //Progress function - function pro() { var src = this.src; @@ -304,8 +301,8 @@ module.exports = { if (j === total && oncomplete) oncomplete(); } - //Error function + //Error function function err() { var src = this.src; if (onerror) @@ -329,7 +326,6 @@ module.exports = { obj = null; if (type === "audio") { - current = (typeof current === "object") ? current : {'': current + ''}; @@ -362,7 +358,8 @@ module.exports = { if (!isAsset( fileUrl ) && isValidImage( asset )) { - obj = new Image(); fileUrl = shortURLOf( fileUrl ); + obj = new Image(); + fileUrl = shortURLOf( fileUrl ); if (type === "sprites") Crafty.sprite( diff --git a/src/core/utility.js b/src/core/utility.js index 1700b1f8..f7acf2b1 100644 --- a/src/core/utility.js +++ b/src/core/utility.js @@ -1,17 +1,12 @@ exports.blobOf = function blobOf(URI) { var XHR = new XMLHttpRequest(); - XHR.responseType = 'blob'; - XHR.open('GET', URI); return new Promise(function (resolve, reject) { - XHR.onload = function () { resolve( this.response ); }; - XHR.onerror = reject; - XHR.send(); }); }; @@ -19,19 +14,18 @@ exports.blobOf = function blobOf(URI) { var DataURI = /^data:(.+?\/(.+?))?(;base64)?,(\S+)/; exports.fileTypeOf = function fileTypeOf(URI) { - var schema = /^(?:(\w+):)?.+?(?:\.(\w+))?$/.exec( URI ); switch ( schema[1] ) { - case 'data': return { + case 'data': return { schema: 'data', type: DataURI.exec( URI )[2] }; - case 'blob': return exports.blobOf( URI ).then(function (blob) { + case 'blob': return exports.blobOf( URI ).then(function (blob) { return { schema: 'blob', type: blob.type }; }); - default: return { + default: return { schema: schema[1], type: schema[2] }; } @@ -40,15 +34,12 @@ exports.fileTypeOf = function fileTypeOf(URI) { var BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; exports.toBlob = function toBlob(dataURI) { - dataURI = DataURI.exec( dataURI ); var type = dataURI[1], base64 = dataURI[3], data = dataURI[4]; - data = base64 ? window.atob( data ) : data; var aBuffer = new ArrayBuffer( data.length ); - var uBuffer = new Uint8Array( aBuffer ); for (var i = 0; data[i]; i++) uBuffer[i] = data.charCodeAt( i ); @@ -56,7 +47,7 @@ exports.toBlob = function toBlob(dataURI) { if (! BlobBuilder) return new window.Blob([aBuffer], {type: type}); - var builder = new BlobBuilder(); builder.append( aBuffer ); - + var builder = new BlobBuilder(); + builder.append( aBuffer ); return builder.getBlob( type ); };