提交 0c27c943 编写于 作者: J Joshua Peek

Merge pull request #78 from matthew-andrews/centralise-support-checks

Centralise the checks for blob and form data support
......@@ -92,26 +92,29 @@
return fileReaderReady(reader)
}
var blobSupport = 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})();
var support = {
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self
}
function Body() {
this.bodyUsed = false
if (blobSupport) {
if (support.blob) {
this._initBody = function(body) {
this._bodyInit = body
if (typeof body === 'string') {
this._bodyText = body
} else if ('Blob' in self && Blob.prototype.isPrototypeOf(body)) {
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body
} else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) {
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
......@@ -158,7 +161,7 @@
this._bodyInit = body
if (typeof body === 'string') {
this._bodyText = body
} else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) {
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
......@@ -173,7 +176,7 @@
}
}
if ('FormData' in self) {
if (support.formData) {
this.formData = function() {
return this.text().then(decode)
}
......@@ -278,7 +281,7 @@
}
xhr.open(self.method, self.url, true)
if ('responseType' in xhr && blobSupport) {
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob'
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册