Skip to content

Commit

Permalink
Minor formatting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
starwed committed Sep 22, 2018
1 parent 9f15cad commit 05ebc54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
9 changes: 3 additions & 6 deletions src/core/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -284,7 +282,6 @@ module.exports = {
};

//Progress function

function pro() {
var src = this.src;

Expand All @@ -304,8 +301,8 @@ module.exports = {

if (j === total && oncomplete) oncomplete();
}
//Error function

//Error function
function err() {
var src = this.src;
if (onerror)
Expand All @@ -329,7 +326,6 @@ module.exports = {
obj = null;

if (type === "audio") {

current = (typeof current === "object") ?
current : {'': current + ''};

Expand Down Expand Up @@ -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(
Expand Down
19 changes: 5 additions & 14 deletions src/core/utility.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
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();
});
};

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]
};
}
Expand All @@ -40,23 +34,20 @@ 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 );

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 );
};

0 comments on commit 05ebc54

Please sign in to comment.