Standardjs format
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
;(function () {
|
||||
|
||||
var global = typeof window === 'object'
|
||||
? window : typeof self === 'object'
|
||||
? self : this
|
||||
@@ -17,7 +16,7 @@
|
||||
var BlobBuilder = global.BlobBuilder
|
||||
|| global.WebKitBlobBuilder
|
||||
|| global.MSBlobBuilder
|
||||
|| global.MozBlobBuilder;
|
||||
|| global.MozBlobBuilder
|
||||
|
||||
global.URL = global.URL || global.webkitURL || function (href, a) {
|
||||
a = document.createElement('a')
|
||||
@@ -34,7 +33,7 @@
|
||||
var arrayBufferSupported = !!global.ArrayBuffer
|
||||
var blobBuilderSupported = BlobBuilder
|
||||
&& BlobBuilder.prototype.append
|
||||
&& BlobBuilder.prototype.getBlob;
|
||||
&& BlobBuilder.prototype.getBlob
|
||||
|
||||
try {
|
||||
// Check if Blob constructor is supported
|
||||
@@ -53,105 +52,103 @@
|
||||
function mapArrayBufferViews (ary) {
|
||||
return ary.map(function (chunk) {
|
||||
if (chunk.buffer instanceof ArrayBuffer) {
|
||||
var buf = chunk.buffer;
|
||||
var buf = chunk.buffer
|
||||
|
||||
// if this is a subarray, make a copy so we only
|
||||
// include the subarray region from the underlying buffer
|
||||
if (chunk.byteLength !== buf.byteLength) {
|
||||
var copy = new Uint8Array(chunk.byteLength);
|
||||
copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
|
||||
buf = copy.buffer;
|
||||
var copy = new Uint8Array(chunk.byteLength)
|
||||
copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength))
|
||||
buf = copy.buffer
|
||||
}
|
||||
|
||||
return buf;
|
||||
return buf
|
||||
}
|
||||
|
||||
return chunk;
|
||||
});
|
||||
return chunk
|
||||
})
|
||||
}
|
||||
|
||||
function BlobBuilderConstructor (ary, options) {
|
||||
options = options || {};
|
||||
options = options || {}
|
||||
|
||||
var bb = new BlobBuilder();
|
||||
var bb = new BlobBuilder()
|
||||
mapArrayBufferViews(ary).forEach(function (part) {
|
||||
bb.append(part);
|
||||
});
|
||||
bb.append(part)
|
||||
})
|
||||
|
||||
return options.type ? bb.getBlob(options.type) : bb.getBlob();
|
||||
};
|
||||
return options.type ? bb.getBlob(options.type) : bb.getBlob()
|
||||
}
|
||||
|
||||
function BlobConstructor (ary, options) {
|
||||
return new origBlob(mapArrayBufferViews(ary), options || {});
|
||||
};
|
||||
return new origBlob(mapArrayBufferViews(ary), options || {})
|
||||
}
|
||||
|
||||
if (global.Blob) {
|
||||
BlobBuilderConstructor.prototype = Blob.prototype;
|
||||
BlobConstructor.prototype = Blob.prototype;
|
||||
BlobBuilderConstructor.prototype = Blob.prototype
|
||||
BlobConstructor.prototype = Blob.prototype
|
||||
}
|
||||
|
||||
function FakeBlobBuilder () {
|
||||
function toUTF8Array (str) {
|
||||
var utf8 = [];
|
||||
var utf8 = []
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var charcode = str.charCodeAt(i);
|
||||
if (charcode < 0x80) utf8.push(charcode);
|
||||
var charcode = str.charCodeAt(i)
|
||||
if (charcode < 0x80) utf8.push(charcode)
|
||||
else if (charcode < 0x800) {
|
||||
utf8.push(0xc0 | (charcode >> 6),
|
||||
0x80 | (charcode & 0x3f));
|
||||
}
|
||||
else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
0x80 | (charcode & 0x3f))
|
||||
} else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
utf8.push(0xe0 | (charcode >> 12),
|
||||
0x80 | ((charcode >> 6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f));
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
// surrogate pair
|
||||
else {
|
||||
i++;
|
||||
i++
|
||||
// UTF-16 encodes 0x10000-0x10FFFF by
|
||||
// subtracting 0x10000 and splitting the
|
||||
// 20 bits of 0x0-0xFFFFF into two halves
|
||||
charcode = 0x10000 + (((charcode & 0x3ff) << 10)
|
||||
| (str.charCodeAt(i) & 0x3ff));
|
||||
| (str.charCodeAt(i) & 0x3ff))
|
||||
utf8.push(0xf0 | (charcode >> 18),
|
||||
0x80 | ((charcode >> 12) & 0x3f),
|
||||
0x80 | ((charcode >> 6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f));
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
}
|
||||
return utf8;
|
||||
return utf8
|
||||
}
|
||||
function fromUtf8Array (array) {
|
||||
var out, i, len, c;
|
||||
var char2, char3;
|
||||
var out, i, len, c
|
||||
var char2, char3
|
||||
|
||||
out = "";
|
||||
len = array.length;
|
||||
i = 0;
|
||||
out = ''
|
||||
len = array.length
|
||||
i = 0
|
||||
while (i < len) {
|
||||
c = array[i++];
|
||||
switch (c >> 4)
|
||||
{
|
||||
c = array[i++]
|
||||
switch (c >> 4) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||
// 0xxxxxxx
|
||||
out += String.fromCharCode(c);
|
||||
break;
|
||||
out += String.fromCharCode(c)
|
||||
break
|
||||
case 12: case 13:
|
||||
// 110x xxxx 10xx xxxx
|
||||
char2 = array[i++];
|
||||
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
||||
break;
|
||||
char2 = array[i++]
|
||||
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F))
|
||||
break
|
||||
case 14:
|
||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||
char2 = array[i++];
|
||||
char3 = array[i++];
|
||||
char2 = array[i++]
|
||||
char3 = array[i++]
|
||||
out += String.fromCharCode(((c & 0x0F) << 12) |
|
||||
((char2 & 0x3F) << 6) |
|
||||
((char3 & 0x3F) << 0));
|
||||
break;
|
||||
((char3 & 0x3F) << 0))
|
||||
break
|
||||
}
|
||||
}
|
||||
return out;
|
||||
return out
|
||||
}
|
||||
function isDataView (obj) {
|
||||
return obj && DataView.prototype.isPrototypeOf(obj)
|
||||
@@ -166,27 +163,27 @@
|
||||
return view
|
||||
}
|
||||
function encodeByteArray (input) {
|
||||
var byteToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
var byteToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||
|
||||
var output = [];
|
||||
var output = []
|
||||
|
||||
for (var i = 0; i < input.length; i += 3) {
|
||||
var byte1 = input[i];
|
||||
var haveByte2 = i + 1 < input.length;
|
||||
var byte2 = haveByte2 ? input[i + 1] : 0;
|
||||
var haveByte3 = i + 2 < input.length;
|
||||
var byte3 = haveByte3 ? input[i + 2] : 0;
|
||||
var byte1 = input[i]
|
||||
var haveByte2 = i + 1 < input.length
|
||||
var byte2 = haveByte2 ? input[i + 1] : 0
|
||||
var haveByte3 = i + 2 < input.length
|
||||
var byte3 = haveByte3 ? input[i + 2] : 0
|
||||
|
||||
var outByte1 = byte1 >> 2;
|
||||
var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4);
|
||||
var outByte3 = ((byte2 & 0x0F) << 2) | (byte3 >> 6);
|
||||
var outByte4 = byte3 & 0x3F;
|
||||
var outByte1 = byte1 >> 2
|
||||
var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4)
|
||||
var outByte3 = ((byte2 & 0x0F) << 2) | (byte3 >> 6)
|
||||
var outByte4 = byte3 & 0x3F
|
||||
|
||||
if (!haveByte3) {
|
||||
outByte4 = 64;
|
||||
outByte4 = 64
|
||||
|
||||
if (!haveByte2) {
|
||||
outByte3 = 64;
|
||||
outByte3 = 64
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +197,8 @@
|
||||
|
||||
var create = Object.create || function (a) {
|
||||
function c () {}
|
||||
c.prototype = a;
|
||||
return new c
|
||||
c.prototype = a
|
||||
return new c()
|
||||
}
|
||||
|
||||
if (arrayBufferSupported) {
|
||||
@@ -222,8 +219,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* Blob constructor */
|
||||
/********************************************************/
|
||||
@@ -258,8 +253,6 @@
|
||||
return '[object Blob]'
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* File constructor */
|
||||
/********************************************************/
|
||||
@@ -267,18 +260,18 @@
|
||||
opts = opts || {}
|
||||
var a = Blob.call(this, chunks, opts) || this
|
||||
a.name = name
|
||||
a.lastModifiedDate = opts.lastModified ? new Date(opts.lastModified) : new Date
|
||||
a.lastModifiedDate = opts.lastModified ? new Date(opts.lastModified) : new Date()
|
||||
a.lastModified = +a.lastModifiedDate
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
File.prototype = create(Blob.prototype);
|
||||
File.prototype.constructor = File;
|
||||
File.prototype = create(Blob.prototype)
|
||||
File.prototype.constructor = File
|
||||
|
||||
if (Object.setPrototypeOf)
|
||||
Object.setPrototypeOf(File, Blob);
|
||||
else {
|
||||
if (Object.setPrototypeOf) {
|
||||
Object.setPrototypeOf(File, Blob)
|
||||
} else {
|
||||
try { File.__proto__ = Blob } catch (e) {}
|
||||
}
|
||||
|
||||
@@ -286,13 +279,13 @@
|
||||
return '[object File]'
|
||||
}
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* FileReader constructor */
|
||||
/********************************************************/
|
||||
function FileReader () {
|
||||
if (!(this instanceof FileReader))
|
||||
if (!(this instanceof FileReader)) {
|
||||
throw new TypeError("Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function.")
|
||||
}
|
||||
|
||||
var delegate = document.createDocumentFragment()
|
||||
this.addEventListener = delegate.addEventListener
|
||||
@@ -305,8 +298,9 @@
|
||||
}
|
||||
|
||||
function _read (fr, blob, kind) {
|
||||
if (!(blob instanceof Blob))
|
||||
if (!(blob instanceof Blob)) {
|
||||
throw new TypeError("Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.")
|
||||
}
|
||||
|
||||
fr.result = ''
|
||||
|
||||
@@ -345,7 +339,6 @@
|
||||
|
||||
FileReader.prototype.abort = function () {}
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* URL */
|
||||
/********************************************************/
|
||||
@@ -415,7 +408,7 @@
|
||||
'opts = opts || {};' +
|
||||
'super(chunks, opts || {});' +
|
||||
'this.name = name;' +
|
||||
'this.lastModifiedDate = opts.lastModified ? new Date(opts.lastModified) : new Date;' +
|
||||
'this.lastModifiedDate = opts.lastModified ? new Date(opts.lastModified) : new Date();' +
|
||||
'this.lastModified = +this.lastModifiedDate;' +
|
||||
'}};' +
|
||||
'return new File([], ""), File'
|
||||
@@ -424,7 +417,7 @@
|
||||
} catch (e) {
|
||||
var klass = function (b, d, c) {
|
||||
var blob = new Blob(b, c)
|
||||
var t = c && void 0 !== c.lastModified ? new Date(c.lastModified) : new Date
|
||||
var t = c && void 0 !== c.lastModified ? new Date(c.lastModified) : new Date()
|
||||
|
||||
blob.name = d
|
||||
blob.lastModifiedDate = t
|
||||
@@ -433,8 +426,9 @@
|
||||
return '[object File]'
|
||||
}
|
||||
|
||||
if (strTag)
|
||||
if (strTag) {
|
||||
blob[strTag] = 'File'
|
||||
}
|
||||
|
||||
return blob
|
||||
}
|
||||
@@ -448,9 +442,8 @@
|
||||
global.Blob = blobSupportsArrayBufferView ? global.Blob : BlobConstructor
|
||||
} else if (blobBuilderSupported) {
|
||||
fixFileAndXHR()
|
||||
global.Blob = BlobBuilderConstructor;
|
||||
global.Blob = BlobBuilderConstructor
|
||||
} else {
|
||||
FakeBlobBuilder()
|
||||
}
|
||||
|
||||
})();
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user