vue-resource
Advanced tools
Comparing version 0.9.3 to 1.0.0
/*! | ||
* vue-resource v0.9.3 | ||
* vue-resource v1.0.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -10,179 +10,7 @@ * Released under the MIT License. | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
* Promise adapter. | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
var PromiseObj = window.Promise; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
@@ -255,5 +83,9 @@ | ||
var debug = false; | ||
var util = {}; | ||
var array = []; | ||
/** | ||
* Utility functions. | ||
*/ | ||
var debug = false;var util = {};var slice = [].slice; | ||
function Util (Vue) { | ||
@@ -284,2 +116,10 @@ util = Vue.util; | ||
function toLower(str) { | ||
return str ? str.toLowerCase() : ''; | ||
} | ||
function toUpper(str) { | ||
return str ? str.toUpperCase() : ''; | ||
} | ||
var isArray = Array.isArray; | ||
@@ -307,2 +147,6 @@ | ||
function isBlob(obj) { | ||
return typeof Blob !== 'undefined' && obj instanceof Blob; | ||
} | ||
function isFormData(obj) { | ||
@@ -338,3 +182,3 @@ return typeof FormData !== 'undefined' && obj instanceof FormData; | ||
if (typeof obj.length == 'number') { | ||
if (obj && typeof obj.length == 'number') { | ||
for (i = 0; i < obj.length; i++) { | ||
@@ -358,3 +202,3 @@ iterator.call(obj[i], obj[i], i); | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -370,3 +214,3 @@ args.forEach(function (source) { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -387,3 +231,3 @@ args.forEach(function (source) { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -413,2 +257,6 @@ args.forEach(function (source) { | ||
/** | ||
* Root Prefix Transform. | ||
*/ | ||
function root (options, next) { | ||
@@ -425,2 +273,6 @@ | ||
/** | ||
* Query Parameter Transform. | ||
*/ | ||
function query (options, next) { | ||
@@ -601,2 +453,6 @@ | ||
/** | ||
* URL Template (RFC 6570) Transform. | ||
*/ | ||
function template (options) { | ||
@@ -742,2 +598,6 @@ | ||
/** | ||
* XDomain client (Internet Explorer). | ||
*/ | ||
function xdrClient (request) { | ||
@@ -771,2 +631,6 @@ return new Promise$1(function (resolve) { | ||
/** | ||
* CORS Interceptor. | ||
*/ | ||
var ORIGIN_URL = Url.parse(location.href); | ||
@@ -800,2 +664,6 @@ var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest(); | ||
/** | ||
* Body Interceptor. | ||
*/ | ||
function body (request, next) { | ||
@@ -805,7 +673,7 @@ | ||
request.body = Url.params(request.body); | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); | ||
} | ||
if (isFormData(request.body)) { | ||
delete request.headers['Content-Type']; | ||
request.headers.delete('Content-Type'); | ||
} | ||
@@ -819,17 +687,35 @@ | ||
var contentType = response.headers['Content-Type']; | ||
Object.defineProperty(response, 'data', { | ||
get: function () { | ||
return this.body; | ||
}, | ||
set: function (body) { | ||
this.body = body; | ||
} | ||
}); | ||
if (isString(contentType) && contentType.indexOf('application/json') === 0) { | ||
return response.bodyText ? when(response.text(), function (text) { | ||
try { | ||
response.data = response.json(); | ||
} catch (e) { | ||
response.data = null; | ||
var type = response.headers.get('Content-Type'); | ||
if (isString(type) && type.indexOf('application/json') === 0) { | ||
try { | ||
response.body = JSON.parse(text); | ||
} catch (e) { | ||
response.body = null; | ||
} | ||
} else { | ||
response.body = text; | ||
} | ||
} else { | ||
response.data = response.text(); | ||
} | ||
return response; | ||
}) : response; | ||
}); | ||
} | ||
/** | ||
* JSONP client. | ||
*/ | ||
function jsonpClient (request) { | ||
@@ -877,2 +763,6 @@ return new Promise$1(function (resolve) { | ||
/** | ||
* JSONP Interceptor. | ||
*/ | ||
function jsonp (request, next) { | ||
@@ -887,3 +777,9 @@ | ||
if (request.method == 'JSONP') { | ||
response.data = response.json(); | ||
return when(response.json(), function (json) { | ||
response.body = json; | ||
return response; | ||
}); | ||
} | ||
@@ -893,2 +789,6 @@ }); | ||
/** | ||
* Before Interceptor. | ||
*/ | ||
function before (request, next) { | ||
@@ -910,3 +810,3 @@ | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.headers.set('X-HTTP-Method-Override', request.method); | ||
request.method = 'POST'; | ||
@@ -918,7 +818,16 @@ } | ||
/** | ||
* Header Interceptor. | ||
*/ | ||
function header (request, next) { | ||
request.method = request.method.toUpperCase(); | ||
request.headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers); | ||
var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]); | ||
each(headers, function (value, name) { | ||
if (!request.headers.has(name)) { | ||
request.headers.set(name, value); | ||
} | ||
}); | ||
next(); | ||
@@ -947,2 +856,6 @@ } | ||
/** | ||
* XMLHttp client. | ||
*/ | ||
function xhrClient (request) { | ||
@@ -956,6 +869,9 @@ return new Promise$1(function (resolve) { | ||
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText), | ||
headers: parseHeaders(xhr.getAllResponseHeaders()) | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) | ||
}); | ||
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) { | ||
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); | ||
}); | ||
resolve(response); | ||
@@ -981,2 +897,6 @@ }; | ||
if ('responseType' in xhr) { | ||
xhr.responseType = 'blob'; | ||
} | ||
if (request.credentials === true) { | ||
@@ -986,4 +906,4 @@ xhr.withCredentials = true; | ||
each(request.headers || {}, function (value, header) { | ||
xhr.setRequestHeader(header, value); | ||
request.headers.forEach(function (value, name) { | ||
xhr.setRequestHeader(name, value); | ||
}); | ||
@@ -995,31 +915,6 @@ | ||
function parseHeaders(str) { | ||
/** | ||
* Base client. | ||
*/ | ||
var headers = {}, | ||
value, | ||
name, | ||
i; | ||
each(trim(str).split('\n'), function (row) { | ||
i = row.indexOf(':'); | ||
name = trim(row.slice(0, i)); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
} | ||
function Client (context) { | ||
@@ -1096,2 +991,76 @@ | ||
/** | ||
* HTTP Headers. | ||
*/ | ||
var Headers = function () { | ||
function Headers(headers) { | ||
var _this = this; | ||
classCallCheck(this, Headers); | ||
this.map = {}; | ||
each(headers, function (value, name) { | ||
return _this.append(name, value); | ||
}); | ||
} | ||
Headers.prototype.has = function has(name) { | ||
return this.map.hasOwnProperty(normalizeName(name)); | ||
}; | ||
Headers.prototype.get = function get(name) { | ||
var list = this.map[normalizeName(name)]; | ||
return list ? list[0] : null; | ||
}; | ||
Headers.prototype.getAll = function getAll(name) { | ||
return this.map[normalizeName(name)] || []; | ||
}; | ||
Headers.prototype.set = function set(name, value) { | ||
this.map[normalizeName(name)] = [trim(value)]; | ||
}; | ||
Headers.prototype.append = function append(name, value) { | ||
var list = this.map[normalizeName(name)]; | ||
if (!list) { | ||
list = this.map[normalizeName(name)] = []; | ||
} | ||
list.push(trim(value)); | ||
}; | ||
Headers.prototype.delete = function _delete(name) { | ||
delete this.map[normalizeName(name)]; | ||
}; | ||
Headers.prototype.forEach = function forEach(callback, thisArg) { | ||
var _this2 = this; | ||
each(this.map, function (list, name) { | ||
each(list, function (value) { | ||
return callback.call(thisArg, value, name, _this2); | ||
}); | ||
}); | ||
}; | ||
return Headers; | ||
}(); | ||
function normalizeName(name) { | ||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { | ||
throw new TypeError('Invalid character in header field name'); | ||
} | ||
return toLower(trim(name)); | ||
} | ||
/** | ||
* HTTP Response. | ||
@@ -1110,19 +1079,33 @@ */ | ||
this.url = url; | ||
this.body = body; | ||
this.headers = headers || {}; | ||
this.ok = status >= 200 && status < 300; | ||
this.status = status || 0; | ||
this.statusText = statusText || ''; | ||
this.ok = status >= 200 && status < 300; | ||
this.headers = new Headers(headers); | ||
this.body = body; | ||
if (isString(body)) { | ||
this.bodyText = body; | ||
} else if (isBlob(body)) { | ||
this.bodyBlob = body; | ||
if (isBlobText(body)) { | ||
this.bodyText = blobText(body); | ||
} | ||
} | ||
} | ||
Response.prototype.text = function text() { | ||
return this.body; | ||
Response.prototype.blob = function blob() { | ||
return when(this.bodyBlob); | ||
}; | ||
Response.prototype.blob = function blob() { | ||
return new Blob([this.body]); | ||
Response.prototype.text = function text() { | ||
return when(this.bodyText); | ||
}; | ||
Response.prototype.json = function json() { | ||
return JSON.parse(this.body); | ||
return when(this.text(), function (text) { | ||
return JSON.parse(text); | ||
}); | ||
}; | ||
@@ -1133,2 +1116,22 @@ | ||
function blobText(body) { | ||
return new Promise$1(function (resolve) { | ||
var reader = new FileReader(); | ||
reader.readAsText(body); | ||
reader.onload = function () { | ||
resolve(reader.result); | ||
}; | ||
}); | ||
} | ||
function isBlobText(body) { | ||
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; | ||
} | ||
/** | ||
* HTTP Request. | ||
*/ | ||
var Request = function () { | ||
@@ -1139,8 +1142,9 @@ function Request(options) { | ||
this.method = 'GET'; | ||
this.body = null; | ||
this.params = {}; | ||
this.headers = {}; | ||
assign(this, options); | ||
assign(this, options, { | ||
method: toUpper(options.method || 'GET'), | ||
headers: new Headers(options.headers) | ||
}); | ||
} | ||
@@ -1222,2 +1226,182 @@ | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
/** | ||
* Service for interacting with RESTful services. | ||
*/ | ||
function Resource(url, params, actions, options) { | ||
@@ -1232,3 +1416,3 @@ | ||
action = merge({ url: url, params: params || {} }, options, action); | ||
action = merge({ url: url, params: assign({}, params) }, options, action); | ||
@@ -1294,2 +1478,6 @@ resource[name] = function () { | ||
/** | ||
* Install plugin. | ||
*/ | ||
function plugin(Vue) { | ||
@@ -1341,6 +1529,13 @@ | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin); | ||
if (typeof window !== 'undefined') { | ||
if (!window.Promise) { | ||
window.Promise = Promise$2; | ||
} | ||
if (window.Vue) { | ||
window.Vue.use(plugin); | ||
} | ||
} | ||
module.exports = plugin; |
/*! | ||
* vue-resource v0.9.3 | ||
* vue-resource v1.0.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -8,179 +8,7 @@ * Released under the MIT License. | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
* Promise adapter. | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
var PromiseObj = window.Promise; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
var PromiseObj = window.Promise || Promise$2; | ||
function Promise$1(executor, context) { | ||
@@ -253,5 +81,9 @@ | ||
var debug = false; | ||
var util = {}; | ||
var array = []; | ||
/** | ||
* Utility functions. | ||
*/ | ||
var debug = false;var util = {};var slice = [].slice; | ||
function Util (Vue) { | ||
@@ -282,2 +114,10 @@ util = Vue.util; | ||
function toLower(str) { | ||
return str ? str.toLowerCase() : ''; | ||
} | ||
function toUpper(str) { | ||
return str ? str.toUpperCase() : ''; | ||
} | ||
var isArray = Array.isArray; | ||
@@ -305,2 +145,6 @@ | ||
function isBlob(obj) { | ||
return typeof Blob !== 'undefined' && obj instanceof Blob; | ||
} | ||
function isFormData(obj) { | ||
@@ -336,3 +180,3 @@ return typeof FormData !== 'undefined' && obj instanceof FormData; | ||
if (typeof obj.length == 'number') { | ||
if (obj && typeof obj.length == 'number') { | ||
for (i = 0; i < obj.length; i++) { | ||
@@ -356,3 +200,3 @@ iterator.call(obj[i], obj[i], i); | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -368,3 +212,3 @@ args.forEach(function (source) { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -385,3 +229,3 @@ args.forEach(function (source) { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -411,2 +255,6 @@ args.forEach(function (source) { | ||
/** | ||
* Root Prefix Transform. | ||
*/ | ||
function root (options, next) { | ||
@@ -423,2 +271,6 @@ | ||
/** | ||
* Query Parameter Transform. | ||
*/ | ||
function query (options, next) { | ||
@@ -599,2 +451,6 @@ | ||
/** | ||
* URL Template (RFC 6570) Transform. | ||
*/ | ||
function template (options) { | ||
@@ -740,2 +596,6 @@ | ||
/** | ||
* XDomain client (Internet Explorer). | ||
*/ | ||
function xdrClient (request) { | ||
@@ -769,2 +629,6 @@ return new Promise$1(function (resolve) { | ||
/** | ||
* CORS Interceptor. | ||
*/ | ||
var ORIGIN_URL = Url.parse(location.href); | ||
@@ -798,2 +662,6 @@ var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest(); | ||
/** | ||
* Body Interceptor. | ||
*/ | ||
function body (request, next) { | ||
@@ -803,7 +671,7 @@ | ||
request.body = Url.params(request.body); | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); | ||
} | ||
if (isFormData(request.body)) { | ||
delete request.headers['Content-Type']; | ||
request.headers.delete('Content-Type'); | ||
} | ||
@@ -817,17 +685,35 @@ | ||
var contentType = response.headers['Content-Type']; | ||
Object.defineProperty(response, 'data', { | ||
get: function () { | ||
return this.body; | ||
}, | ||
set: function (body) { | ||
this.body = body; | ||
} | ||
}); | ||
if (isString(contentType) && contentType.indexOf('application/json') === 0) { | ||
return response.bodyText ? when(response.text(), function (text) { | ||
try { | ||
response.data = response.json(); | ||
} catch (e) { | ||
response.data = null; | ||
var type = response.headers.get('Content-Type'); | ||
if (isString(type) && type.indexOf('application/json') === 0) { | ||
try { | ||
response.body = JSON.parse(text); | ||
} catch (e) { | ||
response.body = null; | ||
} | ||
} else { | ||
response.body = text; | ||
} | ||
} else { | ||
response.data = response.text(); | ||
} | ||
return response; | ||
}) : response; | ||
}); | ||
} | ||
/** | ||
* JSONP client. | ||
*/ | ||
function jsonpClient (request) { | ||
@@ -875,2 +761,6 @@ return new Promise$1(function (resolve) { | ||
/** | ||
* JSONP Interceptor. | ||
*/ | ||
function jsonp (request, next) { | ||
@@ -885,3 +775,9 @@ | ||
if (request.method == 'JSONP') { | ||
response.data = response.json(); | ||
return when(response.json(), function (json) { | ||
response.body = json; | ||
return response; | ||
}); | ||
} | ||
@@ -891,2 +787,6 @@ }); | ||
/** | ||
* Before Interceptor. | ||
*/ | ||
function before (request, next) { | ||
@@ -908,3 +808,3 @@ | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.headers.set('X-HTTP-Method-Override', request.method); | ||
request.method = 'POST'; | ||
@@ -916,7 +816,16 @@ } | ||
/** | ||
* Header Interceptor. | ||
*/ | ||
function header (request, next) { | ||
request.method = request.method.toUpperCase(); | ||
request.headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers); | ||
var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]); | ||
each(headers, function (value, name) { | ||
if (!request.headers.has(name)) { | ||
request.headers.set(name, value); | ||
} | ||
}); | ||
next(); | ||
@@ -945,2 +854,6 @@ } | ||
/** | ||
* XMLHttp client. | ||
*/ | ||
function xhrClient (request) { | ||
@@ -954,6 +867,9 @@ return new Promise$1(function (resolve) { | ||
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText), | ||
headers: parseHeaders(xhr.getAllResponseHeaders()) | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) | ||
}); | ||
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) { | ||
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); | ||
}); | ||
resolve(response); | ||
@@ -979,2 +895,6 @@ }; | ||
if ('responseType' in xhr) { | ||
xhr.responseType = 'blob'; | ||
} | ||
if (request.credentials === true) { | ||
@@ -984,4 +904,4 @@ xhr.withCredentials = true; | ||
each(request.headers || {}, function (value, header) { | ||
xhr.setRequestHeader(header, value); | ||
request.headers.forEach(function (value, name) { | ||
xhr.setRequestHeader(name, value); | ||
}); | ||
@@ -993,31 +913,6 @@ | ||
function parseHeaders(str) { | ||
/** | ||
* Base client. | ||
*/ | ||
var headers = {}, | ||
value, | ||
name, | ||
i; | ||
each(trim(str).split('\n'), function (row) { | ||
i = row.indexOf(':'); | ||
name = trim(row.slice(0, i)); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
} | ||
function Client (context) { | ||
@@ -1094,2 +989,76 @@ | ||
/** | ||
* HTTP Headers. | ||
*/ | ||
var Headers = function () { | ||
function Headers(headers) { | ||
var _this = this; | ||
classCallCheck(this, Headers); | ||
this.map = {}; | ||
each(headers, function (value, name) { | ||
return _this.append(name, value); | ||
}); | ||
} | ||
Headers.prototype.has = function has(name) { | ||
return this.map.hasOwnProperty(normalizeName(name)); | ||
}; | ||
Headers.prototype.get = function get(name) { | ||
var list = this.map[normalizeName(name)]; | ||
return list ? list[0] : null; | ||
}; | ||
Headers.prototype.getAll = function getAll(name) { | ||
return this.map[normalizeName(name)] || []; | ||
}; | ||
Headers.prototype.set = function set(name, value) { | ||
this.map[normalizeName(name)] = [trim(value)]; | ||
}; | ||
Headers.prototype.append = function append(name, value) { | ||
var list = this.map[normalizeName(name)]; | ||
if (!list) { | ||
list = this.map[normalizeName(name)] = []; | ||
} | ||
list.push(trim(value)); | ||
}; | ||
Headers.prototype.delete = function _delete(name) { | ||
delete this.map[normalizeName(name)]; | ||
}; | ||
Headers.prototype.forEach = function forEach(callback, thisArg) { | ||
var _this2 = this; | ||
each(this.map, function (list, name) { | ||
each(list, function (value) { | ||
return callback.call(thisArg, value, name, _this2); | ||
}); | ||
}); | ||
}; | ||
return Headers; | ||
}(); | ||
function normalizeName(name) { | ||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { | ||
throw new TypeError('Invalid character in header field name'); | ||
} | ||
return toLower(trim(name)); | ||
} | ||
/** | ||
* HTTP Response. | ||
@@ -1108,19 +1077,33 @@ */ | ||
this.url = url; | ||
this.body = body; | ||
this.headers = headers || {}; | ||
this.ok = status >= 200 && status < 300; | ||
this.status = status || 0; | ||
this.statusText = statusText || ''; | ||
this.ok = status >= 200 && status < 300; | ||
this.headers = new Headers(headers); | ||
this.body = body; | ||
if (isString(body)) { | ||
this.bodyText = body; | ||
} else if (isBlob(body)) { | ||
this.bodyBlob = body; | ||
if (isBlobText(body)) { | ||
this.bodyText = blobText(body); | ||
} | ||
} | ||
} | ||
Response.prototype.text = function text() { | ||
return this.body; | ||
Response.prototype.blob = function blob() { | ||
return when(this.bodyBlob); | ||
}; | ||
Response.prototype.blob = function blob() { | ||
return new Blob([this.body]); | ||
Response.prototype.text = function text() { | ||
return when(this.bodyText); | ||
}; | ||
Response.prototype.json = function json() { | ||
return JSON.parse(this.body); | ||
return when(this.text(), function (text) { | ||
return JSON.parse(text); | ||
}); | ||
}; | ||
@@ -1131,2 +1114,22 @@ | ||
function blobText(body) { | ||
return new Promise$1(function (resolve) { | ||
var reader = new FileReader(); | ||
reader.readAsText(body); | ||
reader.onload = function () { | ||
resolve(reader.result); | ||
}; | ||
}); | ||
} | ||
function isBlobText(body) { | ||
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; | ||
} | ||
/** | ||
* HTTP Request. | ||
*/ | ||
var Request = function () { | ||
@@ -1137,8 +1140,9 @@ function Request(options) { | ||
this.method = 'GET'; | ||
this.body = null; | ||
this.params = {}; | ||
this.headers = {}; | ||
assign(this, options); | ||
assign(this, options, { | ||
method: toUpper(options.method || 'GET'), | ||
headers: new Headers(options.headers) | ||
}); | ||
} | ||
@@ -1220,2 +1224,182 @@ | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
function Promise$2(executor) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
var promise = this; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
var called = false; | ||
try { | ||
var then = x && x['then']; | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
/** | ||
* Service for interacting with RESTful services. | ||
*/ | ||
function Resource(url, params, actions, options) { | ||
@@ -1230,3 +1414,3 @@ | ||
action = merge({ url: url, params: params || {} }, options, action); | ||
action = merge({ url: url, params: assign({}, params) }, options, action); | ||
@@ -1292,2 +1476,6 @@ resource[name] = function () { | ||
/** | ||
* Install plugin. | ||
*/ | ||
function plugin(Vue) { | ||
@@ -1339,4 +1527,11 @@ | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin); | ||
if (typeof window !== 'undefined') { | ||
if (!window.Promise) { | ||
window.Promise = Promise$2; | ||
} | ||
if (window.Vue) { | ||
window.Vue.use(plugin); | ||
} | ||
} | ||
@@ -1343,0 +1538,0 @@ |
/*! | ||
* vue-resource v0.9.3 | ||
* vue-resource v1.0.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -11,1309 +11,1504 @@ * Released under the MIT License. | ||
(global.VueResource = factory()); | ||
}(this, function () { 'use strict'; | ||
}(this, (function () { 'use strict'; | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
/** | ||
* Promise adapter. | ||
*/ | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
var PromiseObj = window.Promise; | ||
function Promise$2(executor) { | ||
function Promise$1(executor, context) { | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
var promise = this; | ||
this.context = context; | ||
} | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
var p = Promise$1.prototype; | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
p.then = function (fulfilled, rejected) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
var p$1 = Promise$2.prototype; | ||
return new Promise$1(this.promise.then(fulfilled, rejected), this.context); | ||
}; | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
p.catch = function (rejected) { | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
var called = false; | ||
return new Promise$1(this.promise.catch(rejected), this.context); | ||
}; | ||
try { | ||
var then = x && x['then']; | ||
p.finally = function (callback) { | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
/** | ||
* Utility functions. | ||
*/ | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
var debug = false;var util = {};var slice = [].slice; | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
function Util (Vue) { | ||
util = Vue.util; | ||
debug = Vue.config.debug || !Vue.config.silent; | ||
} | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
function warn(msg) { | ||
if (typeof console !== 'undefined' && debug) { | ||
console.warn('[VueResource warn]: ' + msg); | ||
} | ||
} | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
function error(msg) { | ||
if (typeof console !== 'undefined') { | ||
console.error(msg); | ||
} | ||
} | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
function nextTick(cb, ctx) { | ||
return util.nextTick(cb, ctx); | ||
} | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
function trim(str) { | ||
return str.replace(/^\s*|\s*$/g, ''); | ||
} | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
function toLower(str) { | ||
return str ? str.toLowerCase() : ''; | ||
} | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
function toUpper(str) { | ||
return str ? str.toUpperCase() : ''; | ||
} | ||
var PromiseObj = window.Promise || Promise$2; | ||
var isArray = Array.isArray; | ||
function Promise$1(executor, context) { | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
} | ||
if (executor instanceof PromiseObj) { | ||
this.promise = executor; | ||
} else { | ||
this.promise = new PromiseObj(executor.bind(context)); | ||
} | ||
function isBoolean(val) { | ||
return val === true || val === false; | ||
} | ||
this.context = context; | ||
} | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
} | ||
Promise$1.all = function (iterable, context) { | ||
return new Promise$1(PromiseObj.all(iterable), context); | ||
}; | ||
function isObject(obj) { | ||
return obj !== null && typeof obj === 'object'; | ||
} | ||
Promise$1.resolve = function (value, context) { | ||
return new Promise$1(PromiseObj.resolve(value), context); | ||
}; | ||
function isPlainObject(obj) { | ||
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; | ||
} | ||
Promise$1.reject = function (reason, context) { | ||
return new Promise$1(PromiseObj.reject(reason), context); | ||
}; | ||
function isBlob(obj) { | ||
return typeof Blob !== 'undefined' && obj instanceof Blob; | ||
} | ||
Promise$1.race = function (iterable, context) { | ||
return new Promise$1(PromiseObj.race(iterable), context); | ||
}; | ||
function isFormData(obj) { | ||
return typeof FormData !== 'undefined' && obj instanceof FormData; | ||
} | ||
var p = Promise$1.prototype; | ||
function when(value, fulfilled, rejected) { | ||
p.bind = function (context) { | ||
this.context = context; | ||
return this; | ||
}; | ||
var promise = Promise$1.resolve(value); | ||
p.then = function (fulfilled, rejected) { | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
if (fulfilled && fulfilled.bind && this.context) { | ||
fulfilled = fulfilled.bind(this.context); | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
function options(fn, obj, opts) { | ||
return new Promise$1(this.promise.then(fulfilled, rejected), this.context); | ||
}; | ||
opts = opts || {}; | ||
p.catch = function (rejected) { | ||
if (isFunction(opts)) { | ||
opts = opts.call(obj); | ||
} | ||
if (rejected && rejected.bind && this.context) { | ||
rejected = rejected.bind(this.context); | ||
} | ||
return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts }); | ||
} | ||
return new Promise$1(this.promise.catch(rejected), this.context); | ||
}; | ||
function each(obj, iterator) { | ||
p.finally = function (callback) { | ||
var i, key; | ||
return this.then(function (value) { | ||
callback.call(this); | ||
return value; | ||
}, function (reason) { | ||
callback.call(this); | ||
return PromiseObj.reject(reason); | ||
}); | ||
}; | ||
if (obj && typeof obj.length == 'number') { | ||
for (i = 0; i < obj.length; i++) { | ||
iterator.call(obj[i], obj[i], i); | ||
} | ||
} else if (isObject(obj)) { | ||
for (key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
iterator.call(obj[key], obj[key], key); | ||
} | ||
} | ||
} | ||
var debug = false; | ||
var util = {}; | ||
var array = []; | ||
function Util (Vue) { | ||
util = Vue.util; | ||
debug = Vue.config.debug || !Vue.config.silent; | ||
} | ||
return obj; | ||
} | ||
function warn(msg) { | ||
if (typeof console !== 'undefined' && debug) { | ||
console.warn('[VueResource warn]: ' + msg); | ||
} | ||
} | ||
var assign = Object.assign || _assign; | ||
function error(msg) { | ||
if (typeof console !== 'undefined') { | ||
console.error(msg); | ||
} | ||
} | ||
function merge(target) { | ||
function nextTick(cb, ctx) { | ||
return util.nextTick(cb, ctx); | ||
} | ||
var args = slice.call(arguments, 1); | ||
function trim(str) { | ||
return str.replace(/^\s*|\s*$/g, ''); | ||
} | ||
args.forEach(function (source) { | ||
_merge(target, source, true); | ||
}); | ||
var isArray = Array.isArray; | ||
return target; | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
} | ||
function defaults(target) { | ||
function isBoolean(val) { | ||
return val === true || val === false; | ||
} | ||
var args = slice.call(arguments, 1); | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
} | ||
args.forEach(function (source) { | ||
function isObject(obj) { | ||
return obj !== null && typeof obj === 'object'; | ||
} | ||
for (var key in source) { | ||
if (target[key] === undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
}); | ||
function isPlainObject(obj) { | ||
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; | ||
} | ||
return target; | ||
} | ||
function isFormData(obj) { | ||
return typeof FormData !== 'undefined' && obj instanceof FormData; | ||
} | ||
function _assign(target) { | ||
function when(value, fulfilled, rejected) { | ||
var args = slice.call(arguments, 1); | ||
var promise = Promise$1.resolve(value); | ||
args.forEach(function (source) { | ||
_merge(target, source); | ||
}); | ||
if (arguments.length < 2) { | ||
return promise; | ||
} | ||
return target; | ||
} | ||
return promise.then(fulfilled, rejected); | ||
} | ||
function _merge(target, source, deep) { | ||
for (var key in source) { | ||
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { | ||
if (isPlainObject(source[key]) && !isPlainObject(target[key])) { | ||
target[key] = {}; | ||
} | ||
if (isArray(source[key]) && !isArray(target[key])) { | ||
target[key] = []; | ||
} | ||
_merge(target[key], source[key], deep); | ||
} else if (source[key] !== undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function options(fn, obj, opts) { | ||
/** | ||
* Root Prefix Transform. | ||
*/ | ||
opts = opts || {}; | ||
function root (options, next) { | ||
if (isFunction(opts)) { | ||
opts = opts.call(obj); | ||
} | ||
var url = next(options); | ||
return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts }); | ||
} | ||
if (isString(options.root) && !url.match(/^(https?:)?\//)) { | ||
url = options.root + '/' + url; | ||
} | ||
function each(obj, iterator) { | ||
return url; | ||
} | ||
var i, key; | ||
/** | ||
* Query Parameter Transform. | ||
*/ | ||
if (typeof obj.length == 'number') { | ||
for (i = 0; i < obj.length; i++) { | ||
iterator.call(obj[i], obj[i], i); | ||
} | ||
} else if (isObject(obj)) { | ||
for (key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
iterator.call(obj[key], obj[key], key); | ||
} | ||
} | ||
} | ||
function query (options, next) { | ||
return obj; | ||
} | ||
var urlParams = Object.keys(Url.options.params), | ||
query = {}, | ||
url = next(options); | ||
var assign = Object.assign || _assign; | ||
each(options.params, function (value, key) { | ||
if (urlParams.indexOf(key) === -1) { | ||
query[key] = value; | ||
} | ||
}); | ||
function merge(target) { | ||
query = Url.params(query); | ||
var args = array.slice.call(arguments, 1); | ||
if (query) { | ||
url += (url.indexOf('?') == -1 ? '?' : '&') + query; | ||
} | ||
args.forEach(function (source) { | ||
_merge(target, source, true); | ||
}); | ||
return url; | ||
} | ||
return target; | ||
} | ||
/** | ||
* URL Template v2.0.6 (https://github.com/bramstein/url-template) | ||
*/ | ||
function defaults(target) { | ||
function expand(url, params, variables) { | ||
var args = array.slice.call(arguments, 1); | ||
var tmpl = parse(url), | ||
expanded = tmpl.expand(params); | ||
args.forEach(function (source) { | ||
if (variables) { | ||
variables.push.apply(variables, tmpl.vars); | ||
} | ||
for (var key in source) { | ||
if (target[key] === undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
}); | ||
return expanded; | ||
} | ||
return target; | ||
} | ||
function parse(template) { | ||
function _assign(target) { | ||
var operators = ['+', '#', '.', '/', ';', '?', '&'], | ||
variables = []; | ||
var args = array.slice.call(arguments, 1); | ||
return { | ||
vars: variables, | ||
expand: function (context) { | ||
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { | ||
if (expression) { | ||
args.forEach(function (source) { | ||
_merge(target, source); | ||
}); | ||
var operator = null, | ||
values = []; | ||
return target; | ||
} | ||
if (operators.indexOf(expression.charAt(0)) !== -1) { | ||
operator = expression.charAt(0); | ||
expression = expression.substr(1); | ||
} | ||
function _merge(target, source, deep) { | ||
for (var key in source) { | ||
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { | ||
if (isPlainObject(source[key]) && !isPlainObject(target[key])) { | ||
target[key] = {}; | ||
} | ||
if (isArray(source[key]) && !isArray(target[key])) { | ||
target[key] = []; | ||
} | ||
_merge(target[key], source[key], deep); | ||
} else if (source[key] !== undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
expression.split(/,/g).forEach(function (variable) { | ||
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); | ||
values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); | ||
variables.push(tmp[1]); | ||
}); | ||
function root (options, next) { | ||
if (operator && operator !== '+') { | ||
var url = next(options); | ||
var separator = ','; | ||
if (isString(options.root) && !url.match(/^(https?:)?\//)) { | ||
url = options.root + '/' + url; | ||
} | ||
if (operator === '?') { | ||
separator = '&'; | ||
} else if (operator !== '#') { | ||
separator = operator; | ||
} | ||
return url; | ||
} | ||
return (values.length !== 0 ? operator : '') + values.join(separator); | ||
} else { | ||
return values.join(','); | ||
} | ||
} else { | ||
return encodeReserved(literal); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
function query (options, next) { | ||
function getValues(context, operator, key, modifier) { | ||
var urlParams = Object.keys(Url.options.params), | ||
query = {}, | ||
url = next(options); | ||
var value = context[key], | ||
result = []; | ||
each(options.params, function (value, key) { | ||
if (urlParams.indexOf(key) === -1) { | ||
query[key] = value; | ||
} | ||
}); | ||
if (isDefined(value) && value !== '') { | ||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
value = value.toString(); | ||
query = Url.params(query); | ||
if (modifier && modifier !== '*') { | ||
value = value.substring(0, parseInt(modifier, 10)); | ||
} | ||
if (query) { | ||
url += (url.indexOf('?') == -1 ? '?' : '&') + query; | ||
} | ||
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); | ||
} else { | ||
if (modifier === '*') { | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
if (isDefined(value[k])) { | ||
result.push(encodeValue(operator, value[k], k)); | ||
} | ||
}); | ||
} | ||
} else { | ||
var tmp = []; | ||
return url; | ||
} | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
tmp.push(encodeValue(operator, value)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
if (isDefined(value[k])) { | ||
tmp.push(encodeURIComponent(k)); | ||
tmp.push(encodeValue(operator, value[k].toString())); | ||
} | ||
}); | ||
} | ||
/** | ||
* URL Template v2.0.6 (https://github.com/bramstein/url-template) | ||
*/ | ||
if (isKeyOperator(operator)) { | ||
result.push(encodeURIComponent(key) + '=' + tmp.join(',')); | ||
} else if (tmp.length !== 0) { | ||
result.push(tmp.join(',')); | ||
} | ||
} | ||
} | ||
} else { | ||
if (operator === ';') { | ||
result.push(encodeURIComponent(key)); | ||
} else if (value === '' && (operator === '&' || operator === '?')) { | ||
result.push(encodeURIComponent(key) + '='); | ||
} else if (value === '') { | ||
result.push(''); | ||
} | ||
} | ||
function expand(url, params, variables) { | ||
return result; | ||
} | ||
var tmpl = parse(url), | ||
expanded = tmpl.expand(params); | ||
function isDefined(value) { | ||
return value !== undefined && value !== null; | ||
} | ||
if (variables) { | ||
variables.push.apply(variables, tmpl.vars); | ||
} | ||
function isKeyOperator(operator) { | ||
return operator === ';' || operator === '&' || operator === '?'; | ||
} | ||
return expanded; | ||
} | ||
function encodeValue(operator, value, key) { | ||
function parse(template) { | ||
value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value); | ||
var operators = ['+', '#', '.', '/', ';', '?', '&'], | ||
variables = []; | ||
if (key) { | ||
return encodeURIComponent(key) + '=' + value; | ||
} else { | ||
return value; | ||
} | ||
} | ||
return { | ||
vars: variables, | ||
expand: function (context) { | ||
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { | ||
if (expression) { | ||
function encodeReserved(str) { | ||
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) { | ||
if (!/%[0-9A-Fa-f]/.test(part)) { | ||
part = encodeURI(part); | ||
} | ||
return part; | ||
}).join(''); | ||
} | ||
var operator = null, | ||
values = []; | ||
/** | ||
* URL Template (RFC 6570) Transform. | ||
*/ | ||
if (operators.indexOf(expression.charAt(0)) !== -1) { | ||
operator = expression.charAt(0); | ||
expression = expression.substr(1); | ||
} | ||
function template (options) { | ||
expression.split(/,/g).forEach(function (variable) { | ||
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); | ||
values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); | ||
variables.push(tmp[1]); | ||
}); | ||
var variables = [], | ||
url = expand(options.url, options.params, variables); | ||
if (operator && operator !== '+') { | ||
variables.forEach(function (key) { | ||
delete options.params[key]; | ||
}); | ||
var separator = ','; | ||
return url; | ||
} | ||
if (operator === '?') { | ||
separator = '&'; | ||
} else if (operator !== '#') { | ||
separator = operator; | ||
} | ||
/** | ||
* Service for URL templating. | ||
*/ | ||
return (values.length !== 0 ? operator : '') + values.join(separator); | ||
} else { | ||
return values.join(','); | ||
} | ||
} else { | ||
return encodeReserved(literal); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
var ie = document.documentMode; | ||
var el = document.createElement('a'); | ||
function getValues(context, operator, key, modifier) { | ||
function Url(url, params) { | ||
var value = context[key], | ||
result = []; | ||
var self = this || {}, | ||
options = url, | ||
transform; | ||
if (isDefined(value) && value !== '') { | ||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
value = value.toString(); | ||
if (isString(url)) { | ||
options = { url: url, params: params }; | ||
} | ||
if (modifier && modifier !== '*') { | ||
value = value.substring(0, parseInt(modifier, 10)); | ||
} | ||
options = merge({}, Url.options, self.$options, options); | ||
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); | ||
} else { | ||
if (modifier === '*') { | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
if (isDefined(value[k])) { | ||
result.push(encodeValue(operator, value[k], k)); | ||
} | ||
}); | ||
} | ||
} else { | ||
var tmp = []; | ||
Url.transforms.forEach(function (handler) { | ||
transform = factory(handler, transform, self.$vm); | ||
}); | ||
if (Array.isArray(value)) { | ||
value.filter(isDefined).forEach(function (value) { | ||
tmp.push(encodeValue(operator, value)); | ||
}); | ||
} else { | ||
Object.keys(value).forEach(function (k) { | ||
if (isDefined(value[k])) { | ||
tmp.push(encodeURIComponent(k)); | ||
tmp.push(encodeValue(operator, value[k].toString())); | ||
} | ||
}); | ||
} | ||
return transform(options); | ||
} | ||
if (isKeyOperator(operator)) { | ||
result.push(encodeURIComponent(key) + '=' + tmp.join(',')); | ||
} else if (tmp.length !== 0) { | ||
result.push(tmp.join(',')); | ||
} | ||
} | ||
} | ||
} else { | ||
if (operator === ';') { | ||
result.push(encodeURIComponent(key)); | ||
} else if (value === '' && (operator === '&' || operator === '?')) { | ||
result.push(encodeURIComponent(key) + '='); | ||
} else if (value === '') { | ||
result.push(''); | ||
} | ||
} | ||
/** | ||
* Url options. | ||
*/ | ||
return result; | ||
} | ||
Url.options = { | ||
url: '', | ||
root: null, | ||
params: {} | ||
}; | ||
function isDefined(value) { | ||
return value !== undefined && value !== null; | ||
} | ||
/** | ||
* Url transforms. | ||
*/ | ||
function isKeyOperator(operator) { | ||
return operator === ';' || operator === '&' || operator === '?'; | ||
} | ||
Url.transforms = [template, query, root]; | ||
function encodeValue(operator, value, key) { | ||
/** | ||
* Encodes a Url parameter string. | ||
* | ||
* @param {Object} obj | ||
*/ | ||
value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value); | ||
Url.params = function (obj) { | ||
if (key) { | ||
return encodeURIComponent(key) + '=' + value; | ||
} else { | ||
return value; | ||
} | ||
} | ||
var params = [], | ||
escape = encodeURIComponent; | ||
function encodeReserved(str) { | ||
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) { | ||
if (!/%[0-9A-Fa-f]/.test(part)) { | ||
part = encodeURI(part); | ||
} | ||
return part; | ||
}).join(''); | ||
} | ||
params.add = function (key, value) { | ||
function template (options) { | ||
if (isFunction(value)) { | ||
value = value(); | ||
} | ||
var variables = [], | ||
url = expand(options.url, options.params, variables); | ||
if (value === null) { | ||
value = ''; | ||
} | ||
variables.forEach(function (key) { | ||
delete options.params[key]; | ||
}); | ||
this.push(escape(key) + '=' + escape(value)); | ||
}; | ||
return url; | ||
} | ||
serialize(params, obj); | ||
/** | ||
* Service for URL templating. | ||
*/ | ||
return params.join('&').replace(/%20/g, '+'); | ||
}; | ||
var ie = document.documentMode; | ||
var el = document.createElement('a'); | ||
/** | ||
* Parse a URL and return its components. | ||
* | ||
* @param {String} url | ||
*/ | ||
function Url(url, params) { | ||
Url.parse = function (url) { | ||
var self = this || {}, | ||
options = url, | ||
transform; | ||
if (ie) { | ||
el.href = url; | ||
url = el.href; | ||
} | ||
if (isString(url)) { | ||
options = { url: url, params: params }; | ||
} | ||
el.href = url; | ||
options = merge({}, Url.options, self.$options, options); | ||
return { | ||
href: el.href, | ||
protocol: el.protocol ? el.protocol.replace(/:$/, '') : '', | ||
port: el.port, | ||
host: el.host, | ||
hostname: el.hostname, | ||
pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname, | ||
search: el.search ? el.search.replace(/^\?/, '') : '', | ||
hash: el.hash ? el.hash.replace(/^#/, '') : '' | ||
}; | ||
}; | ||
Url.transforms.forEach(function (handler) { | ||
transform = factory(handler, transform, self.$vm); | ||
}); | ||
function factory(handler, next, vm) { | ||
return function (options) { | ||
return handler.call(vm, options, next); | ||
}; | ||
} | ||
return transform(options); | ||
} | ||
function serialize(params, obj, scope) { | ||
/** | ||
* Url options. | ||
*/ | ||
var array = isArray(obj), | ||
plain = isPlainObject(obj), | ||
hash; | ||
Url.options = { | ||
url: '', | ||
root: null, | ||
params: {} | ||
}; | ||
each(obj, function (value, key) { | ||
/** | ||
* Url transforms. | ||
*/ | ||
hash = isObject(value) || isArray(value); | ||
Url.transforms = [template, query, root]; | ||
if (scope) { | ||
key = scope + '[' + (plain || hash ? key : '') + ']'; | ||
} | ||
/** | ||
* Encodes a Url parameter string. | ||
* | ||
* @param {Object} obj | ||
*/ | ||
if (!scope && array) { | ||
params.add(value.name, value.value); | ||
} else if (hash) { | ||
serialize(params, value, key); | ||
} else { | ||
params.add(key, value); | ||
} | ||
}); | ||
} | ||
Url.params = function (obj) { | ||
/** | ||
* XDomain client (Internet Explorer). | ||
*/ | ||
var params = [], | ||
escape = encodeURIComponent; | ||
function xdrClient (request) { | ||
return new Promise$1(function (resolve) { | ||
params.add = function (key, value) { | ||
var xdr = new XDomainRequest(), | ||
handler = function (event) { | ||
if (isFunction(value)) { | ||
value = value(); | ||
} | ||
var response = request.respondWith(xdr.responseText, { | ||
status: xdr.status, | ||
statusText: xdr.statusText | ||
}); | ||
if (value === null) { | ||
value = ''; | ||
} | ||
resolve(response); | ||
}; | ||
this.push(escape(key) + '=' + escape(value)); | ||
}; | ||
request.abort = function () { | ||
return xdr.abort(); | ||
}; | ||
serialize(params, obj); | ||
xdr.open(request.method, request.getUrl(), true); | ||
xdr.timeout = 0; | ||
xdr.onload = handler; | ||
xdr.onerror = handler; | ||
xdr.ontimeout = function () {}; | ||
xdr.onprogress = function () {}; | ||
xdr.send(request.getBody()); | ||
}); | ||
} | ||
return params.join('&').replace(/%20/g, '+'); | ||
}; | ||
/** | ||
* CORS Interceptor. | ||
*/ | ||
/** | ||
* Parse a URL and return its components. | ||
* | ||
* @param {String} url | ||
*/ | ||
var ORIGIN_URL = Url.parse(location.href); | ||
var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest(); | ||
Url.parse = function (url) { | ||
function cors (request, next) { | ||
if (ie) { | ||
el.href = url; | ||
url = el.href; | ||
} | ||
if (!isBoolean(request.crossOrigin) && crossOrigin(request)) { | ||
request.crossOrigin = true; | ||
} | ||
el.href = url; | ||
if (request.crossOrigin) { | ||
return { | ||
href: el.href, | ||
protocol: el.protocol ? el.protocol.replace(/:$/, '') : '', | ||
port: el.port, | ||
host: el.host, | ||
hostname: el.hostname, | ||
pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname, | ||
search: el.search ? el.search.replace(/^\?/, '') : '', | ||
hash: el.hash ? el.hash.replace(/^#/, '') : '' | ||
}; | ||
}; | ||
if (!SUPPORTS_CORS) { | ||
request.client = xdrClient; | ||
} | ||
function factory(handler, next, vm) { | ||
return function (options) { | ||
return handler.call(vm, options, next); | ||
}; | ||
} | ||
delete request.emulateHTTP; | ||
} | ||
function serialize(params, obj, scope) { | ||
next(); | ||
} | ||
var array = isArray(obj), | ||
plain = isPlainObject(obj), | ||
hash; | ||
function crossOrigin(request) { | ||
each(obj, function (value, key) { | ||
var requestUrl = Url.parse(Url(request)); | ||
hash = isObject(value) || isArray(value); | ||
return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host; | ||
} | ||
if (scope) { | ||
key = scope + '[' + (plain || hash ? key : '') + ']'; | ||
} | ||
/** | ||
* Body Interceptor. | ||
*/ | ||
if (!scope && array) { | ||
params.add(value.name, value.value); | ||
} else if (hash) { | ||
serialize(params, value, key); | ||
} else { | ||
params.add(key, value); | ||
} | ||
}); | ||
} | ||
function body (request, next) { | ||
function xdrClient (request) { | ||
return new Promise$1(function (resolve) { | ||
if (request.emulateJSON && isPlainObject(request.body)) { | ||
request.body = Url.params(request.body); | ||
request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); | ||
} | ||
var xdr = new XDomainRequest(), | ||
handler = function (event) { | ||
if (isFormData(request.body)) { | ||
request.headers.delete('Content-Type'); | ||
} | ||
var response = request.respondWith(xdr.responseText, { | ||
status: xdr.status, | ||
statusText: xdr.statusText | ||
}); | ||
if (isPlainObject(request.body)) { | ||
request.body = JSON.stringify(request.body); | ||
} | ||
resolve(response); | ||
}; | ||
next(function (response) { | ||
request.abort = function () { | ||
return xdr.abort(); | ||
}; | ||
Object.defineProperty(response, 'data', { | ||
get: function () { | ||
return this.body; | ||
}, | ||
set: function (body) { | ||
this.body = body; | ||
} | ||
}); | ||
xdr.open(request.method, request.getUrl(), true); | ||
xdr.timeout = 0; | ||
xdr.onload = handler; | ||
xdr.onerror = handler; | ||
xdr.ontimeout = function () {}; | ||
xdr.onprogress = function () {}; | ||
xdr.send(request.getBody()); | ||
}); | ||
} | ||
return response.bodyText ? when(response.text(), function (text) { | ||
var ORIGIN_URL = Url.parse(location.href); | ||
var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest(); | ||
var type = response.headers.get('Content-Type'); | ||
function cors (request, next) { | ||
if (isString(type) && type.indexOf('application/json') === 0) { | ||
if (!isBoolean(request.crossOrigin) && crossOrigin(request)) { | ||
request.crossOrigin = true; | ||
} | ||
try { | ||
response.body = JSON.parse(text); | ||
} catch (e) { | ||
response.body = null; | ||
} | ||
} else { | ||
response.body = text; | ||
} | ||
if (request.crossOrigin) { | ||
return response; | ||
}) : response; | ||
}); | ||
} | ||
if (!SUPPORTS_CORS) { | ||
request.client = xdrClient; | ||
} | ||
/** | ||
* JSONP client. | ||
*/ | ||
delete request.emulateHTTP; | ||
} | ||
function jsonpClient (request) { | ||
return new Promise$1(function (resolve) { | ||
next(); | ||
} | ||
var name = request.jsonp || 'callback', | ||
callback = '_jsonp' + Math.random().toString(36).substr(2), | ||
body = null, | ||
handler, | ||
script; | ||
function crossOrigin(request) { | ||
handler = function (event) { | ||
var requestUrl = Url.parse(Url(request)); | ||
var status = 0; | ||
return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host; | ||
} | ||
if (event.type === 'load' && body !== null) { | ||
status = 200; | ||
} else if (event.type === 'error') { | ||
status = 404; | ||
} | ||
function body (request, next) { | ||
resolve(request.respondWith(body, { status: status })); | ||
if (request.emulateJSON && isPlainObject(request.body)) { | ||
request.body = Url.params(request.body); | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
} | ||
delete window[callback]; | ||
document.body.removeChild(script); | ||
}; | ||
if (isFormData(request.body)) { | ||
delete request.headers['Content-Type']; | ||
} | ||
request.params[name] = callback; | ||
if (isPlainObject(request.body)) { | ||
request.body = JSON.stringify(request.body); | ||
} | ||
window[callback] = function (result) { | ||
body = JSON.stringify(result); | ||
}; | ||
next(function (response) { | ||
script = document.createElement('script'); | ||
script.src = request.getUrl(); | ||
script.type = 'text/javascript'; | ||
script.async = true; | ||
script.onload = handler; | ||
script.onerror = handler; | ||
var contentType = response.headers['Content-Type']; | ||
document.body.appendChild(script); | ||
}); | ||
} | ||
if (isString(contentType) && contentType.indexOf('application/json') === 0) { | ||
/** | ||
* JSONP Interceptor. | ||
*/ | ||
try { | ||
response.data = response.json(); | ||
} catch (e) { | ||
response.data = null; | ||
} | ||
} else { | ||
response.data = response.text(); | ||
} | ||
}); | ||
} | ||
function jsonp (request, next) { | ||
function jsonpClient (request) { | ||
return new Promise$1(function (resolve) { | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
var name = request.jsonp || 'callback', | ||
callback = '_jsonp' + Math.random().toString(36).substr(2), | ||
body = null, | ||
handler, | ||
script; | ||
next(function (response) { | ||
handler = function (event) { | ||
if (request.method == 'JSONP') { | ||
var status = 0; | ||
return when(response.json(), function (json) { | ||
if (event.type === 'load' && body !== null) { | ||
status = 200; | ||
} else if (event.type === 'error') { | ||
status = 404; | ||
} | ||
response.body = json; | ||
resolve(request.respondWith(body, { status: status })); | ||
return response; | ||
}); | ||
} | ||
}); | ||
} | ||
delete window[callback]; | ||
document.body.removeChild(script); | ||
}; | ||
/** | ||
* Before Interceptor. | ||
*/ | ||
request.params[name] = callback; | ||
function before (request, next) { | ||
window[callback] = function (result) { | ||
body = JSON.stringify(result); | ||
}; | ||
if (isFunction(request.before)) { | ||
request.before.call(this, request); | ||
} | ||
script = document.createElement('script'); | ||
script.src = request.getUrl(); | ||
script.type = 'text/javascript'; | ||
script.async = true; | ||
script.onload = handler; | ||
script.onerror = handler; | ||
next(); | ||
} | ||
document.body.appendChild(script); | ||
}); | ||
} | ||
/** | ||
* HTTP method override Interceptor. | ||
*/ | ||
function jsonp (request, next) { | ||
function method (request, next) { | ||
if (request.method == 'JSONP') { | ||
request.client = jsonpClient; | ||
} | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers.set('X-HTTP-Method-Override', request.method); | ||
request.method = 'POST'; | ||
} | ||
next(function (response) { | ||
next(); | ||
} | ||
if (request.method == 'JSONP') { | ||
response.data = response.json(); | ||
} | ||
}); | ||
} | ||
/** | ||
* Header Interceptor. | ||
*/ | ||
function before (request, next) { | ||
function header (request, next) { | ||
if (isFunction(request.before)) { | ||
request.before.call(this, request); | ||
} | ||
var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]); | ||
next(); | ||
} | ||
each(headers, function (value, name) { | ||
if (!request.headers.has(name)) { | ||
request.headers.set(name, value); | ||
} | ||
}); | ||
/** | ||
* HTTP method override Interceptor. | ||
*/ | ||
next(); | ||
} | ||
function method (request, next) { | ||
/** | ||
* Timeout Interceptor. | ||
*/ | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.method = 'POST'; | ||
} | ||
function timeout (request, next) { | ||
next(); | ||
} | ||
var timeout; | ||
function header (request, next) { | ||
if (request.timeout) { | ||
timeout = setTimeout(function () { | ||
request.abort(); | ||
}, request.timeout); | ||
} | ||
request.method = request.method.toUpperCase(); | ||
request.headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers); | ||
next(function (response) { | ||
next(); | ||
} | ||
clearTimeout(timeout); | ||
}); | ||
} | ||
/** | ||
* Timeout Interceptor. | ||
*/ | ||
/** | ||
* XMLHttp client. | ||
*/ | ||
function timeout (request, next) { | ||
function xhrClient (request) { | ||
return new Promise$1(function (resolve) { | ||
var timeout; | ||
var xhr = new XMLHttpRequest(), | ||
handler = function (event) { | ||
if (request.timeout) { | ||
timeout = setTimeout(function () { | ||
request.abort(); | ||
}, request.timeout); | ||
} | ||
var response = request.respondWith('response' in xhr ? xhr.response : xhr.responseText, { | ||
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) | ||
}); | ||
next(function (response) { | ||
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) { | ||
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); | ||
}); | ||
clearTimeout(timeout); | ||
}); | ||
} | ||
resolve(response); | ||
}; | ||
function xhrClient (request) { | ||
return new Promise$1(function (resolve) { | ||
request.abort = function () { | ||
return xhr.abort(); | ||
}; | ||
var xhr = new XMLHttpRequest(), | ||
handler = function (event) { | ||
xhr.open(request.method, request.getUrl(), true); | ||
xhr.timeout = 0; | ||
xhr.onload = handler; | ||
xhr.onerror = handler; | ||
var response = request.respondWith('response' in xhr ? xhr.response : xhr.responseText, { | ||
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText), | ||
headers: parseHeaders(xhr.getAllResponseHeaders()) | ||
}); | ||
if (request.progress) { | ||
if (request.method === 'GET') { | ||
xhr.addEventListener('progress', request.progress); | ||
} else if (/^(POST|PUT)$/i.test(request.method)) { | ||
xhr.upload.addEventListener('progress', request.progress); | ||
} | ||
} | ||
resolve(response); | ||
}; | ||
if ('responseType' in xhr) { | ||
xhr.responseType = 'blob'; | ||
} | ||
request.abort = function () { | ||
return xhr.abort(); | ||
}; | ||
if (request.credentials === true) { | ||
xhr.withCredentials = true; | ||
} | ||
xhr.open(request.method, request.getUrl(), true); | ||
xhr.timeout = 0; | ||
xhr.onload = handler; | ||
xhr.onerror = handler; | ||
request.headers.forEach(function (value, name) { | ||
xhr.setRequestHeader(name, value); | ||
}); | ||
if (request.progress) { | ||
if (request.method === 'GET') { | ||
xhr.addEventListener('progress', request.progress); | ||
} else if (/^(POST|PUT)$/i.test(request.method)) { | ||
xhr.upload.addEventListener('progress', request.progress); | ||
} | ||
} | ||
xhr.send(request.getBody()); | ||
}); | ||
} | ||
if (request.credentials === true) { | ||
xhr.withCredentials = true; | ||
} | ||
/** | ||
* Base client. | ||
*/ | ||
each(request.headers || {}, function (value, header) { | ||
xhr.setRequestHeader(header, value); | ||
}); | ||
function Client (context) { | ||
xhr.send(request.getBody()); | ||
}); | ||
} | ||
var reqHandlers = [sendRequest], | ||
resHandlers = [], | ||
handler; | ||
function parseHeaders(str) { | ||
if (!isObject(context)) { | ||
context = null; | ||
} | ||
var headers = {}, | ||
value, | ||
name, | ||
i; | ||
function Client(request) { | ||
return new Promise$1(function (resolve) { | ||
each(trim(str).split('\n'), function (row) { | ||
function exec() { | ||
i = row.indexOf(':'); | ||
name = trim(row.slice(0, i)); | ||
value = trim(row.slice(i + 1)); | ||
handler = reqHandlers.pop(); | ||
if (headers[name]) { | ||
if (isFunction(handler)) { | ||
handler.call(context, request, next); | ||
} else { | ||
warn('Invalid interceptor of type ' + typeof handler + ', must be a function'); | ||
next(); | ||
} | ||
} | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
} else { | ||
function next(response) { | ||
headers[name] = value; | ||
} | ||
}); | ||
if (isFunction(response)) { | ||
return headers; | ||
resHandlers.unshift(response); | ||
} else if (isObject(response)) { | ||
resHandlers.forEach(function (handler) { | ||
response = when(response, function (response) { | ||
return handler.call(context, response) || response; | ||
}); | ||
}); | ||
when(response, resolve); | ||
return; | ||
} | ||
exec(); | ||
} | ||
exec(); | ||
}, context); | ||
} | ||
Client.use = function (handler) { | ||
reqHandlers.push(handler); | ||
}; | ||
return Client; | ||
} | ||
function sendRequest(request, resolve) { | ||
var client = request.client || xhrClient; | ||
resolve(client(request)); | ||
} | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
function Client (context) { | ||
/** | ||
* HTTP Headers. | ||
*/ | ||
var reqHandlers = [sendRequest], | ||
resHandlers = [], | ||
handler; | ||
var Headers = function () { | ||
function Headers(headers) { | ||
var _this = this; | ||
if (!isObject(context)) { | ||
context = null; | ||
} | ||
classCallCheck(this, Headers); | ||
function Client(request) { | ||
return new Promise$1(function (resolve) { | ||
function exec() { | ||
this.map = {}; | ||
handler = reqHandlers.pop(); | ||
each(headers, function (value, name) { | ||
return _this.append(name, value); | ||
}); | ||
} | ||
if (isFunction(handler)) { | ||
handler.call(context, request, next); | ||
} else { | ||
warn('Invalid interceptor of type ' + typeof handler + ', must be a function'); | ||
next(); | ||
} | ||
} | ||
Headers.prototype.has = function has(name) { | ||
return this.map.hasOwnProperty(normalizeName(name)); | ||
}; | ||
function next(response) { | ||
Headers.prototype.get = function get(name) { | ||
if (isFunction(response)) { | ||
var list = this.map[normalizeName(name)]; | ||
resHandlers.unshift(response); | ||
} else if (isObject(response)) { | ||
return list ? list[0] : null; | ||
}; | ||
resHandlers.forEach(function (handler) { | ||
response = when(response, function (response) { | ||
return handler.call(context, response) || response; | ||
}); | ||
}); | ||
Headers.prototype.getAll = function getAll(name) { | ||
return this.map[normalizeName(name)] || []; | ||
}; | ||
when(response, resolve); | ||
Headers.prototype.set = function set(name, value) { | ||
this.map[normalizeName(name)] = [trim(value)]; | ||
}; | ||
return; | ||
} | ||
Headers.prototype.append = function append(name, value) { | ||
exec(); | ||
} | ||
var list = this.map[normalizeName(name)]; | ||
exec(); | ||
}, context); | ||
} | ||
if (!list) { | ||
list = this.map[normalizeName(name)] = []; | ||
} | ||
Client.use = function (handler) { | ||
reqHandlers.push(handler); | ||
}; | ||
list.push(trim(value)); | ||
}; | ||
return Client; | ||
} | ||
Headers.prototype.delete = function _delete(name) { | ||
delete this.map[normalizeName(name)]; | ||
}; | ||
function sendRequest(request, resolve) { | ||
Headers.prototype.forEach = function forEach(callback, thisArg) { | ||
var _this2 = this; | ||
var client = request.client || xhrClient; | ||
each(this.map, function (list, name) { | ||
each(list, function (value) { | ||
return callback.call(thisArg, value, name, _this2); | ||
}); | ||
}); | ||
}; | ||
resolve(client(request)); | ||
} | ||
return Headers; | ||
}(); | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
function normalizeName(name) { | ||
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { | ||
throw new TypeError('Invalid character in header field name'); | ||
} | ||
}; | ||
/** | ||
* HTTP Response. | ||
*/ | ||
return toLower(trim(name)); | ||
} | ||
var Response = function () { | ||
function Response(body, _ref) { | ||
var url = _ref.url; | ||
var headers = _ref.headers; | ||
var status = _ref.status; | ||
var statusText = _ref.statusText; | ||
classCallCheck(this, Response); | ||
/** | ||
* HTTP Response. | ||
*/ | ||
var Response = function () { | ||
function Response(body, _ref) { | ||
var url = _ref.url; | ||
var headers = _ref.headers; | ||
var status = _ref.status; | ||
var statusText = _ref.statusText; | ||
classCallCheck(this, Response); | ||
this.url = url; | ||
this.body = body; | ||
this.headers = headers || {}; | ||
this.status = status || 0; | ||
this.statusText = statusText || ''; | ||
this.ok = status >= 200 && status < 300; | ||
} | ||
Response.prototype.text = function text() { | ||
return this.body; | ||
}; | ||
this.url = url; | ||
this.ok = status >= 200 && status < 300; | ||
this.status = status || 0; | ||
this.statusText = statusText || ''; | ||
this.headers = new Headers(headers); | ||
this.body = body; | ||
Response.prototype.blob = function blob() { | ||
return new Blob([this.body]); | ||
}; | ||
if (isString(body)) { | ||
Response.prototype.json = function json() { | ||
return JSON.parse(this.body); | ||
}; | ||
this.bodyText = body; | ||
} else if (isBlob(body)) { | ||
return Response; | ||
}(); | ||
this.bodyBlob = body; | ||
var Request = function () { | ||
function Request(options) { | ||
classCallCheck(this, Request); | ||
if (isBlobText(body)) { | ||
this.bodyText = blobText(body); | ||
} | ||
} | ||
} | ||
Response.prototype.blob = function blob() { | ||
return when(this.bodyBlob); | ||
}; | ||
this.method = 'GET'; | ||
this.body = null; | ||
this.params = {}; | ||
this.headers = {}; | ||
Response.prototype.text = function text() { | ||
return when(this.bodyText); | ||
}; | ||
assign(this, options); | ||
} | ||
Response.prototype.json = function json() { | ||
return when(this.text(), function (text) { | ||
return JSON.parse(text); | ||
}); | ||
}; | ||
Request.prototype.getUrl = function getUrl() { | ||
return Url(this); | ||
}; | ||
return Response; | ||
}(); | ||
Request.prototype.getBody = function getBody() { | ||
return this.body; | ||
}; | ||
function blobText(body) { | ||
return new Promise$1(function (resolve) { | ||
Request.prototype.respondWith = function respondWith(body, options) { | ||
return new Response(body, assign(options || {}, { url: this.getUrl() })); | ||
}; | ||
var reader = new FileReader(); | ||
return Request; | ||
}(); | ||
reader.readAsText(body); | ||
reader.onload = function () { | ||
resolve(reader.result); | ||
}; | ||
}); | ||
} | ||
/** | ||
* Service for sending network requests. | ||
*/ | ||
function isBlobText(body) { | ||
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; | ||
} | ||
var CUSTOM_HEADERS = { 'X-Requested-With': 'XMLHttpRequest' }; | ||
var COMMON_HEADERS = { 'Accept': 'application/json, text/plain, */*' }; | ||
var JSON_CONTENT_TYPE = { 'Content-Type': 'application/json;charset=utf-8' }; | ||
/** | ||
* HTTP Request. | ||
*/ | ||
function Http(options) { | ||
var Request = function () { | ||
function Request(options) { | ||
classCallCheck(this, Request); | ||
var self = this || {}, | ||
client = Client(self.$vm); | ||
defaults(options || {}, self.$options, Http.options); | ||
this.body = null; | ||
this.params = {}; | ||
Http.interceptors.forEach(function (handler) { | ||
client.use(handler); | ||
}); | ||
assign(this, options, { | ||
method: toUpper(options.method || 'GET'), | ||
headers: new Headers(options.headers) | ||
}); | ||
} | ||
return client(new Request(options)).then(function (response) { | ||
Request.prototype.getUrl = function getUrl() { | ||
return Url(this); | ||
}; | ||
return response.ok ? response : Promise$1.reject(response); | ||
}, function (response) { | ||
Request.prototype.getBody = function getBody() { | ||
return this.body; | ||
}; | ||
if (response instanceof Error) { | ||
error(response); | ||
} | ||
Request.prototype.respondWith = function respondWith(body, options) { | ||
return new Response(body, assign(options || {}, { url: this.getUrl() })); | ||
}; | ||
return Promise$1.reject(response); | ||
}); | ||
} | ||
return Request; | ||
}(); | ||
Http.options = {}; | ||
/** | ||
* Service for sending network requests. | ||
*/ | ||
Http.headers = { | ||
put: JSON_CONTENT_TYPE, | ||
post: JSON_CONTENT_TYPE, | ||
patch: JSON_CONTENT_TYPE, | ||
delete: JSON_CONTENT_TYPE, | ||
custom: CUSTOM_HEADERS, | ||
common: COMMON_HEADERS | ||
}; | ||
var CUSTOM_HEADERS = { 'X-Requested-With': 'XMLHttpRequest' }; | ||
var COMMON_HEADERS = { 'Accept': 'application/json, text/plain, */*' }; | ||
var JSON_CONTENT_TYPE = { 'Content-Type': 'application/json;charset=utf-8' }; | ||
Http.interceptors = [before, timeout, method, body, jsonp, header, cors]; | ||
function Http(options) { | ||
['get', 'delete', 'head', 'jsonp'].forEach(function (method) { | ||
var self = this || {}, | ||
client = Client(self.$vm); | ||
Http[method] = function (url, options) { | ||
return this(assign(options || {}, { url: url, method: method })); | ||
}; | ||
}); | ||
defaults(options || {}, self.$options, Http.options); | ||
['post', 'put', 'patch'].forEach(function (method) { | ||
Http.interceptors.forEach(function (handler) { | ||
client.use(handler); | ||
}); | ||
Http[method] = function (url, body, options) { | ||
return this(assign(options || {}, { url: url, method: method, body: body })); | ||
}; | ||
}); | ||
return client(new Request(options)).then(function (response) { | ||
function Resource(url, params, actions, options) { | ||
return response.ok ? response : Promise$1.reject(response); | ||
}, function (response) { | ||
var self = this || {}, | ||
resource = {}; | ||
if (response instanceof Error) { | ||
error(response); | ||
} | ||
actions = assign({}, Resource.actions, actions); | ||
return Promise$1.reject(response); | ||
}); | ||
} | ||
each(actions, function (action, name) { | ||
Http.options = {}; | ||
action = merge({ url: url, params: params || {} }, options, action); | ||
Http.headers = { | ||
put: JSON_CONTENT_TYPE, | ||
post: JSON_CONTENT_TYPE, | ||
patch: JSON_CONTENT_TYPE, | ||
delete: JSON_CONTENT_TYPE, | ||
custom: CUSTOM_HEADERS, | ||
common: COMMON_HEADERS | ||
}; | ||
resource[name] = function () { | ||
return (self.$http || Http)(opts(action, arguments)); | ||
}; | ||
}); | ||
Http.interceptors = [before, timeout, method, body, jsonp, header, cors]; | ||
return resource; | ||
} | ||
['get', 'delete', 'head', 'jsonp'].forEach(function (method) { | ||
function opts(action, args) { | ||
Http[method] = function (url, options) { | ||
return this(assign(options || {}, { url: url, method: method })); | ||
}; | ||
}); | ||
var options = assign({}, action), | ||
params = {}, | ||
body; | ||
['post', 'put', 'patch'].forEach(function (method) { | ||
switch (args.length) { | ||
Http[method] = function (url, body, options) { | ||
return this(assign(options || {}, { url: url, method: method, body: body })); | ||
}; | ||
}); | ||
case 2: | ||
/** | ||
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) | ||
*/ | ||
params = args[0]; | ||
body = args[1]; | ||
var RESOLVED = 0; | ||
var REJECTED = 1; | ||
var PENDING = 2; | ||
break; | ||
function Promise$2(executor) { | ||
case 1: | ||
this.state = PENDING; | ||
this.value = undefined; | ||
this.deferred = []; | ||
if (/^(POST|PUT|PATCH)$/i.test(options.method)) { | ||
body = args[0]; | ||
} else { | ||
params = args[0]; | ||
} | ||
var promise = this; | ||
break; | ||
try { | ||
executor(function (x) { | ||
promise.resolve(x); | ||
}, function (r) { | ||
promise.reject(r); | ||
}); | ||
} catch (e) { | ||
promise.reject(e); | ||
} | ||
} | ||
case 0: | ||
Promise$2.reject = function (r) { | ||
return new Promise$2(function (resolve, reject) { | ||
reject(r); | ||
}); | ||
}; | ||
break; | ||
Promise$2.resolve = function (x) { | ||
return new Promise$2(function (resolve, reject) { | ||
resolve(x); | ||
}); | ||
}; | ||
default: | ||
Promise$2.all = function all(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
var count = 0, | ||
result = []; | ||
throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments'; | ||
} | ||
if (iterable.length === 0) { | ||
resolve(result); | ||
} | ||
options.body = body; | ||
options.params = assign({}, options.params, params); | ||
function resolver(i) { | ||
return function (x) { | ||
result[i] = x; | ||
count += 1; | ||
return options; | ||
} | ||
if (count === iterable.length) { | ||
resolve(result); | ||
} | ||
}; | ||
} | ||
Resource.actions = { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolver(i), reject); | ||
} | ||
}); | ||
}; | ||
get: { method: 'GET' }, | ||
save: { method: 'POST' }, | ||
query: { method: 'GET' }, | ||
update: { method: 'PUT' }, | ||
remove: { method: 'DELETE' }, | ||
delete: { method: 'DELETE' } | ||
Promise$2.race = function race(iterable) { | ||
return new Promise$2(function (resolve, reject) { | ||
for (var i = 0; i < iterable.length; i += 1) { | ||
Promise$2.resolve(iterable[i]).then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
}; | ||
var p$1 = Promise$2.prototype; | ||
function plugin(Vue) { | ||
p$1.resolve = function resolve(x) { | ||
var promise = this; | ||
if (plugin.installed) { | ||
return; | ||
} | ||
if (promise.state === PENDING) { | ||
if (x === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
Util(Vue); | ||
var called = false; | ||
Vue.url = Url; | ||
Vue.http = Http; | ||
Vue.resource = Resource; | ||
Vue.Promise = Promise$1; | ||
try { | ||
var then = x && x['then']; | ||
Object.defineProperties(Vue.prototype, { | ||
if (x !== null && typeof x === 'object' && typeof then === 'function') { | ||
then.call(x, function (x) { | ||
if (!called) { | ||
promise.resolve(x); | ||
} | ||
called = true; | ||
}, function (r) { | ||
if (!called) { | ||
promise.reject(r); | ||
} | ||
called = true; | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
if (!called) { | ||
promise.reject(e); | ||
} | ||
return; | ||
} | ||
$url: { | ||
get: function () { | ||
return options(Vue.url, this, this.$options.url); | ||
} | ||
}, | ||
promise.state = RESOLVED; | ||
promise.value = x; | ||
promise.notify(); | ||
} | ||
}; | ||
$http: { | ||
get: function () { | ||
return options(Vue.http, this, this.$options.http); | ||
} | ||
}, | ||
p$1.reject = function reject(reason) { | ||
var promise = this; | ||
$resource: { | ||
get: function () { | ||
return Vue.resource.bind(this); | ||
} | ||
}, | ||
if (promise.state === PENDING) { | ||
if (reason === promise) { | ||
throw new TypeError('Promise settled with itself.'); | ||
} | ||
$promise: { | ||
get: function () { | ||
var _this = this; | ||
promise.state = REJECTED; | ||
promise.value = reason; | ||
promise.notify(); | ||
} | ||
}; | ||
return function (executor) { | ||
return new Vue.Promise(executor, _this); | ||
}; | ||
} | ||
} | ||
p$1.notify = function notify() { | ||
var promise = this; | ||
}); | ||
} | ||
nextTick(function () { | ||
if (promise.state !== PENDING) { | ||
while (promise.deferred.length) { | ||
var deferred = promise.deferred.shift(), | ||
onResolved = deferred[0], | ||
onRejected = deferred[1], | ||
resolve = deferred[2], | ||
reject = deferred[3]; | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin); | ||
} | ||
try { | ||
if (promise.state === RESOLVED) { | ||
if (typeof onResolved === 'function') { | ||
resolve(onResolved.call(undefined, promise.value)); | ||
} else { | ||
resolve(promise.value); | ||
} | ||
} else if (promise.state === REJECTED) { | ||
if (typeof onRejected === 'function') { | ||
resolve(onRejected.call(undefined, promise.value)); | ||
} else { | ||
reject(promise.value); | ||
} | ||
} | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
return plugin; | ||
p$1.then = function then(onResolved, onRejected) { | ||
var promise = this; | ||
})); | ||
return new Promise$2(function (resolve, reject) { | ||
promise.deferred.push([onResolved, onRejected, resolve, reject]); | ||
promise.notify(); | ||
}); | ||
}; | ||
p$1.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
/** | ||
* Service for interacting with RESTful services. | ||
*/ | ||
function Resource(url, params, actions, options) { | ||
var self = this || {}, | ||
resource = {}; | ||
actions = assign({}, Resource.actions, actions); | ||
each(actions, function (action, name) { | ||
action = merge({ url: url, params: assign({}, params) }, options, action); | ||
resource[name] = function () { | ||
return (self.$http || Http)(opts(action, arguments)); | ||
}; | ||
}); | ||
return resource; | ||
} | ||
function opts(action, args) { | ||
var options = assign({}, action), | ||
params = {}, | ||
body; | ||
switch (args.length) { | ||
case 2: | ||
params = args[0]; | ||
body = args[1]; | ||
break; | ||
case 1: | ||
if (/^(POST|PUT|PATCH)$/i.test(options.method)) { | ||
body = args[0]; | ||
} else { | ||
params = args[0]; | ||
} | ||
break; | ||
case 0: | ||
break; | ||
default: | ||
throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments'; | ||
} | ||
options.body = body; | ||
options.params = assign({}, options.params, params); | ||
return options; | ||
} | ||
Resource.actions = { | ||
get: { method: 'GET' }, | ||
save: { method: 'POST' }, | ||
query: { method: 'GET' }, | ||
update: { method: 'PUT' }, | ||
remove: { method: 'DELETE' }, | ||
delete: { method: 'DELETE' } | ||
}; | ||
/** | ||
* Install plugin. | ||
*/ | ||
function plugin(Vue) { | ||
if (plugin.installed) { | ||
return; | ||
} | ||
Util(Vue); | ||
Vue.url = Url; | ||
Vue.http = Http; | ||
Vue.resource = Resource; | ||
Vue.Promise = Promise$1; | ||
Object.defineProperties(Vue.prototype, { | ||
$url: { | ||
get: function () { | ||
return options(Vue.url, this, this.$options.url); | ||
} | ||
}, | ||
$http: { | ||
get: function () { | ||
return options(Vue.http, this, this.$options.http); | ||
} | ||
}, | ||
$resource: { | ||
get: function () { | ||
return Vue.resource.bind(this); | ||
} | ||
}, | ||
$promise: { | ||
get: function () { | ||
var _this = this; | ||
return function (executor) { | ||
return new Vue.Promise(executor, _this); | ||
}; | ||
} | ||
} | ||
}); | ||
} | ||
if (typeof window !== 'undefined') { | ||
if (!window.Promise) { | ||
window.Promise = Promise$2; | ||
} | ||
if (window.Vue) { | ||
window.Vue.use(plugin); | ||
} | ||
} | ||
return plugin; | ||
}))); |
/*! | ||
* vue-resource v0.9.3 | ||
* vue-resource v1.0.0 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -7,2 +7,2 @@ * Released under the MIT License. | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.VueResource=n()}(this,function(){"use strict";function t(t){this.state=Z,this.value=void 0,this.deferred=[];var n=this;try{t(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(e){n.reject(e)}}function n(t,n){t instanceof nt?this.promise=t:this.promise=new nt(t.bind(n)),this.context=n}function e(t){rt=t.util,ot=t.config.debug||!t.config.silent}function o(t){"undefined"!=typeof console&&ot&&console.warn("[VueResource warn]: "+t)}function r(t){"undefined"!=typeof console&&console.error(t)}function i(t,n){return rt.nextTick(t,n)}function u(t){return t.replace(/^\s*|\s*$/g,"")}function s(t){return"string"==typeof t}function c(t){return t===!0||t===!1}function a(t){return"function"==typeof t}function f(t){return null!==t&&"object"==typeof t}function h(t){return f(t)&&Object.getPrototypeOf(t)==Object.prototype}function p(t){return"undefined"!=typeof FormData&&t instanceof FormData}function l(t,e,o){var r=n.resolve(t);return arguments.length<2?r:r.then(e,o)}function d(t,n,e){return e=e||{},a(e)&&(e=e.call(n)),v(t.bind({$vm:n,$options:e}),t,{$options:e})}function m(t,n){var e,o;if("number"==typeof t.length)for(e=0;e<t.length;e++)n.call(t[e],t[e],e);else if(f(t))for(o in t)t.hasOwnProperty(o)&&n.call(t[o],t[o],o);return t}function v(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){g(t,n,!0)}),t}function y(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){for(var e in n)void 0===t[e]&&(t[e]=n[e])}),t}function b(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){g(t,n)}),t}function g(t,n,e){for(var o in n)e&&(h(n[o])||ut(n[o]))?(h(n[o])&&!h(t[o])&&(t[o]={}),ut(n[o])&&!ut(t[o])&&(t[o]=[]),g(t[o],n[o],e)):void 0!==n[o]&&(t[o]=n[o])}function w(t,n){var e=n(t);return s(t.root)&&!e.match(/^(https?:)?\//)&&(e=t.root+"/"+e),e}function T(t,n){var e=Object.keys(R.options.params),o={},r=n(t);return m(t.params,function(t,n){e.indexOf(n)===-1&&(o[n]=t)}),o=R.params(o),o&&(r+=(r.indexOf("?")==-1?"?":"&")+o),r}function j(t,n,e){var o=E(t),r=o.expand(n);return e&&e.push.apply(e,o.vars),r}function E(t){var n=["+","#",".","/",";","?","&"],e=[];return{vars:e,expand:function(o){return t.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(t,r,i){if(r){var u=null,s=[];if(n.indexOf(r.charAt(0))!==-1&&(u=r.charAt(0),r=r.substr(1)),r.split(/,/g).forEach(function(t){var n=/([^:\*]*)(?::(\d+)|(\*))?/.exec(t);s.push.apply(s,x(o,u,n[1],n[2]||n[3])),e.push(n[1])}),u&&"+"!==u){var c=",";return"?"===u?c="&":"#"!==u&&(c=u),(0!==s.length?u:"")+s.join(c)}return s.join(",")}return $(i)})}}}function x(t,n,e,o){var r=t[e],i=[];if(O(r)&&""!==r)if("string"==typeof r||"number"==typeof r||"boolean"==typeof r)r=r.toString(),o&&"*"!==o&&(r=r.substring(0,parseInt(o,10))),i.push(C(n,r,P(n)?e:null));else if("*"===o)Array.isArray(r)?r.filter(O).forEach(function(t){i.push(C(n,t,P(n)?e:null))}):Object.keys(r).forEach(function(t){O(r[t])&&i.push(C(n,r[t],t))});else{var u=[];Array.isArray(r)?r.filter(O).forEach(function(t){u.push(C(n,t))}):Object.keys(r).forEach(function(t){O(r[t])&&(u.push(encodeURIComponent(t)),u.push(C(n,r[t].toString())))}),P(n)?i.push(encodeURIComponent(e)+"="+u.join(",")):0!==u.length&&i.push(u.join(","))}else";"===n?i.push(encodeURIComponent(e)):""!==r||"&"!==n&&"?"!==n?""===r&&i.push(""):i.push(encodeURIComponent(e)+"=");return i}function O(t){return void 0!==t&&null!==t}function P(t){return";"===t||"&"===t||"?"===t}function C(t,n,e){return n="+"===t||"#"===t?$(n):encodeURIComponent(n),e?encodeURIComponent(e)+"="+n:n}function $(t){return t.split(/(%[0-9A-Fa-f]{2})/g).map(function(t){return/%[0-9A-Fa-f]/.test(t)||(t=encodeURI(t)),t}).join("")}function U(t){var n=[],e=j(t.url,t.params,n);return n.forEach(function(n){delete t.params[n]}),e}function R(t,n){var e,o=this||{},r=t;return s(t)&&(r={url:t,params:n}),r=v({},R.options,o.$options,r),R.transforms.forEach(function(t){e=A(t,e,o.$vm)}),e(r)}function A(t,n,e){return function(o){return t.call(e,o,n)}}function S(t,n,e){var o,r=ut(n),i=h(n);m(n,function(n,u){o=f(n)||ut(n),e&&(u=e+"["+(i||o?u:"")+"]"),!e&&r?t.add(n.name,n.value):o?S(t,n,u):t.add(u,n)})}function k(t){return new n(function(n){var e=new XDomainRequest,o=function(o){var r=t.respondWith(e.responseText,{status:e.status,statusText:e.statusText});n(r)};t.abort=function(){return e.abort()},e.open(t.method,t.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,e.ontimeout=function(){},e.onprogress=function(){},e.send(t.getBody())})}function H(t,n){!c(t.crossOrigin)&&I(t)&&(t.crossOrigin=!0),t.crossOrigin&&(ht||(t.client=k),delete t.emulateHTTP),n()}function I(t){var n=R.parse(R(t));return n.protocol!==ft.protocol||n.host!==ft.host}function L(t,n){t.emulateJSON&&h(t.body)&&(t.body=R.params(t.body),t.headers["Content-Type"]="application/x-www-form-urlencoded"),p(t.body)&&delete t.headers["Content-Type"],h(t.body)&&(t.body=JSON.stringify(t.body)),n(function(t){var n=t.headers["Content-Type"];if(s(n)&&0===n.indexOf("application/json"))try{t.data=t.json()}catch(e){t.data=null}else t.data=t.text()})}function q(t){return new n(function(n){var e,o,r=t.jsonp||"callback",i="_jsonp"+Math.random().toString(36).substr(2),u=null;e=function(e){var r=0;"load"===e.type&&null!==u?r=200:"error"===e.type&&(r=404),n(t.respondWith(u,{status:r})),delete window[i],document.body.removeChild(o)},t.params[r]=i,window[i]=function(t){u=JSON.stringify(t)},o=document.createElement("script"),o.src=t.getUrl(),o.type="text/javascript",o.async=!0,o.onload=e,o.onerror=e,document.body.appendChild(o)})}function N(t,n){"JSONP"==t.method&&(t.client=q),n(function(n){"JSONP"==t.method&&(n.data=n.json())})}function D(t,n){a(t.before)&&t.before.call(this,t),n()}function J(t,n){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers["X-HTTP-Method-Override"]=t.method,t.method="POST"),n()}function M(t,n){t.method=t.method.toUpperCase(),t.headers=st({},V.headers.common,t.crossOrigin?{}:V.headers.custom,V.headers[t.method.toLowerCase()],t.headers),n()}function X(t,n){var e;t.timeout&&(e=setTimeout(function(){t.abort()},t.timeout)),n(function(t){clearTimeout(e)})}function W(t){return new n(function(n){var e=new XMLHttpRequest,o=function(o){var r=t.respondWith("response"in e?e.response:e.responseText,{status:1223===e.status?204:e.status,statusText:1223===e.status?"No Content":u(e.statusText),headers:B(e.getAllResponseHeaders())});n(r)};t.abort=function(){return e.abort()},e.open(t.method,t.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,t.progress&&("GET"===t.method?e.addEventListener("progress",t.progress):/^(POST|PUT)$/i.test(t.method)&&e.upload.addEventListener("progress",t.progress)),t.credentials===!0&&(e.withCredentials=!0),m(t.headers||{},function(t,n){e.setRequestHeader(n,t)}),e.send(t.getBody())})}function B(t){var n,e,o,r={};return m(u(t).split("\n"),function(t){o=t.indexOf(":"),e=u(t.slice(0,o)),n=u(t.slice(o+1)),r[e]?ut(r[e])?r[e].push(n):r[e]=[r[e],n]:r[e]=n}),r}function F(t){function e(e){return new n(function(n){function s(){r=i.pop(),a(r)?r.call(t,e,c):(o("Invalid interceptor of type "+typeof r+", must be a function"),c())}function c(e){if(a(e))u.unshift(e);else if(f(e))return u.forEach(function(n){e=l(e,function(e){return n.call(t,e)||e})}),void l(e,n);s()}s()},t)}var r,i=[G],u=[];return f(t)||(t=null),e.use=function(t){i.push(t)},e}function G(t,n){var e=t.client||W;n(e(t))}function V(t){var e=this||{},o=F(e.$vm);return y(t||{},e.$options,V.options),V.interceptors.forEach(function(t){o.use(t)}),o(new dt(t)).then(function(t){return t.ok?t:n.reject(t)},function(t){return t instanceof Error&&r(t),n.reject(t)})}function _(t,n,e,o){var r=this||{},i={};return e=st({},_.actions,e),m(e,function(e,u){e=v({url:t,params:n||{}},o,e),i[u]=function(){return(r.$http||V)(z(e,arguments))}}),i}function z(t,n){var e,o=st({},t),r={};switch(n.length){case 2:r=n[0],e=n[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?e=n[0]:r=n[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, body], got "+n.length+" arguments"}return o.body=e,o.params=st({},o.params,r),o}function K(t){K.installed||(e(t),t.url=R,t.http=V,t.resource=_,t.Promise=n,Object.defineProperties(t.prototype,{$url:{get:function(){return d(t.url,this,this.$options.url)}},$http:{get:function(){return d(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var n=this;return function(e){return new t.Promise(e,n)}}}}))}var Q=0,Y=1,Z=2;t.reject=function(n){return new t(function(t,e){e(n)})},t.resolve=function(n){return new t(function(t,e){t(n)})},t.all=function(n){return new t(function(e,o){function r(t){return function(o){u[t]=o,i+=1,i===n.length&&e(u)}}var i=0,u=[];0===n.length&&e(u);for(var s=0;s<n.length;s+=1)t.resolve(n[s]).then(r(s),o)})},t.race=function(n){return new t(function(e,o){for(var r=0;r<n.length;r+=1)t.resolve(n[r]).then(e,o)})};var tt=t.prototype;tt.resolve=function(t){var n=this;if(n.state===Z){if(t===n)throw new TypeError("Promise settled with itself.");var e=!1;try{var o=t&&t.then;if(null!==t&&"object"==typeof t&&"function"==typeof o)return void o.call(t,function(t){e||n.resolve(t),e=!0},function(t){e||n.reject(t),e=!0})}catch(r){return void(e||n.reject(r))}n.state=Q,n.value=t,n.notify()}},tt.reject=function(t){var n=this;if(n.state===Z){if(t===n)throw new TypeError("Promise settled with itself.");n.state=Y,n.value=t,n.notify()}},tt.notify=function(){var t=this;i(function(){if(t.state!==Z)for(;t.deferred.length;){var n=t.deferred.shift(),e=n[0],o=n[1],r=n[2],i=n[3];try{t.state===Q?r("function"==typeof e?e.call(void 0,t.value):t.value):t.state===Y&&("function"==typeof o?r(o.call(void 0,t.value)):i(t.value))}catch(u){i(u)}}})},tt.then=function(n,e){var o=this;return new t(function(t,r){o.deferred.push([n,e,t,r]),o.notify()})},tt["catch"]=function(t){return this.then(void 0,t)};var nt=window.Promise||t;n.all=function(t,e){return new n(nt.all(t),e)},n.resolve=function(t,e){return new n(nt.resolve(t),e)},n.reject=function(t,e){return new n(nt.reject(t),e)},n.race=function(t,e){return new n(nt.race(t),e)};var et=n.prototype;et.bind=function(t){return this.context=t,this},et.then=function(t,e){return t&&t.bind&&this.context&&(t=t.bind(this.context)),e&&e.bind&&this.context&&(e=e.bind(this.context)),new n(this.promise.then(t,e),this.context)},et["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),new n(this.promise["catch"](t),this.context)},et["finally"]=function(t){return this.then(function(n){return t.call(this),n},function(n){return t.call(this),nt.reject(n)})};var ot=!1,rt={},it=[],ut=Array.isArray,st=Object.assign||b,ct=document.documentMode,at=document.createElement("a");R.options={url:"",root:null,params:{}},R.transforms=[U,T,w],R.params=function(t){var n=[],e=encodeURIComponent;return n.add=function(t,n){a(n)&&(n=n()),null===n&&(n=""),this.push(e(t)+"="+e(n))},S(n,t),n.join("&").replace(/%20/g,"+")},R.parse=function(t){return ct&&(at.href=t,t=at.href),at.href=t,{href:at.href,protocol:at.protocol?at.protocol.replace(/:$/,""):"",port:at.port,host:at.host,hostname:at.hostname,pathname:"/"===at.pathname.charAt(0)?at.pathname:"/"+at.pathname,search:at.search?at.search.replace(/^\?/,""):"",hash:at.hash?at.hash.replace(/^#/,""):""}};var ft=R.parse(location.href),ht="withCredentials"in new XMLHttpRequest,pt=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt=function(){function t(n,e){var o=e.url,r=e.headers,i=e.status,u=e.statusText;pt(this,t),this.url=o,this.body=n,this.headers=r||{},this.status=i||0,this.statusText=u||"",this.ok=i>=200&&i<300}return t.prototype.text=function(){return this.body},t.prototype.blob=function(){return new Blob([this.body])},t.prototype.json=function(){return JSON.parse(this.body)},t}(),dt=function(){function t(n){pt(this,t),this.method="GET",this.body=null,this.params={},this.headers={},st(this,n)}return t.prototype.getUrl=function(){return R(this)},t.prototype.getBody=function(){return this.body},t.prototype.respondWith=function(t,n){return new lt(t,st(n||{},{url:this.getUrl()}))},t}(),mt={"X-Requested-With":"XMLHttpRequest"},vt={Accept:"application/json, text/plain, */*"},yt={"Content-Type":"application/json;charset=utf-8"};return V.options={},V.headers={put:yt,post:yt,patch:yt,"delete":yt,custom:mt,common:vt},V.interceptors=[D,X,J,L,N,M,H],["get","delete","head","jsonp"].forEach(function(t){V[t]=function(n,e){return this(st(e||{},{url:n,method:t}))}}),["post","put","patch"].forEach(function(t){V[t]=function(n,e,o){return this(st(o||{},{url:n,method:t,body:e}))}}),_.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(K),K}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.VueResource=n()}(this,function(){"use strict";function t(t,n){t instanceof et?this.promise=t:this.promise=new et(t.bind(n)),this.context=n}function n(t){it=t.util,rt=t.config.debug||!t.config.silent}function e(t){"undefined"!=typeof console&&rt&&console.warn("[VueResource warn]: "+t)}function o(t){"undefined"!=typeof console&&console.error(t)}function r(t,n){return it.nextTick(t,n)}function i(t){return t.replace(/^\s*|\s*$/g,"")}function u(t){return t?t.toLowerCase():""}function s(t){return t?t.toUpperCase():""}function c(t){return"string"==typeof t}function a(t){return t===!0||t===!1}function f(t){return"function"==typeof t}function p(t){return null!==t&&"object"==typeof t}function h(t){return p(t)&&Object.getPrototypeOf(t)==Object.prototype}function l(t){return"undefined"!=typeof Blob&&t instanceof Blob}function d(t){return"undefined"!=typeof FormData&&t instanceof FormData}function m(n,e,o){var r=t.resolve(n);return arguments.length<2?r:r.then(e,o)}function y(t,n,e){return e=e||{},f(e)&&(e=e.call(n)),b(t.bind({$vm:n,$options:e}),t,{$options:e})}function v(t,n){var e,o;if(t&&"number"==typeof t.length)for(e=0;e<t.length;e++)n.call(t[e],t[e],e);else if(p(t))for(o in t)t.hasOwnProperty(o)&&n.call(t[o],t[o],o);return t}function b(t){var n=ut.call(arguments,1);return n.forEach(function(n){T(t,n,!0)}),t}function w(t){var n=ut.call(arguments,1);return n.forEach(function(n){for(var e in n)void 0===t[e]&&(t[e]=n[e])}),t}function g(t){var n=ut.call(arguments,1);return n.forEach(function(n){T(t,n)}),t}function T(t,n,e){for(var o in n)e&&(h(n[o])||st(n[o]))?(h(n[o])&&!h(t[o])&&(t[o]={}),st(n[o])&&!st(t[o])&&(t[o]=[]),T(t[o],n[o],e)):void 0!==n[o]&&(t[o]=n[o])}function x(t,n){var e=n(t);return c(t.root)&&!e.match(/^(https?:)?\//)&&(e=t.root+"/"+e),e}function E(t,n){var e=Object.keys(S.options.params),o={},r=n(t);return v(t.params,function(t,n){e.indexOf(n)===-1&&(o[n]=t)}),o=S.params(o),o&&(r+=(r.indexOf("?")==-1?"?":"&")+o),r}function j(t,n,e){var o=O(t),r=o.expand(n);return e&&e.push.apply(e,o.vars),r}function O(t){var n=["+","#",".","/",";","?","&"],e=[];return{vars:e,expand:function(o){return t.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(t,r,i){if(r){var u=null,s=[];if(n.indexOf(r.charAt(0))!==-1&&(u=r.charAt(0),r=r.substr(1)),r.split(/,/g).forEach(function(t){var n=/([^:\*]*)(?::(\d+)|(\*))?/.exec(t);s.push.apply(s,P(o,u,n[1],n[2]||n[3])),e.push(n[1])}),u&&"+"!==u){var c=",";return"?"===u?c="&":"#"!==u&&(c=u),(0!==s.length?u:"")+s.join(c)}return s.join(",")}return U(i)})}}}function P(t,n,e,o){var r=t[e],i=[];if(C(r)&&""!==r)if("string"==typeof r||"number"==typeof r||"boolean"==typeof r)r=r.toString(),o&&"*"!==o&&(r=r.substring(0,parseInt(o,10))),i.push(R(n,r,$(n)?e:null));else if("*"===o)Array.isArray(r)?r.filter(C).forEach(function(t){i.push(R(n,t,$(n)?e:null))}):Object.keys(r).forEach(function(t){C(r[t])&&i.push(R(n,r[t],t))});else{var u=[];Array.isArray(r)?r.filter(C).forEach(function(t){u.push(R(n,t))}):Object.keys(r).forEach(function(t){C(r[t])&&(u.push(encodeURIComponent(t)),u.push(R(n,r[t].toString())))}),$(n)?i.push(encodeURIComponent(e)+"="+u.join(",")):0!==u.length&&i.push(u.join(","))}else";"===n?i.push(encodeURIComponent(e)):""!==r||"&"!==n&&"?"!==n?""===r&&i.push(""):i.push(encodeURIComponent(e)+"=");return i}function C(t){return void 0!==t&&null!==t}function $(t){return";"===t||"&"===t||"?"===t}function R(t,n,e){return n="+"===t||"#"===t?U(n):encodeURIComponent(n),e?encodeURIComponent(e)+"="+n:n}function U(t){return t.split(/(%[0-9A-Fa-f]{2})/g).map(function(t){return/%[0-9A-Fa-f]/.test(t)||(t=encodeURI(t)),t}).join("")}function A(t){var n=[],e=j(t.url,t.params,n);return n.forEach(function(n){delete t.params[n]}),e}function S(t,n){var e,o=this||{},r=t;return c(t)&&(r={url:t,params:n}),r=b({},S.options,o.$options,r),S.transforms.forEach(function(t){e=I(t,e,o.$vm)}),e(r)}function I(t,n,e){return function(o){return t.call(e,o,n)}}function k(t,n,e){var o,r=st(n),i=h(n);v(n,function(n,u){o=p(n)||st(n),e&&(u=e+"["+(i||o?u:"")+"]"),!e&&r?t.add(n.name,n.value):o?k(t,n,u):t.add(u,n)})}function H(n){return new t(function(t){var e=new XDomainRequest,o=function(o){var r=n.respondWith(e.responseText,{status:e.status,statusText:e.statusText});t(r)};n.abort=function(){return e.abort()},e.open(n.method,n.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,e.ontimeout=function(){},e.onprogress=function(){},e.send(n.getBody())})}function L(t,n){!a(t.crossOrigin)&&N(t)&&(t.crossOrigin=!0),t.crossOrigin&&(ht||(t.client=H),delete t.emulateHTTP),n()}function N(t){var n=S.parse(S(t));return n.protocol!==pt.protocol||n.host!==pt.host}function q(t,n){t.emulateJSON&&h(t.body)&&(t.body=S.params(t.body),t.headers.set("Content-Type","application/x-www-form-urlencoded")),d(t.body)&&t.headers.delete("Content-Type"),h(t.body)&&(t.body=JSON.stringify(t.body)),n(function(t){return Object.defineProperty(t,"data",{get:function(){return this.body},set:function(t){this.body=t}}),t.bodyText?m(t.text(),function(n){var e=t.headers.get("Content-Type");if(c(e)&&0===e.indexOf("application/json"))try{t.body=JSON.parse(n)}catch(n){t.body=null}else t.body=n;return t}):t})}function B(n){return new t(function(t){var e,o,r=n.jsonp||"callback",i="_jsonp"+Math.random().toString(36).substr(2),u=null;e=function(e){var r=0;"load"===e.type&&null!==u?r=200:"error"===e.type&&(r=404),t(n.respondWith(u,{status:r})),delete window[i],document.body.removeChild(o)},n.params[r]=i,window[i]=function(t){u=JSON.stringify(t)},o=document.createElement("script"),o.src=n.getUrl(),o.type="text/javascript",o.async=!0,o.onload=e,o.onerror=e,document.body.appendChild(o)})}function J(t,n){"JSONP"==t.method&&(t.client=B),n(function(n){if("JSONP"==t.method)return m(n.json(),function(t){return n.body=t,n})})}function D(t,n){f(t.before)&&t.before.call(this,t),n()}function M(t,n){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers.set("X-HTTP-Method-Override",t.method),t.method="POST"),n()}function X(t,n){var e=ct({},Q.headers.common,t.crossOrigin?{}:Q.headers.custom,Q.headers[u(t.method)]);v(e,function(n,e){t.headers.has(e)||t.headers.set(e,n)}),n()}function F(t,n){var e;t.timeout&&(e=setTimeout(function(){t.abort()},t.timeout)),n(function(t){clearTimeout(e)})}function W(n){return new t(function(t){var e=new XMLHttpRequest,o=function(o){var r=n.respondWith("response"in e?e.response:e.responseText,{status:1223===e.status?204:e.status,statusText:1223===e.status?"No Content":i(e.statusText)});v(i(e.getAllResponseHeaders()).split("\n"),function(t){r.headers.append(t.slice(0,t.indexOf(":")),t.slice(t.indexOf(":")+1))}),t(r)};n.abort=function(){return e.abort()},e.open(n.method,n.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,n.progress&&("GET"===n.method?e.addEventListener("progress",n.progress):/^(POST|PUT)$/i.test(n.method)&&e.upload.addEventListener("progress",n.progress)),"responseType"in e&&(e.responseType="blob"),n.credentials===!0&&(e.withCredentials=!0),n.headers.forEach(function(t,n){e.setRequestHeader(n,t)}),e.send(n.getBody())})}function G(n){function o(o){return new t(function(t){function s(){r=i.pop(),f(r)?r.call(n,o,c):(e("Invalid interceptor of type "+typeof r+", must be a function"),c())}function c(e){if(f(e))u.unshift(e);else if(p(e))return u.forEach(function(t){e=m(e,function(e){return t.call(n,e)||e})}),void m(e,t);s()}s()},n)}var r,i=[V],u=[];return p(n)||(n=null),o.use=function(t){i.push(t)},o}function V(t,n){var e=t.client||W;n(e(t))}function _(t){if(/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return u(i(t))}function z(n){return new t(function(t){var e=new FileReader;e.readAsText(n),e.onload=function(){t(e.result)}})}function K(t){return 0===t.type.indexOf("text")||t.type.indexOf("json")!==-1}function Q(n){var e=this||{},r=G(e.$vm);return w(n||{},e.$options,Q.options),Q.interceptors.forEach(function(t){r.use(t)}),r(new yt(n)).then(function(n){return n.ok?n:t.reject(n)},function(n){return n instanceof Error&&o(n),t.reject(n)})}function Y(t){this.state=xt,this.value=void 0,this.deferred=[];var n=this;try{t(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(t){n.reject(t)}}function Z(t,n,e,o){var r=this||{},i={};return e=ct({},Z.actions,e),v(e,function(e,u){e=b({url:t,params:ct({},n)},o,e),i[u]=function(){return(r.$http||Q)(tt(e,arguments))}}),i}function tt(t,n){var e,o=ct({},t),r={};switch(n.length){case 2:r=n[0],e=n[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?e=n[0]:r=n[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, body], got "+n.length+" arguments"}return o.body=e,o.params=ct({},o.params,r),o}function nt(e){nt.installed||(n(e),e.url=S,e.http=Q,e.resource=Z,e.Promise=t,Object.defineProperties(e.prototype,{$url:{get:function(){return y(e.url,this,this.$options.url)}},$http:{get:function(){return y(e.http,this,this.$options.http)}},$resource:{get:function(){return e.resource.bind(this)}},$promise:{get:function(){var t=this;return function(n){return new e.Promise(n,t)}}}}))}var et=window.Promise;t.all=function(n,e){return new t(et.all(n),e)},t.resolve=function(n,e){return new t(et.resolve(n),e)},t.reject=function(n,e){return new t(et.reject(n),e)},t.race=function(n,e){return new t(et.race(n),e)};var ot=t.prototype;ot.bind=function(t){return this.context=t,this},ot.then=function(n,e){return n&&n.bind&&this.context&&(n=n.bind(this.context)),e&&e.bind&&this.context&&(e=e.bind(this.context)),new t(this.promise.then(n,e),this.context)},ot.catch=function(n){return n&&n.bind&&this.context&&(n=n.bind(this.context)),new t(this.promise.catch(n),this.context)},ot.finally=function(t){return this.then(function(n){return t.call(this),n},function(n){return t.call(this),et.reject(n)})};var rt=!1,it={},ut=[].slice,st=Array.isArray,ct=Object.assign||g,at=document.documentMode,ft=document.createElement("a");S.options={url:"",root:null,params:{}},S.transforms=[A,E,x],S.params=function(t){var n=[],e=encodeURIComponent;return n.add=function(t,n){f(n)&&(n=n()),null===n&&(n=""),this.push(e(t)+"="+e(n))},k(n,t),n.join("&").replace(/%20/g,"+")},S.parse=function(t){return at&&(ft.href=t,t=ft.href),ft.href=t,{href:ft.href,protocol:ft.protocol?ft.protocol.replace(/:$/,""):"",port:ft.port,host:ft.host,hostname:ft.hostname,pathname:"/"===ft.pathname.charAt(0)?ft.pathname:"/"+ft.pathname,search:ft.search?ft.search.replace(/^\?/,""):"",hash:ft.hash?ft.hash.replace(/^#/,""):""}};var pt=S.parse(location.href),ht="withCredentials"in new XMLHttpRequest,lt=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},dt=function(){function t(n){var e=this;lt(this,t),this.map={},v(n,function(t,n){return e.append(n,t)})}return t.prototype.has=function(t){return this.map.hasOwnProperty(_(t))},t.prototype.get=function(t){var n=this.map[_(t)];return n?n[0]:null},t.prototype.getAll=function(t){return this.map[_(t)]||[]},t.prototype.set=function(t,n){this.map[_(t)]=[i(n)]},t.prototype.append=function(t,n){var e=this.map[_(t)];e||(e=this.map[_(t)]=[]),e.push(i(n))},t.prototype.delete=function(t){delete this.map[_(t)]},t.prototype.forEach=function(t,n){var e=this;v(this.map,function(o,r){v(o,function(o){return t.call(n,o,r,e)})})},t}(),mt=function(){function t(n,e){var o=e.url,r=e.headers,i=e.status,u=e.statusText;lt(this,t),this.url=o,this.ok=i>=200&&i<300,this.status=i||0,this.statusText=u||"",this.headers=new dt(r),this.body=n,c(n)?this.bodyText=n:l(n)&&(this.bodyBlob=n,K(n)&&(this.bodyText=z(n)))}return t.prototype.blob=function(){return m(this.bodyBlob)},t.prototype.text=function(){return m(this.bodyText)},t.prototype.json=function(){return m(this.text(),function(t){return JSON.parse(t)})},t}(),yt=function(){function t(n){lt(this,t),this.body=null,this.params={},ct(this,n,{method:s(n.method||"GET"),headers:new dt(n.headers)})}return t.prototype.getUrl=function(){return S(this)},t.prototype.getBody=function(){return this.body},t.prototype.respondWith=function(t,n){return new mt(t,ct(n||{},{url:this.getUrl()}))},t}(),vt={"X-Requested-With":"XMLHttpRequest"},bt={Accept:"application/json, text/plain, */*"},wt={"Content-Type":"application/json;charset=utf-8"};Q.options={},Q.headers={put:wt,post:wt,patch:wt,delete:wt,custom:vt,common:bt},Q.interceptors=[D,F,M,q,J,X,L],["get","delete","head","jsonp"].forEach(function(t){Q[t]=function(n,e){return this(ct(e||{},{url:n,method:t}))}}),["post","put","patch"].forEach(function(t){Q[t]=function(n,e,o){return this(ct(o||{},{url:n,method:t,body:e}))}});var gt=0,Tt=1,xt=2;Y.reject=function(t){return new Y(function(n,e){e(t)})},Y.resolve=function(t){return new Y(function(n,e){n(t)})},Y.all=function(t){return new Y(function(n,e){function o(e){return function(o){i[e]=o,r+=1,r===t.length&&n(i)}}var r=0,i=[];0===t.length&&n(i);for(var u=0;u<t.length;u+=1)Y.resolve(t[u]).then(o(u),e)})},Y.race=function(t){return new Y(function(n,e){for(var o=0;o<t.length;o+=1)Y.resolve(t[o]).then(n,e)})};var Et=Y.prototype;return Et.resolve=function(t){var n=this;if(n.state===xt){if(t===n)throw new TypeError("Promise settled with itself.");var e=!1;try{var o=t&&t.then;if(null!==t&&"object"==typeof t&&"function"==typeof o)return void o.call(t,function(t){e||n.resolve(t),e=!0},function(t){e||n.reject(t),e=!0})}catch(t){return void(e||n.reject(t))}n.state=gt,n.value=t,n.notify()}},Et.reject=function(t){var n=this;if(n.state===xt){if(t===n)throw new TypeError("Promise settled with itself.");n.state=Tt,n.value=t,n.notify()}},Et.notify=function(){var t=this;r(function(){if(t.state!==xt)for(;t.deferred.length;){var n=t.deferred.shift(),e=n[0],o=n[1],r=n[2],i=n[3];try{t.state===gt?r("function"==typeof e?e.call(void 0,t.value):t.value):t.state===Tt&&("function"==typeof o?r(o.call(void 0,t.value)):i(t.value))}catch(t){i(t)}}})},Et.then=function(t,n){var e=this;return new Y(function(o,r){e.deferred.push([t,n,o,r]),e.notify()})},Et.catch=function(t){return this.then(void 0,t)},Z.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&(window.Promise||(window.Promise=Y),window.Vue&&window.Vue.use(nt)),nt}); |
{ | ||
"name": "vue-resource", | ||
"version": "0.9.3", | ||
"description": "A web request service for Vue.js", | ||
"version": "1.0.0", | ||
"main": "dist/vue-resource.common.js", | ||
"jsnext:main": "dist/vue-resource.es2015.js", | ||
"scripts": { | ||
"test": "webpack --config test/webpack.config.js", | ||
"build": "node build/build.js", | ||
"release": "node build/release.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuejs/vue-resource.git" | ||
}, | ||
"description": "The HTTP client for Vue.js", | ||
"homepage": "https://github.com/vuejs/vue-resource#readme", | ||
"license": "MIT", | ||
"keywords": [ | ||
"vue", | ||
"vuejs", | ||
"resource", | ||
"mvvm" | ||
"xhr", | ||
"http", | ||
"ajax" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/vuejs/vue-resource/issues" | ||
}, | ||
"homepage": "https://github.com/vuejs/vue-resource#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuejs/vue-resource.git" | ||
}, | ||
"scripts": { | ||
"test": "webpack --config test/webpack.config.js", | ||
"build": "node build/build.js", | ||
"release": "node build/release.js" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.10.4", | ||
"babel-loader": "^6.2.4", | ||
"babel-plugin-transform-runtime": "^6.9.0", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-core": "^6.14.0", | ||
"babel-loader": "^6.2.5", | ||
"babel-plugin-transform-runtime": "^6.15.0", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-es2015-loose-rollup": "^7.0.0", | ||
"babel-runtime": "^6.9.2", | ||
"jasmine-core": "^2.3.4", | ||
"replace-in-file": "^1.1.1", | ||
"rollup": "^0.33.0", | ||
"generate-release": "^0.10.1", | ||
"jasmine-core": "^2.5.0", | ||
"replace-in-file": "^2.0.1", | ||
"rollup": "^0.34.13", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"uglify-js": "^2.6.4", | ||
"uglify-js": "^2.7.3", | ||
"vue": "^1.0.26", | ||
"webpack": "^1.13.1" | ||
"webpack": "2.1.0-beta.21" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# vue-resource [![npm package](https://img.shields.io/npm/v/vue-resource.svg)](https://www.npmjs.com/package/vue-resource) | ||
# vue-resource [![Downloads](https://img.shields.io/npm/dt/vue-resource.svg)](https://www.npmjs.com/package/vue-resource) [![Version](https://img.shields.io/npm/v/vue-resource.svg)](https://www.npmjs.com/package/vue-resource) [![License](https://img.shields.io/npm/l/vue-resource.svg)](https://www.npmjs.com/package/vue-resource) | ||
@@ -10,3 +10,3 @@ The plugin for [Vue.js](http://vuejs.org) provides services for making web requests and handle responses using a [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) or JSONP. | ||
- Supports latest Firefox, Chrome, Safari, Opera and IE9+ | ||
- Compact size 12KB (4.5KB gzipped) | ||
- Compact size 14KB (5.3KB gzipped) | ||
@@ -26,7 +26,19 @@ ## Installation | ||
### CDN | ||
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/0.9.3/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [npmcdn](https://npmcdn.com/vue-resource@0.9.3/dist/vue-resource.min.js). | ||
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.0.0/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [npmcdn](https://npmcdn.com/vue-resource@1.0.0/dist/vue-resource.min.js). | ||
```html | ||
<script src="https://cdn.jsdelivr.net/vue.resource/0.9.3/vue-resource.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/vue.resource/1.0.0/vue-resource.min.js"></script> | ||
``` | ||
## Example | ||
```js | ||
{ | ||
// GET /someUrl | ||
this.$http.get('/someUrl').then((response) => { | ||
// success callback | ||
}, (response) => { | ||
// error callback | ||
}); | ||
} | ||
``` | ||
## Documentation | ||
@@ -38,2 +50,3 @@ | ||
- [Code Recipes](docs/recipes.md) | ||
- [API Reference](docs/api.md) | ||
@@ -40,0 +53,0 @@ ## Changelog |
@@ -6,3 +6,3 @@ /** | ||
import Promise from '../../promise'; | ||
import { each, trim, isArray } from '../../util'; | ||
import { each, trim } from '../../util'; | ||
@@ -17,7 +17,10 @@ export default function (request) { | ||
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText), | ||
headers: parseHeaders(xhr.getAllResponseHeaders()), | ||
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText) | ||
} | ||
); | ||
each(trim(xhr.getAllResponseHeaders()).split('\n'), (row) => { | ||
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1)); | ||
}); | ||
resolve(response); | ||
@@ -41,2 +44,6 @@ }; | ||
if ('responseType' in xhr) { | ||
xhr.responseType = 'blob'; | ||
} | ||
if (request.credentials === true) { | ||
@@ -46,4 +53,4 @@ xhr.withCredentials = true; | ||
each(request.headers || {}, (value, header) => { | ||
xhr.setRequestHeader(header, value); | ||
request.headers.forEach((value, name) => { | ||
xhr.setRequestHeader(name, value); | ||
}); | ||
@@ -54,29 +61,1 @@ | ||
} | ||
function parseHeaders(str) { | ||
var headers = {}, value, name, i; | ||
each(trim(str).split('\n'), (row) => { | ||
i = row.indexOf(':'); | ||
name = trim(row.slice(0, i)); | ||
value = trim(row.slice(i + 1)); | ||
if (headers[name]) { | ||
if (isArray(headers[name])) { | ||
headers[name].push(value); | ||
} else { | ||
headers[name] = [headers[name], value]; | ||
} | ||
} else { | ||
headers[name] = value; | ||
} | ||
}); | ||
return headers; | ||
} |
@@ -6,3 +6,3 @@ /** | ||
import Url from '../../url/index'; | ||
import { isString, isFormData, isPlainObject } from '../../util'; | ||
import { when, isString, isFormData, isPlainObject } from '../../util'; | ||
@@ -13,7 +13,7 @@ export default function (request, next) { | ||
request.body = Url.params(request.body); | ||
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); | ||
} | ||
if (isFormData(request.body)) { | ||
delete request.headers['Content-Type']; | ||
request.headers.delete('Content-Type'); | ||
} | ||
@@ -27,17 +27,35 @@ | ||
var contentType = response.headers['Content-Type']; | ||
Object.defineProperty(response, 'data', { | ||
if (isString(contentType) && contentType.indexOf('application/json') === 0) { | ||
get() { | ||
return this.body; | ||
}, | ||
try { | ||
response.data = response.json(); | ||
} catch (e) { | ||
response.data = null; | ||
set(body) { | ||
this.body = body; | ||
} | ||
} else { | ||
response.data = response.text(); | ||
} | ||
}); | ||
return response.bodyText ? when(response.text(), text => { | ||
var type = response.headers.get('Content-Type'); | ||
if (isString(type) && type.indexOf('application/json') === 0) { | ||
try { | ||
response.body = JSON.parse(text); | ||
} catch (e) { | ||
response.body = null; | ||
} | ||
} else { | ||
response.body = text; | ||
} | ||
return response; | ||
}) : response; | ||
}); | ||
} |
@@ -6,14 +6,18 @@ /** | ||
import Http from '../index'; | ||
import { assign } from '../../util'; | ||
import { assign, each, toLower } from '../../util'; | ||
export default function (request, next) { | ||
request.method = request.method.toUpperCase(); | ||
request.headers = assign({}, Http.headers.common, | ||
var headers = assign({}, Http.headers.common, | ||
!request.crossOrigin ? Http.headers.custom : {}, | ||
Http.headers[request.method.toLowerCase()], | ||
request.headers | ||
Http.headers[toLower(request.method)] | ||
); | ||
each(headers, (value, name) => { | ||
if (!request.headers.has(name)) { | ||
request.headers.set(name, value); | ||
} | ||
}); | ||
next(); | ||
} |
@@ -6,2 +6,3 @@ /** | ||
import jsonpClient from '../client/jsonp'; | ||
import { when } from '../../util'; | ||
@@ -17,3 +18,9 @@ export default function (request, next) { | ||
if (request.method == 'JSONP') { | ||
response.data = response.json(); | ||
return when(response.json(), json => { | ||
response.body = json; | ||
return response; | ||
}); | ||
} | ||
@@ -20,0 +27,0 @@ |
@@ -8,3 +8,3 @@ /** | ||
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { | ||
request.headers['X-HTTP-Method-Override'] = request.method; | ||
request.headers.set('X-HTTP-Method-Override', request.method); | ||
request.method = 'POST'; | ||
@@ -11,0 +11,0 @@ } |
@@ -6,4 +6,5 @@ /** | ||
import Url from '../url/index'; | ||
import Headers from './headers'; | ||
import Response from './response'; | ||
import { assign } from '../util'; | ||
import { assign, toUpper } from '../util'; | ||
@@ -14,8 +15,9 @@ export default class Request { | ||
this.method = 'GET'; | ||
this.body = null; | ||
this.params = {}; | ||
this.headers = {}; | ||
assign(this, options); | ||
assign(this, options, { | ||
method: toUpper(options.method || 'GET'), | ||
headers: new Headers(options.headers) | ||
}); | ||
} | ||
@@ -22,0 +24,0 @@ |
@@ -5,2 +5,6 @@ /** | ||
import Headers from './headers'; | ||
import Promise from '../promise'; | ||
import { when, isBlob, isString } from '../util'; | ||
export default class Response { | ||
@@ -11,22 +15,51 @@ | ||
this.url = url; | ||
this.body = body; | ||
this.headers = headers || {}; | ||
this.ok = status >= 200 && status < 300; | ||
this.status = status || 0; | ||
this.statusText = statusText || ''; | ||
this.ok = status >= 200 && status < 300; | ||
this.headers = new Headers(headers); | ||
this.body = body; | ||
} | ||
if (isString(body)) { | ||
text() { | ||
return this.body; | ||
this.bodyText = body; | ||
} else if (isBlob(body)) { | ||
this.bodyBlob = body; | ||
if (isBlobText(body)) { | ||
this.bodyText = blobText(body); | ||
} | ||
} | ||
} | ||
blob() { | ||
return new Blob([this.body]); | ||
return when(this.bodyBlob); | ||
} | ||
text() { | ||
return when(this.bodyText); | ||
} | ||
json() { | ||
return JSON.parse(this.body); | ||
return when(this.text(), text => JSON.parse(text)); | ||
} | ||
} | ||
function blobText(body) { | ||
return new Promise((resolve) => { | ||
var reader = new FileReader(); | ||
reader.readAsText(body); | ||
reader.onload = () => { | ||
resolve(reader.result); | ||
}; | ||
}); | ||
} | ||
function isBlobText(body) { | ||
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1; | ||
} |
@@ -8,2 +8,3 @@ /** | ||
import Promise from './promise'; | ||
import PromiseLib from './lib/promise'; | ||
import Resource from './resource'; | ||
@@ -54,6 +55,14 @@ import Util, { options } from './util'; | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin); | ||
if (typeof window !== 'undefined') { | ||
if (!window.Promise) { | ||
window.Promise = PromiseLib; | ||
} | ||
if (window.Vue) { | ||
window.Vue.use(plugin); | ||
} | ||
} | ||
export default plugin; |
@@ -5,6 +5,4 @@ /** | ||
import PromiseLib from './lib/promise'; | ||
var PromiseObj = window.Promise; | ||
var PromiseObj = window.Promise || PromiseLib; | ||
export default function Promise(executor, context) { | ||
@@ -11,0 +9,0 @@ |
@@ -19,3 +19,3 @@ /** | ||
action = merge({url, params: params || {}}, options, action); | ||
action = merge({url, params: assign({}, params)}, options, action); | ||
@@ -22,0 +22,0 @@ resource[name] = function () { |
@@ -7,3 +7,3 @@ /** | ||
var debug = false, util = {}, array = []; | ||
var debug = false, util = {}, { slice } = []; | ||
@@ -35,2 +35,10 @@ export default function (Vue) { | ||
export function toLower(str) { | ||
return str ? str.toLowerCase() : ''; | ||
} | ||
export function toUpper(str) { | ||
return str ? str.toUpperCase() : ''; | ||
} | ||
export const isArray = Array.isArray; | ||
@@ -58,2 +66,6 @@ | ||
export function isBlob(obj) { | ||
return typeof Blob !== 'undefined' && obj instanceof Blob; | ||
} | ||
export function isFormData(obj) { | ||
@@ -89,3 +101,3 @@ return typeof FormData !== 'undefined' && obj instanceof FormData; | ||
if (typeof obj.length == 'number') { | ||
if (obj && typeof obj.length == 'number') { | ||
for (i = 0; i < obj.length; i++) { | ||
@@ -109,3 +121,3 @@ iterator.call(obj[i], obj[i], i); | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -121,3 +133,3 @@ args.forEach((source) => { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -139,3 +151,3 @@ args.forEach((source) => { | ||
var args = array.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
@@ -142,0 +154,0 @@ args.forEach((source) => { |
@@ -11,6 +11,5 @@ import Vue from 'vue'; | ||
expect(res.status).toBe(200); | ||
expect(res.data).toBe('text'); | ||
expect(res.blob() instanceof Blob).toBe(true); | ||
expect(res.headers['Content-Type']).toBe('text/plain'); | ||
expect(res.headers['Content-Length']).toBe('4'); | ||
expect(res.body).toBe('text'); | ||
expect(res.headers.get('Content-Type')).toBe('text/plain'); | ||
expect(res.headers.get('Content-Length')).toBe('4'); | ||
@@ -28,4 +27,4 @@ done(); | ||
expect(res.status).toBe(200); | ||
expect(res.data.foo).toBe('bar'); | ||
expect(typeof res.json()).toBe('object'); | ||
expect(typeof res.body).toBe('object'); | ||
expect(res.body.foo).toBe('bar'); | ||
@@ -43,3 +42,3 @@ done(); | ||
expect(res.status).toBe(200); | ||
expect(res.data).toBeNull(); | ||
expect(res.body).toBeNull(); | ||
@@ -51,2 +50,16 @@ done(); | ||
it('get("github.com/avatar")', (done) => { | ||
Vue.http.get('https://avatars1.githubusercontent.com/u/6128107').then((res) => { | ||
expect(res.ok).toBe(true); | ||
expect(res.status).toBe(200); | ||
expect(res.body instanceof Blob).toBe(true); | ||
expect(res.body.type).toBe('image/png'); | ||
done(); | ||
}); | ||
}); | ||
it('get("cors-api.appspot.com")', (done) => { | ||
@@ -58,5 +71,5 @@ | ||
expect(res.status).toBe(200); | ||
expect(res.data.shift().requestType).toBe('cors'); | ||
expect(res.headers['Content-Type']).toBe('application/json'); | ||
expect(typeof res.json()).toBe('object'); | ||
expect(typeof res.body).toBe('object'); | ||
expect(res.body.shift().requestType).toBe('cors'); | ||
expect(res.headers.get('Content-Type')).toBe('application/json'); | ||
@@ -74,4 +87,4 @@ done(); | ||
expect(res.status).toBe(200); | ||
expect(res.data.foo).toBe('bar'); | ||
expect(typeof res.json()).toBe('object'); | ||
expect(typeof res.body).toBe('object'); | ||
expect(res.body.foo).toBe('bar'); | ||
@@ -98,4 +111,4 @@ done(); | ||
expect(res.status).toBe(200); | ||
expect(res.data.foo).toBe('bar'); | ||
expect(typeof res.json()).toBe('object'); | ||
expect(typeof res.body).toBe('object'); | ||
expect(res.body.foo).toBe('bar'); | ||
@@ -102,0 +115,0 @@ done(); |
@@ -9,5 +9,5 @@ module.exports = { | ||
loaders: [ | ||
{test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015-loose']}} | ||
{test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: [['es2015', {modules: false}]]}} | ||
] | ||
} | ||
}; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
44
0
61
376317
11488