From 1e472bc223434f4006b5b02bb94ce00fa1ea85c9 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sat, 11 Jun 2016 16:06:20 +0200 Subject: [PATCH 1/7] IE9 status 1223 bug, fixes #288 --- src/http/client/xdr.js | 2 +- src/http/client/xhr.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http/client/xdr.js b/src/http/client/xdr.js index 456df31d..f9171dbd 100644 --- a/src/http/client/xdr.js +++ b/src/http/client/xdr.js @@ -20,7 +20,7 @@ module.exports = function (request) { response.data = xdr.responseText; response.status = xdr.status; - response.statusText = xdr.statusText; + response.statusText = xdr.statusText || ''; resolve(response); }; diff --git a/src/http/client/xhr.js b/src/http/client/xhr.js index 8ab6b5e1..4e9da225 100644 --- a/src/http/client/xhr.js +++ b/src/http/client/xhr.js @@ -18,9 +18,9 @@ module.exports = function (request) { handler = function (event) { - response.data = xhr.responseText; - response.status = xhr.status; - response.statusText = xhr.statusText; + response.data = ('response' in xhr) ? xhr.response : xhr.responseText; + response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug + response.statusText = xhr.statusText || ''; response.headers = xhr.getAllResponseHeaders(); resolve(response); From e09888e7761c97696af386f37d65c2f31e8c4f93 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 11:06:36 +0200 Subject: [PATCH 2/7] shiny es6 modules :tada: --- build/build.js | 74 +++++++++++++++++++++++++++ build/webpack.build.config.js | 67 ------------------------ package.json | 10 ++-- src/http/before.js | 8 +-- src/http/client/index.js | 22 ++++---- src/http/client/jsonp.js | 10 ++-- src/http/client/xdr.js | 10 ++-- src/http/client/xhr.js | 21 ++++---- src/http/cors.js | 17 ++++--- src/http/header.js | 17 ++++--- src/http/index.js | 48 +++++++++--------- src/http/interceptor.js | 14 +++--- src/http/jsonp.js | 6 ++- src/http/method.js | 4 +- src/http/mime.js | 15 +++--- src/http/timeout.js | 4 +- src/index.js | 26 +++++----- src/lib/promise.js | 14 +++--- src/lib/url-template.js | 66 ++++++++++++------------ src/promise.js | 16 +++--- src/resource.js | 27 +++++----- src/url/index.js | 44 ++++++++-------- src/url/legacy.js | 8 +-- src/url/query.js | 13 ++--- src/url/root.js | 8 +-- src/url/template.js | 8 +-- src/util.js | 95 +++++++++++++++++++---------------- test/http.js | 2 +- test/index.js | 7 ++- test/promise.js | 5 +- test/url.js | 2 +- 31 files changed, 360 insertions(+), 328 deletions(-) create mode 100644 build/build.js delete mode 100644 build/webpack.build.config.js diff --git a/build/build.js b/build/build.js new file mode 100644 index 00000000..4d63191f --- /dev/null +++ b/build/build.js @@ -0,0 +1,74 @@ +var fs = require('fs'); +var rollup = require('rollup'); +var uglify = require('uglify-js'); +var babel = require('rollup-plugin-babel'); +var package = require('../package.json'); +var version = process.env.VERSION || package.version; +var banner = + "/*!\n" + + " * vue-resource v" + version + "\n" + + " * https://github.com/vuejs/vue-resource\n" + + " * Released under the MIT License.\n" + + " */\n"; + +// Standalone +rollup.rollup({ + entry: 'src/index.js', + plugins: [ + babel({ + presets: ['es2015-rollup'] + }) + ] +}) +.then(function (bundle) { + return write('dist/vue-resource.js', bundle.generate({ + format: 'umd', + banner: banner, + moduleName: 'VueResource' + }).code); +}) +.then(function () { + return write( + 'dist/vue-resource.min.js', + banner + '\n' + uglify.minify('dist/vue-resource.js').code + ); +}) +.catch(logError); + +// CommonJS +rollup.rollup({ + entry: 'src/index.js', + plugins: [ + babel({ + presets: ['es2015-rollup'] + }) + ] +}) +.then(function (bundle) { + return write('dist/vue-resource.common.js', bundle.generate({ + format: 'cjs', + banner: banner + }).code); +}); + +function write (dest, code) { + return new Promise(function (resolve, reject) { + fs.writeFile(dest, code, function (err) { + if (err) return reject(err); + console.log(blue(dest) + ' ' + getSize(code)); + resolve(); + }); + }); +} + +function getSize (code) { + return (code.length / 1024).toFixed(2) + 'kb'; +} + +function logError (e) { + console.log(e); +} + +function blue (str) { + return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'; +} diff --git a/build/webpack.build.config.js b/build/webpack.build.config.js deleted file mode 100644 index 65608530..00000000 --- a/build/webpack.build.config.js +++ /dev/null @@ -1,67 +0,0 @@ -var webpack = require("webpack"); -var version = require("../package.json").version; -var banner = - "/**\n" + - " * vue-resource v" + version + "\n" + - " * https://github.com/vuejs/vue-resource\n" + - " * Released under the MIT License.\n" + - " */\n"; - -module.exports = [ - - { - entry: "./src/index", - output: { - path: "./dist", - filename: "vue-resource.js", - library: "VueResource", - libraryTarget: "umd" - }, - module: { - loaders: [ - {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015']}} - ] - }, - plugins: [ - new webpack.BannerPlugin(banner, {raw: true}) - ] - }, - - { - entry: "./src/index", - output: { - path: "./dist", - filename: "vue-resource.common.js", - library: "VueResource", - libraryTarget: "commonjs2" - }, - module: { - loaders: [ - {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015']}} - ] - }, - plugins: [ - new webpack.BannerPlugin(banner, {raw: true}) - ] - }, - - { - entry: "./src/index", - output: { - path: "./dist", - filename: "vue-resource.min.js", - library: "VueResource", - libraryTarget: "umd" - }, - module: { - loaders: [ - {test: /.js/, exclude: /node_modules/, loader: 'babel', query: {presets: ['es2015']}} - ] - }, - plugins: [ - new webpack.optimize.UglifyJsPlugin, - new webpack.BannerPlugin(banner, {raw: true}) - ] - } - -]; diff --git a/package.json b/package.json index 2fe02d8a..06715d95 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A web request service for Vue.js", "main": "dist/vue-resource.common.js", "scripts": { - "build": "webpack --config build/webpack.build.config.js", + "build": "node build/build.js", "test": "webpack --config test/webpack.config.js" }, "repository": { @@ -23,12 +23,16 @@ }, "homepage": "https://github.com/vuejs/vue-resource#readme", "devDependencies": { - "babel-core": "^6.9.0", + "babel-core": "^6.9.1", "babel-loader": "^6.2.4", "babel-plugin-transform-runtime": "^6.9.0", "babel-preset-es2015": "^6.9.0", - "babel-runtime": "^6.9.0", + "babel-preset-es2015-rollup": "^1.1.1", + "babel-runtime": "^6.9.2", "jasmine-core": "^2.3.4", + "rollup": "^0.31.1", + "rollup-plugin-babel": "^2.5.1", + "uglify-js": "^2.6.2", "vue": "^1.0.24", "webpack": "^1.13.1" } diff --git a/src/http/before.js b/src/http/before.js index 9741edc3..f2041c4b 100644 --- a/src/http/before.js +++ b/src/http/before.js @@ -2,13 +2,13 @@ * Before Interceptor. */ -var _ = require('../util'); +import { isFunction } from '../util'; -module.exports = { +const exports = { request: function (request) { - if (_.isFunction(request.beforeSend)) { + if (isFunction(request.beforeSend)) { request.beforeSend.call(this, request); } @@ -16,3 +16,5 @@ module.exports = { } }; + +export default exports; diff --git a/src/http/client/index.js b/src/http/client/index.js index 4690900d..2cd3194b 100644 --- a/src/http/client/index.js +++ b/src/http/client/index.js @@ -2,11 +2,11 @@ * Base client. */ -var _ = require('../../util'); -var Promise = require('../../promise'); -var xhrClient = require('./xhr'); +import Promise from '../../promise'; +import xhrClient from './xhr'; +import { each, trim, isArray, isString, toLower } from '../../util'; -module.exports = function (request) { +export default function (request) { var response = (request.client || xhrClient)(request); @@ -19,7 +19,7 @@ module.exports = function (request) { response.headers = function (name) { if (name) { - return headers[_.toLower(name)]; + return headers[toLower(name)]; } return headers; @@ -32,22 +32,22 @@ module.exports = function (request) { return response; }); -}; +} function parseHeaders(str) { var headers = {}, value, name, i; - if (_.isString(str)) { - _.each(str.split('\n'), function (row) { + if (isString(str)) { + each(str.split('\n'), function (row) { i = row.indexOf(':'); - name = _.trim(_.toLower(row.slice(0, i))); - value = _.trim(row.slice(i + 1)); + name = trim(toLower(row.slice(0, i))); + value = trim(row.slice(i + 1)); if (headers[name]) { - if (_.isArray(headers[name])) { + if (isArray(headers[name])) { headers[name].push(value); } else { headers[name] = [headers[name], value]; diff --git a/src/http/client/jsonp.js b/src/http/client/jsonp.js index 7b834c6d..14464ba0 100644 --- a/src/http/client/jsonp.js +++ b/src/http/client/jsonp.js @@ -2,10 +2,10 @@ * JSONP client. */ -var _ = require('../../util'); -var Promise = require('../../promise'); +import Url from '../../url/index'; +import Promise from '../../promise'; -module.exports = function (request) { +export default function (request) { return new Promise(function (resolve) { var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {request: request, data: null}, handler, script; @@ -16,7 +16,7 @@ module.exports = function (request) { }; script = document.createElement('script'); - script.src = _.url(request); + script.src = Url(request); script.type = 'text/javascript'; script.async = true; @@ -45,4 +45,4 @@ module.exports = function (request) { document.body.appendChild(script); }); -}; +} diff --git a/src/http/client/xdr.js b/src/http/client/xdr.js index f9171dbd..eb470e5f 100644 --- a/src/http/client/xdr.js +++ b/src/http/client/xdr.js @@ -2,10 +2,10 @@ * XDomain client (Internet Explorer). */ -var _ = require('../../util'); -var Promise = require('../../promise'); +import Url from '../../url/index'; +import Promise from '../../promise'; -module.exports = function (request) { +export default function (request) { return new Promise(function (resolve) { var xdr = new XDomainRequest(), response = {request: request}, handler; @@ -14,7 +14,7 @@ module.exports = function (request) { xdr.abort(); }; - xdr.open(request.method, _.url(request), true); + xdr.open(request.method, Url(request), true); handler = function (event) { @@ -34,4 +34,4 @@ module.exports = function (request) { xdr.send(request.data); }); -}; +} diff --git a/src/http/client/xhr.js b/src/http/client/xhr.js index 4e9da225..1bc9bbda 100644 --- a/src/http/client/xhr.js +++ b/src/http/client/xhr.js @@ -2,10 +2,11 @@ * XMLHttp client. */ -var _ = require('../../util'); -var Promise = require('../../promise'); +import Url from '../../url/index'; +import Promise from '../../promise'; +import { each, extend, isPlainObject } from '../../util'; -module.exports = function (request) { +export default function (request) { return new Promise(function (resolve) { var xhr = new XMLHttpRequest(), response = {request: request}, handler; @@ -14,7 +15,7 @@ module.exports = function (request) { xhr.abort(); }; - xhr.open(request.method, _.url(request), true); + xhr.open(request.method, Url(request), true); handler = function (event) { @@ -33,18 +34,18 @@ module.exports = function (request) { xhr.ontimeout = function () {}; xhr.onprogress = function () {}; - if (_.isPlainObject(request.xhr)) { - _.extend(xhr, request.xhr); + if (isPlainObject(request.xhr)) { + extend(xhr, request.xhr); } - if (_.isPlainObject(request.upload)) { - _.extend(xhr.upload, request.upload); + if (isPlainObject(request.upload)) { + extend(xhr.upload, request.upload); } - _.each(request.headers || {}, function (value, header) { + each(request.headers || {}, function (value, header) { xhr.setRequestHeader(header, value); }); xhr.send(request.data); }); -}; +} diff --git a/src/http/cors.js b/src/http/cors.js index fb89be3a..e4850c2d 100644 --- a/src/http/cors.js +++ b/src/http/cors.js @@ -2,12 +2,13 @@ * CORS Interceptor. */ -var _ = require('../util'); -var xdrClient = require('./client/xdr'); -var xhrCors = 'withCredentials' in new XMLHttpRequest(); -var originUrl = _.url.parse(location.href); +import Url from '../url/index'; +import xdrClient from './client/xdr'; -module.exports = { +const originUrl = Url.parse(location.href); +const supportCors = 'withCredentials' in new XMLHttpRequest(); + +const exports = { request: function (request) { @@ -17,7 +18,7 @@ module.exports = { if (request.crossOrigin) { - if (!xhrCors) { + if (!supportCors) { request.client = xdrClient; } @@ -31,7 +32,9 @@ module.exports = { function crossOrigin(request) { - var requestUrl = _.url.parse(_.url(request)); + var requestUrl = Url.parse(Url(request)); return (requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host); } + +export default exports; diff --git a/src/http/header.js b/src/http/header.js index 0fd88503..327eeb5a 100644 --- a/src/http/header.js +++ b/src/http/header.js @@ -2,21 +2,22 @@ * Header Interceptor. */ -var _ = require('../util'); +import Http from './index'; +import { extend, isPlainObject } from '../util'; -module.exports = { +const exports = { request: function (request) { request.method = request.method.toUpperCase(); - request.headers = _.extend({}, _.http.headers.common, - !request.crossOrigin ? _.http.headers.custom : {}, - _.http.headers[request.method.toLowerCase()], + request.headers = extend({}, Http.headers.common, + !request.crossOrigin ? Http.headers.custom : {}, + Http.headers[request.method.toLowerCase()], request.headers ); - if (_.isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { - _.extend(request.params, request.data); + if (isPlainObject(request.data) && /^(GET|JSONP)$/i.test(request.method)) { + extend(request.params, request.data); delete request.data; } @@ -24,3 +25,5 @@ module.exports = { } }; + +export default exports; diff --git a/src/http/index.js b/src/http/index.js index cd2a119a..6ddd086f 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -2,13 +2,21 @@ * Service for sending network requests. */ -var _ = require('../util'); -var Client = require('./client'); -var Promise = require('../promise'); -var interceptor = require('./interceptor'); -var jsonType = {'Content-Type': 'application/json'}; - -function Http(url, options) { +const jsonType = {'Content-Type': 'application/json'}; + +import cors from './cors'; +import mime from './mime'; +import jsonp from './jsonp'; +import before from './before'; +import method from './method'; +import header from './header'; +import timeout from './timeout'; +import interceptor from './interceptor'; +import Client from './client/index'; +import Promise from '../promise'; +import { error, extend, merge, isFunction, isObject } from '../util'; + +export default function Http(url, options) { var self = this || {}, client = Client, request, promise; @@ -16,8 +24,8 @@ function Http(url, options) { client = interceptor(handler, self.$vm)(client); }); - options = _.isObject(url) ? url : _.extend({url: url}, options); - request = _.merge({}, Http.options, self.$options, options); + options = isObject(url) ? url : extend({url: url}, options); + request = merge({}, Http.options, self.$options, options); promise = client(request).bind(self.$vm).then((response) => { return response.ok ? response : Promise.reject(response); @@ -25,7 +33,7 @@ function Http(url, options) { }, (response) => { if (response instanceof Error) { - _.error(response); + error(response); } return Promise.reject(response); @@ -57,16 +65,6 @@ Http.options = { timeout: 0 }; -Http.interceptors = [ - require('./before'), - require('./timeout'), - require('./jsonp'), - require('./method'), - require('./mime'), - require('./header'), - require('./cors') -]; - Http.headers = { put: jsonType, post: jsonType, @@ -76,23 +74,23 @@ Http.headers = { custom: {'X-Requested-With': 'XMLHttpRequest'} }; +Http.interceptors = [before, timeout, jsonp, method, mime, header, cors]; + ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { Http[method] = function (url, data, success, options) { - if (_.isFunction(data)) { + if (isFunction(data)) { options = success; success = data; data = undefined; } - if (_.isObject(success)) { + if (isObject(success)) { options = success; success = undefined; } - return this(url, _.extend({method: method, data: data, success: success}, options)); + return this(url, extend({method: method, data: data, success: success}, options)); }; }); - -module.exports = _.http = Http; diff --git a/src/http/interceptor.js b/src/http/interceptor.js index 4851d18d..4c0c5b4a 100644 --- a/src/http/interceptor.js +++ b/src/http/interceptor.js @@ -2,27 +2,27 @@ * Interceptor factory. */ -var _ = require('../util'); -var Promise = require('../promise'); +import Promise from '../promise'; +import { isFunction } from '../util'; -module.exports = function (handler, vm) { +export default function (handler, vm) { return function (client) { - if (_.isFunction(handler)) { + if (isFunction(handler)) { handler = handler.call(vm, Promise); } return function (request) { - if (_.isFunction(handler.request)) { + if (isFunction(handler.request)) { request = handler.request.call(vm, request); } return when(request, function (request) { return when(client(request), function (response) { - if (_.isFunction(handler.response)) { + if (isFunction(handler.response)) { response = handler.response.call(vm, response); } @@ -31,7 +31,7 @@ module.exports = function (handler, vm) { }); }; }; -}; +} function when(value, fulfilled, rejected) { diff --git a/src/http/jsonp.js b/src/http/jsonp.js index 6f5fd5b7..7326dd06 100644 --- a/src/http/jsonp.js +++ b/src/http/jsonp.js @@ -2,9 +2,9 @@ * JSONP Interceptor. */ -var jsonpClient = require('./client/jsonp'); +import jsonpClient from './client/jsonp'; -module.exports = { +const exports = { request: function (request) { @@ -16,3 +16,5 @@ module.exports = { } }; + +export default exports; diff --git a/src/http/method.js b/src/http/method.js index 1a305084..b341800a 100644 --- a/src/http/method.js +++ b/src/http/method.js @@ -2,7 +2,7 @@ * HTTP method override Interceptor. */ -module.exports = { +const exports = { request: function (request) { @@ -15,3 +15,5 @@ module.exports = { } }; + +export default exports; diff --git a/src/http/mime.js b/src/http/mime.js index b14434a1..5f10041b 100644 --- a/src/http/mime.js +++ b/src/http/mime.js @@ -2,22 +2,23 @@ * Mime Interceptor. */ -var _ = require('../util'); +import Url from '../url/index'; +import { isObject, isPlainObject } from '../util'; -module.exports = { +const exports = { request: function (request) { - if (request.emulateJSON && _.isPlainObject(request.data)) { + if (request.emulateJSON && isPlainObject(request.data)) { request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - request.data = _.url.params(request.data); + request.data = Url.params(request.data); } - if (_.isObject(request.data) && /FormData/i.test(request.data.toString())) { + if (isObject(request.data) && /FormData/i.test(request.data.toString())) { delete request.headers['Content-Type']; } - if (_.isPlainObject(request.data)) { + if (isPlainObject(request.data)) { request.data = JSON.stringify(request.data); } @@ -34,3 +35,5 @@ module.exports = { } }; + +export default exports; diff --git a/src/http/timeout.js b/src/http/timeout.js index 069c92c6..e66a89b9 100644 --- a/src/http/timeout.js +++ b/src/http/timeout.js @@ -2,7 +2,7 @@ * Timeout Interceptor. */ -module.exports = function () { +const exports = function () { var timeout; @@ -28,3 +28,5 @@ module.exports = function () { }; }; + +export default exports; diff --git a/src/index.js b/src/index.js index 852d7236..fb4a40af 100644 --- a/src/index.js +++ b/src/index.js @@ -2,34 +2,36 @@ * Install plugin. */ +import Url from './url/index'; +import Http from './http/index'; +import Promise from './promise'; +import Resource from './resource'; +import Util, { options } from './util'; + function plugin(Vue) { if (plugin.installed) { return; } - var _ = require('./util'); - - _.config = Vue.config; - _.warning = Vue.util.warn; - _.nextTick = Vue.util.nextTick; + Util(Vue); - Vue.url = require('./url'); - Vue.http = require('./http'); - Vue.resource = require('./resource'); - Vue.Promise = require('./promise'); + Vue.url = Url; + Vue.http = Http; + Vue.resource = Resource; + Vue.Promise = Promise; Object.defineProperties(Vue.prototype, { $url: { get() { - return _.options(Vue.url, this, this.$options.url); + return options(Vue.url, this, this.$options.url); } }, $http: { get() { - return _.options(Vue.http, this, this.$options.http); + return options(Vue.http, this, this.$options.http); } }, @@ -52,4 +54,4 @@ if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); } -module.exports = plugin; +export default plugin; diff --git a/src/lib/promise.js b/src/lib/promise.js index eb1b2649..ee8c69e0 100644 --- a/src/lib/promise.js +++ b/src/lib/promise.js @@ -2,13 +2,13 @@ * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) */ -var _ = require('../util'); +const RESOLVED = 0; +const REJECTED = 1; +const PENDING = 2; -var RESOLVED = 0; -var REJECTED = 1; -var PENDING = 2; +import { nextTick } from '../util'; -function Promise(executor) { +export default function Promise(executor) { this.state = PENDING; this.value = undefined; @@ -132,7 +132,7 @@ p.reject = function reject(reason) { p.notify = function notify() { var promise = this; - _.nextTick(function () { + nextTick(function () { if (promise.state !== PENDING) { while (promise.deferred.length) { var deferred = promise.deferred.shift(), @@ -175,5 +175,3 @@ p.then = function then(onResolved, onRejected) { p.catch = function (onRejected) { return this.then(undefined, onRejected); }; - -module.exports = Promise; diff --git a/src/lib/url-template.js b/src/lib/url-template.js index 803388b4..9345eac1 100644 --- a/src/lib/url-template.js +++ b/src/lib/url-template.js @@ -2,18 +2,18 @@ * URL Template v2.0.6 (https://github.com/bramstein/url-template) */ -exports.expand = function (url, params, variables) { +export function expand(url, params, variables) { - var tmpl = this.parse(url), expanded = tmpl.expand(params); + var tmpl = parse(url), expanded = tmpl.expand(params); if (variables) { variables.push.apply(variables, tmpl.vars); } return expanded; -}; +} -exports.parse = function (template) { +export function parse(template) { var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = []; @@ -32,7 +32,7 @@ exports.parse = function (template) { expression.split(/,/g).forEach(function (variable) { var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push.apply(values, exports.getValues(context, operator, tmp[1], tmp[2] || tmp[3])); + values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3])); variables.push(tmp[1]); }); @@ -52,18 +52,18 @@ exports.parse = function (template) { } } else { - return exports.encodeReserved(literal); + return encodeReserved(literal); } }); } }; -}; +} -exports.getValues = function (context, operator, key, modifier) { +function getValues(context, operator, key, modifier) { var value = context[key], result = []; - if (this.isDefined(value) && value !== '') { + if (isDefined(value) && value !== '') { if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { value = value.toString(); @@ -71,37 +71,37 @@ exports.getValues = function (context, operator, key, modifier) { value = value.substring(0, parseInt(modifier, 10)); } - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); + result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); } else { if (modifier === '*') { if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); - }, this); + value.filter(isDefined).forEach(function (value) { + result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); + }); } else { Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { - result.push(this.encodeValue(operator, value[k], k)); + if (isDefined(value[k])) { + result.push(encodeValue(operator, value[k], k)); } - }, this); + }); } } else { var tmp = []; if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - tmp.push(this.encodeValue(operator, value)); - }, this); + value.filter(isDefined).forEach(function (value) { + tmp.push(encodeValue(operator, value)); + }); } else { Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { + if (isDefined(value[k])) { tmp.push(encodeURIComponent(k)); - tmp.push(this.encodeValue(operator, value[k].toString())); + tmp.push(encodeValue(operator, value[k].toString())); } - }, this); + }); } - if (this.isKeyOperator(operator)) { + if (isKeyOperator(operator)) { result.push(encodeURIComponent(key) + '=' + tmp.join(',')); } else if (tmp.length !== 0) { result.push(tmp.join(',')); @@ -119,32 +119,32 @@ exports.getValues = function (context, operator, key, modifier) { } return result; -}; +} -exports.isDefined = function (value) { +function isDefined(value) { return value !== undefined && value !== null; -}; +} -exports.isKeyOperator = function (operator) { +function isKeyOperator(operator) { return operator === ';' || operator === '&' || operator === '?'; -}; +} -exports.encodeValue = function (operator, value, key) { +function encodeValue(operator, value, key) { - value = (operator === '+' || operator === '#') ? this.encodeReserved(value) : encodeURIComponent(value); + value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value); if (key) { return encodeURIComponent(key) + '=' + value; } else { return value; } -}; +} -exports.encodeReserved = function (str) { +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(''); -}; +} diff --git a/src/promise.js b/src/promise.js index 9a68ff6f..bfd35476 100644 --- a/src/promise.js +++ b/src/promise.js @@ -2,10 +2,12 @@ * Promise adapter. */ -var _ = require('./util'); -var PromiseObj = window.Promise || require('./lib/promise'); +import { warn } from './util'; +import PromiseLib from './lib/promise'; -function Promise(executor, context) { +var PromiseObj = window.Promise || PromiseLib; + +export default function Promise(executor, context) { if (executor instanceof PromiseObj) { this.promise = executor; @@ -79,7 +81,7 @@ p.finally = function (callback) { p.success = function (callback) { - _.warn('The `success` method has been deprecated. Use the `then` method instead.'); + warn('The `success` method has been deprecated. Use the `then` method instead.'); return this.then(function (response) { return callback.call(this, response.data, response.status, response) || response; @@ -88,7 +90,7 @@ p.success = function (callback) { p.error = function (callback) { - _.warn('The `error` method has been deprecated. Use the `catch` method instead.'); + warn('The `error` method has been deprecated. Use the `catch` method instead.'); return this.catch(function (response) { return callback.call(this, response.data, response.status, response) || response; @@ -97,7 +99,7 @@ p.error = function (callback) { p.always = function (callback) { - _.warn('The `always` method has been deprecated. Use the `finally` method instead.'); + warn('The `always` method has been deprecated. Use the `finally` method instead.'); var cb = function (response) { return callback.call(this, response.data, response.status, response) || response; @@ -105,5 +107,3 @@ p.always = function (callback) { return this.then(cb, cb); }; - -module.exports = Promise; diff --git a/src/resource.js b/src/resource.js index 5ad20dc0..d69c7600 100644 --- a/src/resource.js +++ b/src/resource.js @@ -2,23 +2,24 @@ * Service for interacting with RESTful services. */ -var _ = require('./util'); +import Http from './http/index'; +import { each, extend, merge, isFunction } from './util'; -function Resource(url, params, actions, options) { +export default function Resource(url, params, actions, options) { - var self = this, resource = {}; + var self = this || {}, resource = {}; - actions = _.extend({}, + actions = extend({}, Resource.actions, actions ); - _.each(actions, function (action, name) { + each(actions, function (action, name) { - action = _.merge({url: url, params: params || {}}, options, action); + action = merge({url: url, params: params || {}}, options, action); resource[name] = function () { - return (self.$http || _.http)(opts(action, arguments)); + return (self.$http || Http)(opts(action, arguments)); }; }); @@ -27,7 +28,7 @@ function Resource(url, params, actions, options) { function opts(action, args) { - var options = _.extend({}, action), params = {}, data, success, error; + var options = extend({}, action), params = {}, data, success, error; switch (args.length) { @@ -39,9 +40,9 @@ function opts(action, args) { case 3: case 2: - if (_.isFunction(args[1])) { + if (isFunction(args[1])) { - if (_.isFunction(args[0])) { + if (isFunction(args[0])) { success = args[0]; error = args[1]; @@ -63,7 +64,7 @@ function opts(action, args) { case 1: - if (_.isFunction(args[0])) { + if (isFunction(args[0])) { success = args[0]; } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) { data = args[0]; @@ -83,7 +84,7 @@ function opts(action, args) { } options.data = data; - options.params = _.extend({}, options.params, params); + options.params = extend({}, options.params, params); if (success) { options.success = success; @@ -106,5 +107,3 @@ Resource.actions = { delete: {method: 'DELETE'} }; - -module.exports = _.resource = Resource; diff --git a/src/url/index.js b/src/url/index.js index 5ad2f8fe..2e7fd795 100644 --- a/src/url/index.js +++ b/src/url/index.js @@ -2,26 +2,31 @@ * Service for URL templating. */ -var _ = require('../util'); -var ie = document.documentMode; -var el = document.createElement('a'); +const ie = document.documentMode; +const el = document.createElement('a'); -function Url(url, params) { +import root from './root'; +import query from './query'; +import legacy from './legacy'; +import template from './template'; +import { each, merge, isArray, isFunction, isObject, isPlainObject, isString } from '../util'; - var options = url, transform; +export default function Url(url, params) { - if (_.isString(url)) { + var self = this || {}, options = url, transform; + + if (isString(url)) { options = {url: url, params: params}; } - options = _.merge({}, Url.options, this.$options, options); + options = merge({}, Url.options, self.$options, options); - Url.transforms.forEach(function (handler) { - transform = factory(handler, transform, this.$vm); - }, this); + Url.transforms.forEach((handler) => { + transform = factory(handler, transform, self.$vm); + }); return transform(options); -}; +} /** * Url options. @@ -37,12 +42,7 @@ Url.options = { * Url transforms. */ -Url.transforms = [ - require('./template'), - require('./legacy'), - require('./query'), - require('./root') -]; +Url.transforms = [template, legacy, query, root]; /** * Encodes a Url parameter string. @@ -56,7 +56,7 @@ Url.params = function (obj) { params.add = function (key, value) { - if (_.isFunction(value)) { + if (isFunction(value)) { value = value(); } @@ -107,11 +107,11 @@ function factory(handler, next, vm) { function serialize(params, obj, scope) { - var array = _.isArray(obj), plain = _.isPlainObject(obj), hash; + var array = isArray(obj), plain = isPlainObject(obj), hash; - _.each(obj, function (value, key) { + each(obj, function (value, key) { - hash = _.isObject(value) || _.isArray(value); + hash = isObject(value) || isArray(value); if (scope) { key = scope + '[' + (plain || hash ? key : '') + ']'; @@ -126,5 +126,3 @@ function serialize(params, obj, scope) { } }); } - -module.exports = _.url = Url; diff --git a/src/url/legacy.js b/src/url/legacy.js index 7c349a35..a91a2044 100644 --- a/src/url/legacy.js +++ b/src/url/legacy.js @@ -2,15 +2,15 @@ * Legacy Transform. */ -var _ = require('../util'); +import { warn } from '../util'; -module.exports = function (options, next) { +export default function (options, next) { var variables = [], url = next(options); url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { - _.warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); + warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); if (options.params[name]) { variables.push(name); @@ -25,7 +25,7 @@ module.exports = function (options, next) { }); return url; -}; +} function encodeUriSegment(value) { diff --git a/src/url/query.js b/src/url/query.js index 7a524019..ab7f9d54 100644 --- a/src/url/query.js +++ b/src/url/query.js @@ -2,23 +2,24 @@ * Query Parameter Transform. */ -var _ = require('../util'); +import Url from './index'; +import { each } from '../util'; -module.exports = function (options, next) { +export default function (options, next) { - var urlParams = Object.keys(_.url.options.params), query = {}, url = next(options); + var urlParams = Object.keys(Url.options.params), query = {}, url = next(options); - _.each(options.params, function (value, key) { + each(options.params, function (value, key) { if (urlParams.indexOf(key) === -1) { query[key] = value; } }); - query = _.url.params(query); + query = Url.params(query); if (query) { url += (url.indexOf('?') == -1 ? '?' : '&') + query; } return url; -}; +} diff --git a/src/url/root.js b/src/url/root.js index c2083c84..7f0cdb38 100644 --- a/src/url/root.js +++ b/src/url/root.js @@ -2,15 +2,15 @@ * Root Prefix Transform. */ -var _ = require('../util'); +import { isString } from '../util'; -module.exports = function (options, next) { +export default function (options, next) { var url = next(options); - if (_.isString(options.root) && !url.match(/^(https?:)?\//)) { + if (isString(options.root) && !url.match(/^(https?:)?\//)) { url = options.root + '/' + url; } return url; -}; +} diff --git a/src/url/template.js b/src/url/template.js index 4d0c1f51..684cf10b 100644 --- a/src/url/template.js +++ b/src/url/template.js @@ -2,15 +2,15 @@ * URL Template (RFC 6570) Transform. */ -var UrlTemplate = require('../lib/url-template'); +import { expand } from '../lib/url-template'; -module.exports = function (options) { +export default function (options) { - var variables = [], url = UrlTemplate.expand(options.url, options.params, variables); + var variables = [], url = expand(options.url, options.params, variables); variables.forEach(function (key) { delete options.params[key]; }); return url; -}; +} diff --git a/src/util.js b/src/util.js index d3e070e5..55fc0be2 100644 --- a/src/util.js +++ b/src/util.js @@ -2,58 +2,67 @@ * Utility functions. */ -var _ = exports, array = [], console = window.console; +var util = {}, config = {}, array = [], console = window.console; -_.warn = function (msg) { - if (console && _.warning && (!_.config.silent || _.config.debug)) { +export default function (Vue) { + util = Vue.util; + config = Vue.config; +} + +export const isArray = Array.isArray; + +export function warn(msg) { + if (console && util.warn && (!config.silent || config.debug)) { console.warn('[VueResource warn]: ' + msg); } -}; +} -_.error = function (msg) { +export function error(msg) { if (console) { console.error(msg); } -}; +} -_.trim = function (str) { +export function nextTick(cb, ctx) { + return util.nextTick(cb, ctx); +} + +export function trim(str) { return str.replace(/^\s*|\s*$/g, ''); -}; +} -_.toLower = function (str) { +export function toLower(str) { return str ? str.toLowerCase() : ''; -}; - -_.isArray = Array.isArray; +} -_.isString = function (val) { +export function isString(val) { return typeof val === 'string'; -}; +} -_.isFunction = function (val) { +export function isFunction(val) { return typeof val === 'function'; -}; +} -_.isObject = function (obj) { +export function isObject(obj) { return obj !== null && typeof obj === 'object'; -}; +} -_.isPlainObject = function (obj) { - return _.isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; -}; +export function isPlainObject(obj) { + return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; +} -_.options = function (fn, obj, options) { +export function options(fn, obj, opts) { - options = options || {}; + opts = opts || {}; - if (_.isFunction(options)) { - options = options.call(obj); + if (isFunction(opts)) { + opts = opts.call(obj); } - return _.merge(fn.bind({$vm: obj, $options: options}), fn, {$options: options}); -}; + return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts}); +} -_.each = function (obj, iterator) { +export function each(obj, iterator) { var i, key; @@ -61,7 +70,7 @@ _.each = function (obj, iterator) { for (i = 0; i < obj.length; i++) { iterator.call(obj[i], obj[i], i); } - } else if (_.isObject(obj)) { + } else if (isObject(obj)) { for (key in obj) { if (obj.hasOwnProperty(key)) { iterator.call(obj[key], obj[key], key); @@ -70,9 +79,9 @@ _.each = function (obj, iterator) { } return obj; -}; +} -_.defaults = function (target, source) { +export function defaults(target, source) { for (var key in source) { if (target[key] === undefined) { @@ -81,40 +90,40 @@ _.defaults = function (target, source) { } return target; -}; +} -_.extend = function (target) { +export function extend(target) { var args = array.slice.call(arguments, 1); args.forEach(function (arg) { - merge(target, arg); + _merge(target, arg); }); return target; -}; +} -_.merge = function (target) { +export function merge(target) { var args = array.slice.call(arguments, 1); args.forEach(function (arg) { - merge(target, arg, true); + _merge(target, arg, true); }); return target; -}; +} -function merge(target, source, deep) { +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])) { + if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { + if (isPlainObject(source[key]) && !isPlainObject(target[key])) { target[key] = {}; } - if (_.isArray(source[key]) && !_.isArray(target[key])) { + if (isArray(source[key]) && !isArray(target[key])) { target[key] = []; } - merge(target[key], source[key], deep); + _merge(target[key], source[key], deep); } else if (source[key] !== undefined) { target[key] = source[key]; } diff --git a/test/http.js b/test/http.js index 85ecae8e..ffe9f3f9 100644 --- a/test/http.js +++ b/test/http.js @@ -1,4 +1,4 @@ -var Vue = require('vue'); +import Vue from 'vue'; describe('Vue.http', function () { diff --git a/test/index.js b/test/index.js index 388d62c9..5f7db6ef 100644 --- a/test/index.js +++ b/test/index.js @@ -1,9 +1,8 @@ -var Vue = require('vue'); -var Resource = require('../src'); +import Vue from 'vue'; +import VueResource from '../src/index'; -Vue.use(Resource); +Vue.use(VueResource); -// require specs require('./url.js'); require('./http.js'); require('./promise.js'); diff --git a/test/promise.js b/test/promise.js index 5d5ca5f3..0be26b6a 100644 --- a/test/promise.js +++ b/test/promise.js @@ -1,7 +1,6 @@ -var Promise = require('../src/promise'); -var isNative = window.Promise !== undefined; +import Promise from '../src/promise'; -describe('Vue.promise ' + (isNative ? '(native)' : '(polyfill)'), function () { +describe('Vue.promise ' + (window.Promise !== undefined ? '(native)' : '(polyfill)'), function () { it('then fulfill', function (done) { diff --git a/test/url.js b/test/url.js index 9e333ae6..54c647cc 100644 --- a/test/url.js +++ b/test/url.js @@ -1,4 +1,4 @@ -var Vue = require('vue'); +import Vue from 'vue'; describe('Vue.url', function () { From d9fb1349651b602a561fc2bd2b295b74abb9993d Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 11:38:32 +0200 Subject: [PATCH 3/7] trim statusText, fixes #276 --- src/http/client/xhr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/client/xhr.js b/src/http/client/xhr.js index 1bc9bbda..ab1fd226 100644 --- a/src/http/client/xhr.js +++ b/src/http/client/xhr.js @@ -4,7 +4,7 @@ import Url from '../../url/index'; import Promise from '../../promise'; -import { each, extend, isPlainObject } from '../../util'; +import { each, extend, trim, isPlainObject } from '../../util'; export default function (request) { return new Promise(function (resolve) { @@ -21,7 +21,7 @@ export default function (request) { response.data = ('response' in xhr) ? xhr.response : xhr.responseText; response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug - response.statusText = xhr.statusText || ''; + response.statusText = trim(xhr.statusText || ''); response.headers = xhr.getAllResponseHeaders(); resolve(response); From 5e013a57de97eb94284a8cf86d31a94f1090e10a Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 11:44:16 +0200 Subject: [PATCH 4/7] add license, see #287 --- LICENSE | 21 +++++++++++++++++++++ README.md | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..9f7b7770 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2016 steffans + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 4201e806..9748da16 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,7 @@ Details changes for each release are documented in the [release notes](https://g ## Contribution If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/vuejs/vue-resource/issues) or a pull request. + +## License + +[MIT](http://opensource.org/licenses/MIT) From 780dea2b5db0d537b19ebbcf66702c5a0484b933 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 11:55:24 +0200 Subject: [PATCH 5/7] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9748da16..4a8a3128 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Add `vue` and `vue-resource` to your `package.json`, then `npm install`, then ad ```js var Vue = require('vue'); +var VueResource = require('vue-resource'); -Vue.use(require('vue-resource')); +Vue.use(VueResource); ``` ## Documentation From 417652a7667b3788b6ae7bd9ea5a4a95f744ae54 Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 15:36:34 +0200 Subject: [PATCH 6/7] use arrow functions --- src/http/before.js | 2 +- src/http/client/index.js | 6 +++--- src/http/client/jsonp.js | 8 ++++---- src/http/client/xdr.js | 10 +++++----- src/http/client/xhr.js | 12 ++++++------ src/http/cors.js | 2 +- src/http/header.js | 2 +- src/http/jsonp.js | 2 +- src/http/method.js | 2 +- src/http/mime.js | 4 ++-- src/http/timeout.js | 6 +++--- src/resource.js | 2 +- src/url/index.js | 4 ++-- src/url/legacy.js | 4 ++-- src/url/query.js | 2 +- src/url/template.js | 2 +- src/util.js | 4 ++-- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/http/before.js b/src/http/before.js index f2041c4b..071e8f7f 100644 --- a/src/http/before.js +++ b/src/http/before.js @@ -6,7 +6,7 @@ import { isFunction } from '../util'; const exports = { - request: function (request) { + request(request) { if (isFunction(request.beforeSend)) { request.beforeSend.call(this, request); diff --git a/src/http/client/index.js b/src/http/client/index.js index 2cd3194b..c6515b6d 100644 --- a/src/http/client/index.js +++ b/src/http/client/index.js @@ -10,13 +10,13 @@ export default function (request) { var response = (request.client || xhrClient)(request); - return Promise.resolve(response).then(function (response) { + return Promise.resolve(response).then((response) => { if (response.headers) { var headers = parseHeaders(response.headers); - response.headers = function (name) { + response.headers = (name) => { if (name) { return headers[toLower(name)]; @@ -39,7 +39,7 @@ function parseHeaders(str) { var headers = {}, value, name, i; if (isString(str)) { - each(str.split('\n'), function (row) { + each(str.split('\n'), (row) => { i = row.indexOf(':'); name = trim(toLower(row.slice(0, i))); diff --git a/src/http/client/jsonp.js b/src/http/client/jsonp.js index 14464ba0..d5e98eb0 100644 --- a/src/http/client/jsonp.js +++ b/src/http/client/jsonp.js @@ -6,12 +6,12 @@ import Url from '../../url/index'; import Promise from '../../promise'; export default function (request) { - return new Promise(function (resolve) { + return new Promise((resolve) => { var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {request: request, data: null}, handler, script; request.params[request.jsonp] = callback; - request.cancel = function () { + request.cancel = () => { handler({type: 'cancel'}); }; @@ -20,11 +20,11 @@ export default function (request) { script.type = 'text/javascript'; script.async = true; - window[callback] = function (data) { + window[callback] = (data) => { response.data = data; }; - handler = function (event) { + handler = (event) => { if (event.type === 'load' && response.data !== null) { response.status = 200; diff --git a/src/http/client/xdr.js b/src/http/client/xdr.js index eb470e5f..d2936bba 100644 --- a/src/http/client/xdr.js +++ b/src/http/client/xdr.js @@ -6,17 +6,17 @@ import Url from '../../url/index'; import Promise from '../../promise'; export default function (request) { - return new Promise(function (resolve) { + return new Promise((resolve) => { var xdr = new XDomainRequest(), response = {request: request}, handler; - request.cancel = function () { + request.cancel = () => { xdr.abort(); }; xdr.open(request.method, Url(request), true); - handler = function (event) { + handler = (event) => { response.data = xdr.responseText; response.status = xdr.status; @@ -29,8 +29,8 @@ export default function (request) { xdr.onload = handler; xdr.onabort = handler; xdr.onerror = handler; - xdr.ontimeout = function () {}; - xdr.onprogress = function () {}; + xdr.ontimeout = () => {}; + xdr.onprogress = () => {}; xdr.send(request.data); }); diff --git a/src/http/client/xhr.js b/src/http/client/xhr.js index ab1fd226..90f77e3d 100644 --- a/src/http/client/xhr.js +++ b/src/http/client/xhr.js @@ -7,17 +7,17 @@ import Promise from '../../promise'; import { each, extend, trim, isPlainObject } from '../../util'; export default function (request) { - return new Promise(function (resolve) { + return new Promise((resolve) => { var xhr = new XMLHttpRequest(), response = {request: request}, handler; - request.cancel = function () { + request.cancel = () => { xhr.abort(); }; xhr.open(request.method, Url(request), true); - handler = function (event) { + handler = (event) => { response.data = ('response' in xhr) ? xhr.response : xhr.responseText; response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug @@ -31,8 +31,8 @@ export default function (request) { xhr.onload = handler; xhr.onabort = handler; xhr.onerror = handler; - xhr.ontimeout = function () {}; - xhr.onprogress = function () {}; + xhr.ontimeout = () => {}; + xhr.onprogress = () => {}; if (isPlainObject(request.xhr)) { extend(xhr, request.xhr); @@ -42,7 +42,7 @@ export default function (request) { extend(xhr.upload, request.upload); } - each(request.headers || {}, function (value, header) { + each(request.headers || {}, (value, header) => { xhr.setRequestHeader(header, value); }); diff --git a/src/http/cors.js b/src/http/cors.js index e4850c2d..5713796a 100644 --- a/src/http/cors.js +++ b/src/http/cors.js @@ -10,7 +10,7 @@ const supportCors = 'withCredentials' in new XMLHttpRequest(); const exports = { - request: function (request) { + request(request) { if (request.crossOrigin === null) { request.crossOrigin = crossOrigin(request); diff --git a/src/http/header.js b/src/http/header.js index 327eeb5a..3d31a813 100644 --- a/src/http/header.js +++ b/src/http/header.js @@ -7,7 +7,7 @@ import { extend, isPlainObject } from '../util'; const exports = { - request: function (request) { + request(request) { request.method = request.method.toUpperCase(); request.headers = extend({}, Http.headers.common, diff --git a/src/http/jsonp.js b/src/http/jsonp.js index 7326dd06..6b3d531c 100644 --- a/src/http/jsonp.js +++ b/src/http/jsonp.js @@ -6,7 +6,7 @@ import jsonpClient from './client/jsonp'; const exports = { - request: function (request) { + request(request) { if (request.method == 'JSONP') { request.client = jsonpClient; diff --git a/src/http/method.js b/src/http/method.js index b341800a..00a9be49 100644 --- a/src/http/method.js +++ b/src/http/method.js @@ -4,7 +4,7 @@ const exports = { - request: function (request) { + request(request) { if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { request.headers['X-HTTP-Method-Override'] = request.method; diff --git a/src/http/mime.js b/src/http/mime.js index 5f10041b..a6099e9e 100644 --- a/src/http/mime.js +++ b/src/http/mime.js @@ -7,7 +7,7 @@ import { isObject, isPlainObject } from '../util'; const exports = { - request: function (request) { + request(request) { if (request.emulateJSON && isPlainObject(request.data)) { request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; @@ -25,7 +25,7 @@ const exports = { return request; }, - response: function (response) { + response(response) { try { response.data = JSON.parse(response.data); diff --git a/src/http/timeout.js b/src/http/timeout.js index e66a89b9..a225d7e8 100644 --- a/src/http/timeout.js +++ b/src/http/timeout.js @@ -8,10 +8,10 @@ const exports = function () { return { - request: function (request) { + request(request) { if (request.timeout) { - timeout = setTimeout(function () { + timeout = setTimeout(() => { request.cancel(); }, request.timeout); } @@ -19,7 +19,7 @@ const exports = function () { return request; }, - response: function (response) { + response(response) { clearTimeout(timeout); diff --git a/src/resource.js b/src/resource.js index d69c7600..caef679a 100644 --- a/src/resource.js +++ b/src/resource.js @@ -14,7 +14,7 @@ export default function Resource(url, params, actions, options) { actions ); - each(actions, function (action, name) { + each(actions, (action, name) => { action = merge({url: url, params: params || {}}, options, action); diff --git a/src/url/index.js b/src/url/index.js index 2e7fd795..2b87e277 100644 --- a/src/url/index.js +++ b/src/url/index.js @@ -100,7 +100,7 @@ Url.parse = function (url) { }; function factory(handler, next, vm) { - return function (options) { + return (options) => { return handler.call(vm, options, next); }; } @@ -109,7 +109,7 @@ function serialize(params, obj, scope) { var array = isArray(obj), plain = isPlainObject(obj), hash; - each(obj, function (value, key) { + each(obj, (value, key) => { hash = isObject(value) || isArray(value); diff --git a/src/url/legacy.js b/src/url/legacy.js index a91a2044..154bf582 100644 --- a/src/url/legacy.js +++ b/src/url/legacy.js @@ -8,7 +8,7 @@ export default function (options, next) { var variables = [], url = next(options); - url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { + url = url.replace(/(\/?):([a-z]\w*)/gi, (match, slash, name) => { warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); @@ -20,7 +20,7 @@ export default function (options, next) { return ''; }); - variables.forEach(function (key) { + variables.forEach((key) => { delete options.params[key]; }); diff --git a/src/url/query.js b/src/url/query.js index ab7f9d54..05b95eae 100644 --- a/src/url/query.js +++ b/src/url/query.js @@ -9,7 +9,7 @@ export default function (options, next) { var urlParams = Object.keys(Url.options.params), query = {}, url = next(options); - each(options.params, function (value, key) { + each(options.params, (value, key) => { if (urlParams.indexOf(key) === -1) { query[key] = value; } diff --git a/src/url/template.js b/src/url/template.js index 684cf10b..806c6c30 100644 --- a/src/url/template.js +++ b/src/url/template.js @@ -8,7 +8,7 @@ export default function (options) { var variables = [], url = expand(options.url, options.params, variables); - variables.forEach(function (key) { + variables.forEach((key) => { delete options.params[key]; }); diff --git a/src/util.js b/src/util.js index 55fc0be2..5626d4d2 100644 --- a/src/util.js +++ b/src/util.js @@ -96,7 +96,7 @@ export function extend(target) { var args = array.slice.call(arguments, 1); - args.forEach(function (arg) { + args.forEach((arg) => { _merge(target, arg); }); @@ -107,7 +107,7 @@ export function merge(target) { var args = array.slice.call(arguments, 1); - args.forEach(function (arg) { + args.forEach((arg) => { _merge(target, arg, true); }); From 35e7a5121fe68e2770fdaa0d6b480e9631c76bbe Mon Sep 17 00:00:00 2001 From: Steffan Date: Sun, 12 Jun 2016 15:40:53 +0200 Subject: [PATCH 7/7] v0.7.4 --- bower.json | 2 +- dist/vue-resource.common.js | 2537 +++++++++++++++------------------- dist/vue-resource.js | 2606 +++++++++++++++-------------------- dist/vue-resource.min.js | 6 +- package.json | 2 +- 5 files changed, 2245 insertions(+), 2908 deletions(-) diff --git a/bower.json b/bower.json index 0c9b31c5..9fb16079 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "vue-resource", "main": "dist/vue-resource.js", "description": "A web request service for Vue.js", - "version": "0.7.3", + "version": "0.7.4", "homepage": "https://github.com/vuejs/vue-resource", "license": "MIT", "ignore": [ diff --git a/dist/vue-resource.common.js b/dist/vue-resource.common.js index 577db0af..bf8c6785 100644 --- a/dist/vue-resource.common.js +++ b/dist/vue-resource.common.js @@ -1,1705 +1,1376 @@ -/** - * vue-resource v0.7.3 +/*! + * vue-resource v0.7.4 * https://github.com/vuejs/vue-resource * Released under the MIT License. */ -module.exports = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Install plugin. - */ - - function plugin(Vue) { - - if (plugin.installed) { - return; - } - - var _ = __webpack_require__(1); - - _.config = Vue.config; - _.warning = Vue.util.warn; - _.nextTick = Vue.util.nextTick; - - Vue.url = __webpack_require__(2); - Vue.http = __webpack_require__(8); - Vue.resource = __webpack_require__(23); - Vue.Promise = __webpack_require__(10); - - Object.defineProperties(Vue.prototype, { - - $url: { - get: function get() { - return _.options(Vue.url, this, this.$options.url); - } - }, - - $http: { - get: function get() { - return _.options(Vue.http, this, this.$options.http); - } - }, - - $resource: { - get: function get() { - return Vue.resource.bind(this); - } - }, - - $promise: { - get: function get() { - var _this = this; - - return function (executor) { - return new Vue.Promise(executor, _this); - }; - } - } - - }); - } - - if (typeof window !== 'undefined' && window.Vue) { - window.Vue.use(plugin); - } - - module.exports = plugin; - -/***/ }, -/* 1 */ -/***/ function(module, exports) { - - 'use strict'; - - var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; - - /** - * Utility functions. - */ - - var _ = exports, - array = [], - console = window.console; - - _.warn = function (msg) { - if (console && _.warning && (!_.config.silent || _.config.debug)) { - console.warn('[VueResource warn]: ' + msg); - } - }; - - _.error = function (msg) { - if (console) { - console.error(msg); - } - }; - - _.trim = function (str) { - return str.replace(/^\s*|\s*$/g, ''); - }; - - _.toLower = function (str) { - return str ? str.toLowerCase() : ''; - }; - - _.isArray = Array.isArray; - - _.isString = function (val) { - return typeof val === 'string'; - }; - - _.isFunction = function (val) { - return typeof val === 'function'; - }; - - _.isObject = function (obj) { - return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; - }; - - _.isPlainObject = function (obj) { - return _.isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; - }; - - _.options = function (fn, obj, options) { - - options = options || {}; - - if (_.isFunction(options)) { - options = options.call(obj); - } - - return _.merge(fn.bind({ $vm: obj, $options: options }), fn, { $options: options }); - }; - - _.each = function (obj, iterator) { - - var i, key; - - 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); - } - } - } - - return obj; - }; - - _.defaults = function (target, source) { - - for (var key in source) { - if (target[key] === undefined) { - target[key] = source[key]; - } - } - - return target; - }; - - _.extend = function (target) { - - var args = array.slice.call(arguments, 1); - - args.forEach(function (arg) { - merge(target, arg); - }); - - return target; - }; - - _.merge = function (target) { - - var args = array.slice.call(arguments, 1); - - args.forEach(function (arg) { - merge(target, arg, true); - }); - - return target; - }; - - 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]; - } - } - } - -/***/ }, -/* 2 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Service for URL templating. - */ - - var _ = __webpack_require__(1); - var ie = document.documentMode; - var el = document.createElement('a'); - - function Url(url, params) { - - var options = url, - transform; - - if (_.isString(url)) { - options = { url: url, params: params }; - } - - options = _.merge({}, Url.options, this.$options, options); - - Url.transforms.forEach(function (handler) { - transform = factory(handler, transform, this.$vm); - }, this); - - return transform(options); - }; - - /** - * Url options. - */ +'use strict'; - Url.options = { - url: '', - root: null, - params: {} - }; +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; +}; - /** - * Url transforms. - */ - - Url.transforms = [__webpack_require__(3), __webpack_require__(5), __webpack_require__(6), __webpack_require__(7)]; - - /** - * Encodes a Url parameter string. - * - * @param {Object} obj - */ - - Url.params = function (obj) { - - var params = [], - escape = encodeURIComponent; - - params.add = function (key, value) { - - if (_.isFunction(value)) { - value = value(); - } - - if (value === null) { - value = ''; - } - - this.push(escape(key) + '=' + escape(value)); - }; - - serialize(params, obj); - - return params.join('&').replace(/%20/g, '+'); - }; - - /** - * Parse a URL and return its components. - * - * @param {String} url - */ - - Url.parse = function (url) { - - if (ie) { - el.href = url; - url = el.href; - } - - el.href = url; - - 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(/^#/, '') : '' - }; - }; - - function factory(handler, next, vm) { - return function (options) { - return handler.call(vm, options, next); - }; - } - - function serialize(params, obj, scope) { - - var array = _.isArray(obj), - plain = _.isPlainObject(obj), - hash; - - _.each(obj, function (value, key) { - - hash = _.isObject(value) || _.isArray(value); - - if (scope) { - key = scope + '[' + (plain || hash ? key : '') + ']'; - } - - if (!scope && array) { - params.add(value.name, value.value); - } else if (hash) { - serialize(params, value, key); - } else { - params.add(key, value); - } - }); - } - - module.exports = _.url = Url; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * URL Template (RFC 6570) Transform. - */ - - var UrlTemplate = __webpack_require__(4); - - module.exports = function (options) { - - var variables = [], - url = UrlTemplate.expand(options.url, options.params, variables); - - variables.forEach(function (key) { - delete options.params[key]; - }); - - return url; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports) { - - 'use strict'; - - /** - * URL Template v2.0.6 (https://github.com/bramstein/url-template) - */ - - exports.expand = function (url, params, variables) { - - var tmpl = this.parse(url), - expanded = tmpl.expand(params); - - if (variables) { - variables.push.apply(variables, tmpl.vars); - } - - return expanded; - }; - - exports.parse = function (template) { - - var operators = ['+', '#', '.', '/', ';', '?', '&'], - variables = []; - - return { - vars: variables, - expand: function expand(context) { - return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { - if (expression) { - - var operator = null, - values = []; - - if (operators.indexOf(expression.charAt(0)) !== -1) { - operator = expression.charAt(0); - expression = expression.substr(1); - } - - expression.split(/,/g).forEach(function (variable) { - var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push.apply(values, exports.getValues(context, operator, tmp[1], tmp[2] || tmp[3])); - variables.push(tmp[1]); - }); - - if (operator && operator !== '+') { - - var separator = ','; - - if (operator === '?') { - separator = '&'; - } else if (operator !== '#') { - separator = operator; - } - - return (values.length !== 0 ? operator : '') + values.join(separator); - } else { - return values.join(','); - } - } else { - return exports.encodeReserved(literal); - } - }); - } - }; - }; - - exports.getValues = function (context, operator, key, modifier) { - - var value = context[key], - result = []; - - if (this.isDefined(value) && value !== '') { - if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { - value = value.toString(); - - if (modifier && modifier !== '*') { - value = value.substring(0, parseInt(modifier, 10)); - } - - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); - } else { - if (modifier === '*') { - if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); - }, this); - } else { - Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { - result.push(this.encodeValue(operator, value[k], k)); - } - }, this); - } - } else { - var tmp = []; - - if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - tmp.push(this.encodeValue(operator, value)); - }, this); - } else { - Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { - tmp.push(encodeURIComponent(k)); - tmp.push(this.encodeValue(operator, value[k].toString())); - } - }, this); - } - - if (this.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(''); - } - } - - return result; - }; - - exports.isDefined = function (value) { - return value !== undefined && value !== null; - }; - - exports.isKeyOperator = function (operator) { - return operator === ';' || operator === '&' || operator === '?'; - }; - - exports.encodeValue = function (operator, value, key) { - - value = operator === '+' || operator === '#' ? this.encodeReserved(value) : encodeURIComponent(value); - - if (key) { - return encodeURIComponent(key) + '=' + value; - } else { - return value; - } - }; - - exports.encodeReserved = function (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(''); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Legacy Transform. - */ - - var _ = __webpack_require__(1); - - module.exports = function (options, next) { - - var variables = [], - url = next(options); - - url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { - - _.warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); - - if (options.params[name]) { - variables.push(name); - return slash + encodeUriSegment(options.params[name]); - } - - return ''; - }); - - variables.forEach(function (key) { - delete options.params[key]; - }); - - return url; - }; - - function encodeUriSegment(value) { - - return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+'); - } - - function encodeUriQuery(value, spaces) { - - return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+'); - } - -/***/ }, -/* 6 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Query Parameter Transform. - */ - - var _ = __webpack_require__(1); - - module.exports = function (options, next) { - - var urlParams = Object.keys(_.url.options.params), - query = {}, - url = next(options); - - _.each(options.params, function (value, key) { - if (urlParams.indexOf(key) === -1) { - query[key] = value; - } - }); - - query = _.url.params(query); +/** + * Utility functions. + */ - if (query) { - url += (url.indexOf('?') == -1 ? '?' : '&') + query; - } +var util = {}; +var config = {}; +var array = []; +var console = window.console; +function Util (Vue) { + util = Vue.util; + config = Vue.config; +} - return url; - }; +var isArray = Array.isArray; -/***/ }, -/* 7 */ -/***/ function(module, exports, __webpack_require__) { +function warn(msg) { + if (console && util.warn && (!config.silent || config.debug)) { + console.warn('[VueResource warn]: ' + msg); + } +} + +function error(msg) { + if (console) { + console.error(msg); + } +} - 'use strict'; +function nextTick(cb, ctx) { + return util.nextTick(cb, ctx); +} - /** - * Root Prefix Transform. - */ +function trim(str) { + return str.replace(/^\s*|\s*$/g, ''); +} - var _ = __webpack_require__(1); +function toLower(str) { + return str ? str.toLowerCase() : ''; +} - module.exports = function (options, next) { +function isString(val) { + return typeof val === 'string'; +} - var url = next(options); +function isFunction(val) { + return typeof val === 'function'; +} - if (_.isString(options.root) && !url.match(/^(https?:)?\//)) { - url = options.root + '/' + url; - } +function isObject(obj) { + return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; +} - return url; - }; +function isPlainObject(obj) { + return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; +} -/***/ }, -/* 8 */ -/***/ function(module, exports, __webpack_require__) { +function options(fn, obj, opts) { - 'use strict'; + opts = opts || {}; - /** - * Service for sending network requests. - */ + if (isFunction(opts)) { + opts = opts.call(obj); + } - var _ = __webpack_require__(1); - var Client = __webpack_require__(9); - var Promise = __webpack_require__(10); - var interceptor = __webpack_require__(13); - var jsonType = { 'Content-Type': 'application/json' }; + return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts }); +} - function Http(url, options) { +function each(obj, iterator) { - var self = this || {}, - client = Client, - request, - promise; + var i, key; - Http.interceptors.forEach(function (handler) { - client = interceptor(handler, self.$vm)(client); - }); + 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); + } + } + } - options = _.isObject(url) ? url : _.extend({ url: url }, options); - request = _.merge({}, Http.options, self.$options, options); - promise = client(request).bind(self.$vm).then(function (response) { + return obj; +} - return response.ok ? response : Promise.reject(response); - }, function (response) { +function extend(target) { - if (response instanceof Error) { - _.error(response); - } + var args = array.slice.call(arguments, 1); - return Promise.reject(response); - }); + args.forEach(function (arg) { + _merge(target, arg); + }); - if (request.success) { - promise.success(request.success); - } + return target; +} - if (request.error) { - promise.error(request.error); - } +function merge(target) { - return promise; - } + var args = array.slice.call(arguments, 1); - Http.options = { - method: 'get', - data: '', - params: {}, - headers: {}, - xhr: null, - upload: null, - jsonp: 'callback', - beforeSend: null, - crossOrigin: null, - emulateHTTP: false, - emulateJSON: false, - timeout: 0 - }; + args.forEach(function (arg) { + _merge(target, arg, true); + }); - Http.interceptors = [__webpack_require__(14), __webpack_require__(15), __webpack_require__(16), __webpack_require__(18), __webpack_require__(19), __webpack_require__(20), __webpack_require__(21)]; + return target; +} - Http.headers = { - put: jsonType, - post: jsonType, - patch: jsonType, - delete: jsonType, - common: { 'Accept': 'application/json, text/plain, */*' }, - custom: { 'X-Requested-With': 'XMLHttpRequest' } - }; +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]; + } + } +} - ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { +function root (options, next) { - Http[method] = function (url, data, success, options) { + var url = next(options); - if (_.isFunction(data)) { - options = success; - success = data; - data = undefined; - } + if (isString(options.root) && !url.match(/^(https?:)?\//)) { + url = options.root + '/' + url; + } - if (_.isObject(success)) { - options = success; - success = undefined; - } + return url; +} - return this(url, _.extend({ method: method, data: data, success: success }, options)); - }; - }); +function query (options, next) { - module.exports = _.http = Http; + var urlParams = Object.keys(Url.options.params), + query = {}, + url = next(options); -/***/ }, -/* 9 */ -/***/ function(module, exports, __webpack_require__) { + each(options.params, function (value, key) { + if (urlParams.indexOf(key) === -1) { + query[key] = value; + } + }); - 'use strict'; + query = Url.params(query); - /** - * Base client. - */ + if (query) { + url += (url.indexOf('?') == -1 ? '?' : '&') + query; + } - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - var xhrClient = __webpack_require__(12); + return url; +} - module.exports = function (request) { +function legacy (options, next) { - var response = (request.client || xhrClient)(request); + var variables = [], + url = next(options); - return Promise.resolve(response).then(function (response) { + url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { - if (response.headers) { + warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); - var headers = parseHeaders(response.headers); + if (options.params[name]) { + variables.push(name); + return slash + encodeUriSegment(options.params[name]); + } - response.headers = function (name) { + return ''; + }); - if (name) { - return headers[_.toLower(name)]; - } + variables.forEach(function (key) { + delete options.params[key]; + }); - return headers; - }; - } + return url; +} - response.ok = response.status >= 200 && response.status < 300; +function encodeUriSegment(value) { - return response; - }); - }; + return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+'); +} - function parseHeaders(str) { +function encodeUriQuery(value, spaces) { - var headers = {}, - value, - name, - i; + return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+'); +} - if (_.isString(str)) { - _.each(str.split('\n'), function (row) { +/** + * URL Template v2.0.6 (https://github.com/bramstein/url-template) + */ - i = row.indexOf(':'); - name = _.trim(_.toLower(row.slice(0, i))); - value = _.trim(row.slice(i + 1)); +function expand(url, params, variables) { + + var tmpl = parse(url), + expanded = tmpl.expand(params); + + if (variables) { + variables.push.apply(variables, tmpl.vars); + } + + return expanded; +} + +function parse(template) { + + var operators = ['+', '#', '.', '/', ';', '?', '&'], + variables = []; + + return { + vars: variables, + expand: function expand(context) { + return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { + if (expression) { + + var operator = null, + values = []; + + if (operators.indexOf(expression.charAt(0)) !== -1) { + operator = expression.charAt(0); + expression = expression.substr(1); + } + + 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]); + }); + + if (operator && operator !== '+') { + + var separator = ','; + + if (operator === '?') { + separator = '&'; + } else if (operator !== '#') { + separator = operator; + } + + return (values.length !== 0 ? operator : '') + values.join(separator); + } else { + return values.join(','); + } + } else { + return encodeReserved(literal); + } + }); + } + }; +} + +function getValues(context, operator, key, modifier) { + + var value = context[key], + result = []; + + if (isDefined(value) && value !== '') { + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + value = value.toString(); + + if (modifier && modifier !== '*') { + value = value.substring(0, parseInt(modifier, 10)); + } + + 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 = []; + + 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())); + } + }); + } + + 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(''); + } + } + + return result; +} + +function isDefined(value) { + return value !== undefined && value !== null; +} + +function isKeyOperator(operator) { + return operator === ';' || operator === '&' || operator === '?'; +} + +function encodeValue(operator, value, key) { + + value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value); + + if (key) { + return encodeURIComponent(key) + '=' + value; + } else { + return value; + } +} + +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(''); +} + +function template (options) { + + var variables = [], + url = expand(options.url, options.params, variables); + + variables.forEach(function (key) { + delete options.params[key]; + }); + + return url; +} - if (headers[name]) { +/** + * Service for URL templating. + */ - if (_.isArray(headers[name])) { - headers[name].push(value); - } else { - headers[name] = [headers[name], value]; - } - } else { +var ie = document.documentMode; +var el = document.createElement('a'); - headers[name] = value; - } - }); - } +function Url(url, params) { - return headers; - } + var self = this || {}, + options = url, + transform; -/***/ }, -/* 10 */ -/***/ function(module, exports, __webpack_require__) { + if (isString(url)) { + options = { url: url, params: params }; + } - 'use strict'; + options = merge({}, Url.options, self.$options, options); - /** - * Promise adapter. - */ + Url.transforms.forEach(function (handler) { + transform = factory(handler, transform, self.$vm); + }); - var _ = __webpack_require__(1); - var PromiseObj = window.Promise || __webpack_require__(11); + return transform(options); +} - function Promise(executor, context) { +/** + * Url options. + */ - if (executor instanceof PromiseObj) { - this.promise = executor; - } else { - this.promise = new PromiseObj(executor.bind(context)); - } +Url.options = { + url: '', + root: null, + params: {} +}; - this.context = context; - } +/** + * Url transforms. + */ - Promise.all = function (iterable, context) { - return new Promise(PromiseObj.all(iterable), context); - }; +Url.transforms = [template, legacy, query, root]; - Promise.resolve = function (value, context) { - return new Promise(PromiseObj.resolve(value), context); - }; +/** + * Encodes a Url parameter string. + * + * @param {Object} obj + */ - Promise.reject = function (reason, context) { - return new Promise(PromiseObj.reject(reason), context); - }; +Url.params = function (obj) { - Promise.race = function (iterable, context) { - return new Promise(PromiseObj.race(iterable), context); - }; + var params = [], + escape = encodeURIComponent; - var p = Promise.prototype; + params.add = function (key, value) { - p.bind = function (context) { - this.context = context; - return this; - }; + if (isFunction(value)) { + value = value(); + } - p.then = function (fulfilled, rejected) { + if (value === null) { + value = ''; + } - if (fulfilled && fulfilled.bind && this.context) { - fulfilled = fulfilled.bind(this.context); - } + this.push(escape(key) + '=' + escape(value)); + }; - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } + serialize(params, obj); - this.promise = this.promise.then(fulfilled, rejected); + return params.join('&').replace(/%20/g, '+'); +}; - return this; - }; +/** + * Parse a URL and return its components. + * + * @param {String} url + */ - p.catch = function (rejected) { +Url.parse = function (url) { + + if (ie) { + el.href = url; + url = el.href; + } + + el.href = url; + + 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(/^#/, '') : '' + }; +}; + +function factory(handler, next, vm) { + return function (options) { + return handler.call(vm, options, next); + }; +} + +function serialize(params, obj, scope) { + + var array = isArray(obj), + plain = isPlainObject(obj), + hash; + + each(obj, function (value, key) { + + hash = isObject(value) || isArray(value); + + if (scope) { + key = scope + '[' + (plain || hash ? key : '') + ']'; + } + + if (!scope && array) { + params.add(value.name, value.value); + } else if (hash) { + serialize(params, value, key); + } else { + params.add(key, value); + } + }); +} - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } +/** + * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) + */ - this.promise = this.promise.catch(rejected); +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 === 'undefined' ? 'undefined' : _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) { + + if (executor instanceof PromiseObj) { + this.promise = executor; + } else { + this.promise = new PromiseObj(executor.bind(context)); + } + + this.context = context; +} + +Promise$1.all = function (iterable, context) { + return new Promise$1(PromiseObj.all(iterable), context); +}; + +Promise$1.resolve = function (value, context) { + return new Promise$1(PromiseObj.resolve(value), context); +}; + +Promise$1.reject = function (reason, context) { + return new Promise$1(PromiseObj.reject(reason), context); +}; + +Promise$1.race = function (iterable, context) { + return new Promise$1(PromiseObj.race(iterable), context); +}; + +var p = Promise$1.prototype; - return this; - }; +p.bind = function (context) { + this.context = context; + return this; +}; - p.finally = function (callback) { +p.then = function (fulfilled, rejected) { - return this.then(function (value) { - callback.call(this); - return value; - }, function (reason) { - callback.call(this); - return PromiseObj.reject(reason); - }); - }; + if (fulfilled && fulfilled.bind && this.context) { + fulfilled = fulfilled.bind(this.context); + } - p.success = function (callback) { + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } - _.warn('The `success` method has been deprecated. Use the `then` method instead.'); + this.promise = this.promise.then(fulfilled, rejected); - return this.then(function (response) { - return callback.call(this, response.data, response.status, response) || response; - }); - }; + return this; +}; - p.error = function (callback) { +p.catch = function (rejected) { - _.warn('The `error` method has been deprecated. Use the `catch` method instead.'); + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } - return this.catch(function (response) { - return callback.call(this, response.data, response.status, response) || response; - }); - }; + this.promise = this.promise.catch(rejected); - p.always = function (callback) { + return this; +}; - _.warn('The `always` method has been deprecated. Use the `finally` method instead.'); +p.finally = function (callback) { - var cb = function cb(response) { - return callback.call(this, response.data, response.status, response) || response; - }; + return this.then(function (value) { + callback.call(this); + return value; + }, function (reason) { + callback.call(this); + return PromiseObj.reject(reason); + }); +}; - return this.then(cb, cb); - }; +p.success = function (callback) { - module.exports = Promise; + warn('The `success` method has been deprecated. Use the `then` method instead.'); -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { + return this.then(function (response) { + return callback.call(this, response.data, response.status, response) || response; + }); +}; - 'use strict'; +p.error = function (callback) { - var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + warn('The `error` method has been deprecated. Use the `catch` method instead.'); - /** - * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) - */ + return this.catch(function (response) { + return callback.call(this, response.data, response.status, response) || response; + }); +}; - var _ = __webpack_require__(1); +p.always = function (callback) { - var RESOLVED = 0; - var REJECTED = 1; - var PENDING = 2; - - function Promise(executor) { + warn('The `always` method has been deprecated. Use the `finally` method instead.'); - 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.reject = function (r) { - return new Promise(function (resolve, reject) { - reject(r); - }); - }; - - Promise.resolve = function (x) { - return new Promise(function (resolve, reject) { - resolve(x); - }); - }; - - Promise.all = function all(iterable) { - return new Promise(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.resolve(iterable[i]).then(resolver(i), reject); - } - }); - }; - - Promise.race = function race(iterable) { - return new Promise(function (resolve, reject) { - for (var i = 0; i < iterable.length; i += 1) { - Promise.resolve(iterable[i]).then(resolve, reject); - } - }); - }; - - var p = Promise.prototype; - - p.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 === 'undefined' ? 'undefined' : _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.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.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.then = function then(onResolved, onRejected) { - var promise = this; - - return new Promise(function (resolve, reject) { - promise.deferred.push([onResolved, onRejected, resolve, reject]); - promise.notify(); - }); - }; - - p.catch = function (onRejected) { - return this.then(undefined, onRejected); - }; - - module.exports = Promise; - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * XMLHttp client. - */ - - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - - module.exports = function (request) { - return new Promise(function (resolve) { - - var xhr = new XMLHttpRequest(), - response = { request: request }, - handler; - - request.cancel = function () { - xhr.abort(); - }; - - xhr.open(request.method, _.url(request), true); - - handler = function handler(event) { + var cb = function cb(response) { + return callback.call(this, response.data, response.status, response) || response; + }; - response.data = xhr.responseText; - response.status = xhr.status; - response.statusText = xhr.statusText; - response.headers = xhr.getAllResponseHeaders(); + return this.then(cb, cb); +}; - resolve(response); - }; +function xdrClient (request) { + return new Promise$1(function (resolve) { - xhr.timeout = 0; - xhr.onload = handler; - xhr.onabort = handler; - xhr.onerror = handler; - xhr.ontimeout = function () {}; - xhr.onprogress = function () {}; + var xdr = new XDomainRequest(), + response = { request: request }, + handler; - if (_.isPlainObject(request.xhr)) { - _.extend(xhr, request.xhr); - } + request.cancel = function () { + xdr.abort(); + }; - if (_.isPlainObject(request.upload)) { - _.extend(xhr.upload, request.upload); - } + xdr.open(request.method, Url(request), true); - _.each(request.headers || {}, function (value, header) { - xhr.setRequestHeader(header, value); - }); + handler = function handler(event) { - xhr.send(request.data); - }); - }; + response.data = xdr.responseText; + response.status = xdr.status; + response.statusText = xdr.statusText || ''; -/***/ }, -/* 13 */ -/***/ function(module, exports, __webpack_require__) { + resolve(response); + }; - 'use strict'; + xdr.timeout = 0; + xdr.onload = handler; + xdr.onabort = handler; + xdr.onerror = handler; + xdr.ontimeout = function () {}; + xdr.onprogress = function () {}; - /** - * Interceptor factory. - */ + xdr.send(request.data); + }); +} - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); +var originUrl = Url.parse(location.href); +var supportCors = 'withCredentials' in new XMLHttpRequest(); - module.exports = function (handler, vm) { +var exports$1 = { + request: function request(_request) { - return function (client) { + if (_request.crossOrigin === null) { + _request.crossOrigin = crossOrigin(_request); + } - if (_.isFunction(handler)) { - handler = handler.call(vm, Promise); - } + if (_request.crossOrigin) { - return function (request) { + if (!supportCors) { + _request.client = xdrClient; + } - if (_.isFunction(handler.request)) { - request = handler.request.call(vm, request); - } + _request.emulateHTTP = false; + } - return when(request, function (request) { - return when(client(request), function (response) { + return _request; + } +}; - if (_.isFunction(handler.response)) { - response = handler.response.call(vm, response); - } +function crossOrigin(request) { - return response; - }); - }); - }; - }; - }; + var requestUrl = Url.parse(Url(request)); - function when(value, fulfilled, rejected) { + return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host; +} - var promise = Promise.resolve(value); +var exports$2 = { + request: function request(_request) { - if (arguments.length < 2) { - return promise; - } + if (_request.emulateJSON && isPlainObject(_request.data)) { + _request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; + _request.data = Url.params(_request.data); + } - return promise.then(fulfilled, rejected); - } + if (isObject(_request.data) && /FormData/i.test(_request.data.toString())) { + delete _request.headers['Content-Type']; + } -/***/ }, -/* 14 */ -/***/ function(module, exports, __webpack_require__) { + if (isPlainObject(_request.data)) { + _request.data = JSON.stringify(_request.data); + } - 'use strict'; + return _request; + }, + response: function response(_response) { - /** - * Before Interceptor. - */ + try { + _response.data = JSON.parse(_response.data); + } catch (e) {} - var _ = __webpack_require__(1); + return _response; + } +}; - module.exports = { +function jsonpClient (request) { + return new Promise$1(function (resolve) { - request: function request(_request) { + var callback = '_jsonp' + Math.random().toString(36).substr(2), + response = { request: request, data: null }, + handler, + script; - if (_.isFunction(_request.beforeSend)) { - _request.beforeSend.call(this, _request); - } + request.params[request.jsonp] = callback; + request.cancel = function () { + handler({ type: 'cancel' }); + }; - return _request; - } + script = document.createElement('script'); + script.src = Url(request); + script.type = 'text/javascript'; + script.async = true; - }; + window[callback] = function (data) { + response.data = data; + }; -/***/ }, -/* 15 */ -/***/ function(module, exports) { + handler = function handler(event) { - "use strict"; + if (event.type === 'load' && response.data !== null) { + response.status = 200; + } else if (event.type === 'error') { + response.status = 404; + } else { + response.status = 0; + } - /** - * Timeout Interceptor. - */ + resolve(response); - module.exports = function () { + delete window[callback]; + document.body.removeChild(script); + }; - var timeout; + script.onload = handler; + script.onerror = handler; - return { + document.body.appendChild(script); + }); +} - request: function request(_request) { +var exports$3 = { + request: function request(_request) { - if (_request.timeout) { - timeout = setTimeout(function () { - _request.cancel(); - }, _request.timeout); - } + if (_request.method == 'JSONP') { + _request.client = jsonpClient; + } - return _request; - }, + return _request; + } +}; - response: function response(_response) { +var exports$4 = { + request: function request(_request) { - clearTimeout(timeout); + if (isFunction(_request.beforeSend)) { + _request.beforeSend.call(this, _request); + } - return _response; - } + return _request; + } +}; - }; - }; +/** + * HTTP method override Interceptor. + */ -/***/ }, -/* 16 */ -/***/ function(module, exports, __webpack_require__) { +var exports$5 = { + request: function request(_request) { - 'use strict'; + if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { + _request.headers['X-HTTP-Method-Override'] = _request.method; + _request.method = 'POST'; + } - /** - * JSONP Interceptor. - */ + return _request; + } +}; - var jsonpClient = __webpack_require__(17); +var exports$6 = { + request: function request(_request) { - module.exports = { + _request.method = _request.method.toUpperCase(); + _request.headers = extend({}, Http.headers.common, !_request.crossOrigin ? Http.headers.custom : {}, Http.headers[_request.method.toLowerCase()], _request.headers); - request: function request(_request) { + if (isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { + extend(_request.params, _request.data); + delete _request.data; + } - if (_request.method == 'JSONP') { - _request.client = jsonpClient; - } + return _request; + } +}; - return _request; - } +/** + * Timeout Interceptor. + */ - }; +var exports$7 = function exports() { -/***/ }, -/* 17 */ -/***/ function(module, exports, __webpack_require__) { + var timeout; - 'use strict'; + return { + request: function request(_request) { - /** - * JSONP client. - */ + if (_request.timeout) { + timeout = setTimeout(function () { + _request.cancel(); + }, _request.timeout); + } - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); + return _request; + }, + response: function response(_response) { - module.exports = function (request) { - return new Promise(function (resolve) { + clearTimeout(timeout); - var callback = '_jsonp' + Math.random().toString(36).substr(2), - response = { request: request, data: null }, - handler, - script; + return _response; + } + }; +}; - request.params[request.jsonp] = callback; - request.cancel = function () { - handler({ type: 'cancel' }); - }; +function interceptor (handler, vm) { - script = document.createElement('script'); - script.src = _.url(request); - script.type = 'text/javascript'; - script.async = true; + return function (client) { - window[callback] = function (data) { - response.data = data; - }; + if (isFunction(handler)) { + handler = handler.call(vm, Promise$1); + } - handler = function handler(event) { + return function (request) { - if (event.type === 'load' && response.data !== null) { - response.status = 200; - } else if (event.type === 'error') { - response.status = 404; - } else { - response.status = 0; - } + if (isFunction(handler.request)) { + request = handler.request.call(vm, request); + } - resolve(response); + return when(request, function (request) { + return when(client(request), function (response) { - delete window[callback]; - document.body.removeChild(script); - }; + if (isFunction(handler.response)) { + response = handler.response.call(vm, response); + } - script.onload = handler; - script.onerror = handler; + return response; + }); + }); + }; + }; +} - document.body.appendChild(script); - }); - }; +function when(value, fulfilled, rejected) { -/***/ }, -/* 18 */ -/***/ function(module, exports) { + var promise = Promise$1.resolve(value); - 'use strict'; + if (arguments.length < 2) { + return promise; + } - /** - * HTTP method override Interceptor. - */ + return promise.then(fulfilled, rejected); +} - module.exports = { +function xhrClient (request) { + return new Promise$1(function (resolve) { - request: function request(_request) { + var xhr = new XMLHttpRequest(), + response = { request: request }, + handler; - if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { - _request.headers['X-HTTP-Method-Override'] = _request.method; - _request.method = 'POST'; - } + request.cancel = function () { + xhr.abort(); + }; - return _request; - } + xhr.open(request.method, Url(request), true); - }; + handler = function handler(event) { -/***/ }, -/* 19 */ -/***/ function(module, exports, __webpack_require__) { + response.data = 'response' in xhr ? xhr.response : xhr.responseText; + response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug + response.statusText = trim(xhr.statusText || ''); + response.headers = xhr.getAllResponseHeaders(); - 'use strict'; + resolve(response); + }; - /** - * Mime Interceptor. - */ + xhr.timeout = 0; + xhr.onload = handler; + xhr.onabort = handler; + xhr.onerror = handler; + xhr.ontimeout = function () {}; + xhr.onprogress = function () {}; - var _ = __webpack_require__(1); + if (isPlainObject(request.xhr)) { + extend(xhr, request.xhr); + } - module.exports = { + if (isPlainObject(request.upload)) { + extend(xhr.upload, request.upload); + } - request: function request(_request) { + each(request.headers || {}, function (value, header) { + xhr.setRequestHeader(header, value); + }); - if (_request.emulateJSON && _.isPlainObject(_request.data)) { - _request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - _request.data = _.url.params(_request.data); - } + xhr.send(request.data); + }); +} - if (_.isObject(_request.data) && /FormData/i.test(_request.data.toString())) { - delete _request.headers['Content-Type']; - } +function Client (request) { - if (_.isPlainObject(_request.data)) { - _request.data = JSON.stringify(_request.data); - } + var response = (request.client || xhrClient)(request); - return _request; - }, + return Promise$1.resolve(response).then(function (response) { - response: function response(_response) { + if (response.headers) { - try { - _response.data = JSON.parse(_response.data); - } catch (e) {} + var headers = parseHeaders(response.headers); - return _response; - } + response.headers = function (name) { - }; + if (name) { + return headers[toLower(name)]; + } -/***/ }, -/* 20 */ -/***/ function(module, exports, __webpack_require__) { + return headers; + }; + } - 'use strict'; + response.ok = response.status >= 200 && response.status < 300; - /** - * Header Interceptor. - */ + return response; + }); +} - var _ = __webpack_require__(1); +function parseHeaders(str) { - module.exports = { + var headers = {}, + value, + name, + i; - request: function request(_request) { + if (isString(str)) { + each(str.split('\n'), function (row) { - _request.method = _request.method.toUpperCase(); - _request.headers = _.extend({}, _.http.headers.common, !_request.crossOrigin ? _.http.headers.custom : {}, _.http.headers[_request.method.toLowerCase()], _request.headers); + i = row.indexOf(':'); + name = trim(toLower(row.slice(0, i))); + value = trim(row.slice(i + 1)); - if (_.isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { - _.extend(_request.params, _request.data); - delete _request.data; - } + if (headers[name]) { - return _request; - } + if (isArray(headers[name])) { + headers[name].push(value); + } else { + headers[name] = [headers[name], value]; + } + } else { - }; + headers[name] = value; + } + }); + } -/***/ }, -/* 21 */ -/***/ function(module, exports, __webpack_require__) { + return headers; +} - 'use strict'; +/** + * Service for sending network requests. + */ - /** - * CORS Interceptor. - */ +var jsonType = { 'Content-Type': 'application/json' }; - var _ = __webpack_require__(1); - var xdrClient = __webpack_require__(22); - var xhrCors = 'withCredentials' in new XMLHttpRequest(); - var originUrl = _.url.parse(location.href); +function Http(url, options) { - module.exports = { + var self = this || {}, + client = Client, + request, + promise; - request: function request(_request) { + Http.interceptors.forEach(function (handler) { + client = interceptor(handler, self.$vm)(client); + }); - if (_request.crossOrigin === null) { - _request.crossOrigin = crossOrigin(_request); - } + options = isObject(url) ? url : extend({ url: url }, options); + request = merge({}, Http.options, self.$options, options); + promise = client(request).bind(self.$vm).then(function (response) { - if (_request.crossOrigin) { + return response.ok ? response : Promise$1.reject(response); + }, function (response) { - if (!xhrCors) { - _request.client = xdrClient; - } + if (response instanceof Error) { + error(response); + } - _request.emulateHTTP = false; - } + return Promise$1.reject(response); + }); - return _request; - } + if (request.success) { + promise.success(request.success); + } - }; + if (request.error) { + promise.error(request.error); + } - function crossOrigin(request) { + return promise; +} - var requestUrl = _.url.parse(_.url(request)); +Http.options = { + method: 'get', + data: '', + params: {}, + headers: {}, + xhr: null, + upload: null, + jsonp: 'callback', + beforeSend: null, + crossOrigin: null, + emulateHTTP: false, + emulateJSON: false, + timeout: 0 +}; - return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host; - } +Http.headers = { + put: jsonType, + post: jsonType, + patch: jsonType, + delete: jsonType, + common: { 'Accept': 'application/json, text/plain, */*' }, + custom: { 'X-Requested-With': 'XMLHttpRequest' } +}; -/***/ }, -/* 22 */ -/***/ function(module, exports, __webpack_require__) { +Http.interceptors = [exports$4, exports$7, exports$3, exports$5, exports$2, exports$6, exports$1]; - 'use strict'; +['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { - /** - * XDomain client (Internet Explorer). - */ + Http[method] = function (url, data, success, options) { - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); + if (isFunction(data)) { + options = success; + success = data; + data = undefined; + } - module.exports = function (request) { - return new Promise(function (resolve) { + if (isObject(success)) { + options = success; + success = undefined; + } - var xdr = new XDomainRequest(), - response = { request: request }, - handler; + return this(url, extend({ method: method, data: data, success: success }, options)); + }; +}); - request.cancel = function () { - xdr.abort(); - }; +function Resource(url, params, actions, options) { - xdr.open(request.method, _.url(request), true); + var self = this || {}, + resource = {}; - handler = function handler(event) { + actions = extend({}, Resource.actions, actions); - response.data = xdr.responseText; - response.status = xdr.status; - response.statusText = xdr.statusText; + each(actions, function (action, name) { - resolve(response); - }; + action = merge({ url: url, params: params || {} }, options, action); - xdr.timeout = 0; - xdr.onload = handler; - xdr.onabort = handler; - xdr.onerror = handler; - xdr.ontimeout = function () {}; - xdr.onprogress = function () {}; + resource[name] = function () { + return (self.$http || Http)(opts(action, arguments)); + }; + }); - xdr.send(request.data); - }); - }; + return resource; +} -/***/ }, -/* 23 */ -/***/ function(module, exports, __webpack_require__) { +function opts(action, args) { - 'use strict'; + var options = extend({}, action), + params = {}, + data, + success, + error; - /** - * Service for interacting with RESTful services. - */ + switch (args.length) { - var _ = __webpack_require__(1); + case 4: - function Resource(url, params, actions, options) { + error = args[3]; + success = args[2]; - var self = this, - resource = {}; + case 3: + case 2: - actions = _.extend({}, Resource.actions, actions); + if (isFunction(args[1])) { - _.each(actions, function (action, name) { + if (isFunction(args[0])) { - action = _.merge({ url: url, params: params || {} }, options, action); + success = args[0]; + error = args[1]; - resource[name] = function () { - return (self.$http || _.http)(opts(action, arguments)); - }; - }); + break; + } - return resource; - } + success = args[1]; + error = args[2]; + } else { - function opts(action, args) { + params = args[0]; + data = args[1]; + success = args[2]; - var options = _.extend({}, action), - params = {}, - data, - success, - error; + break; + } - switch (args.length) { + case 1: - case 4: + if (isFunction(args[0])) { + success = args[0]; + } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) { + data = args[0]; + } else { + params = args[0]; + } - error = args[3]; - success = args[2]; + break; - case 3: - case 2: + case 0: - if (_.isFunction(args[1])) { + break; - if (_.isFunction(args[0])) { + default: - success = args[0]; - error = args[1]; + throw 'Expected up to 4 arguments [params, data, success, error], got ' + args.length + ' arguments'; + } - break; - } + options.data = data; + options.params = extend({}, options.params, params); - success = args[1]; - error = args[2]; - } else { + if (success) { + options.success = success; + } - params = args[0]; - data = args[1]; - success = args[2]; + if (error) { + options.error = error; + } - break; - } + return options; +} - case 1: +Resource.actions = { - if (_.isFunction(args[0])) { - success = args[0]; - } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) { - data = args[0]; - } else { - params = args[0]; - } + get: { method: 'GET' }, + save: { method: 'POST' }, + query: { method: 'GET' }, + update: { method: 'PUT' }, + remove: { method: 'DELETE' }, + delete: { method: 'DELETE' } - break; +}; - case 0: +function plugin(Vue) { - break; + if (plugin.installed) { + return; + } - default: + Util(Vue); - throw 'Expected up to 4 arguments [params, data, success, error], got ' + args.length + ' arguments'; - } + Vue.url = Url; + Vue.http = Http; + Vue.resource = Resource; + Vue.Promise = Promise$1; - options.data = data; - options.params = _.extend({}, options.params, params); + Object.defineProperties(Vue.prototype, { - if (success) { - options.success = success; - } + $url: { + get: function get() { + return options(Vue.url, this, this.$options.url); + } + }, - if (error) { - options.error = error; - } + $http: { + get: function get() { + return options(Vue.http, this, this.$options.http); + } + }, - return options; - } + $resource: { + get: function get() { + return Vue.resource.bind(this); + } + }, - Resource.actions = { + $promise: { + get: function get() { + var _this = this; - get: { method: 'GET' }, - save: { method: 'POST' }, - query: { method: 'GET' }, - update: { method: 'PUT' }, - remove: { method: 'DELETE' }, - delete: { method: 'DELETE' } + return function (executor) { + return new Vue.Promise(executor, _this); + }; + } + } - }; + }); +} - module.exports = _.resource = Resource; +if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(plugin); +} -/***/ } -/******/ ]); \ No newline at end of file +module.exports = plugin; \ No newline at end of file diff --git a/dist/vue-resource.js b/dist/vue-resource.js index dc23ad0d..266c93f2 100644 --- a/dist/vue-resource.js +++ b/dist/vue-resource.js @@ -1,1716 +1,1382 @@ -/** - * vue-resource v0.7.3 +/*! + * vue-resource v0.7.4 * https://github.com/vuejs/vue-resource * Released under the MIT License. */ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["VueResource"] = factory(); - else - root["VueResource"] = factory(); -})(this, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.VueResource = factory()); +}(this, function () { 'use strict'; -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + }; -/******/ // Flag the module as loaded -/******/ module.loaded = true; + /** + * Utility functions. + */ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } + var util = {}; + var config = {}; + var array = []; + var console = window.console; + function Util (Vue) { + util = Vue.util; + config = Vue.config; + } + var isArray = Array.isArray; + + function warn(msg) { + if (console && util.warn && (!config.silent || config.debug)) { + console.warn('[VueResource warn]: ' + msg); + } + } + + function error(msg) { + if (console) { + console.error(msg); + } + } + + function nextTick(cb, ctx) { + return util.nextTick(cb, ctx); + } + + function trim(str) { + return str.replace(/^\s*|\s*$/g, ''); + } + + function toLower(str) { + return str ? str.toLowerCase() : ''; + } + + function isString(val) { + return typeof val === 'string'; + } + + function isFunction(val) { + return typeof val === 'function'; + } + + function isObject(obj) { + return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; + } + + function isPlainObject(obj) { + return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; + } -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { + function options(fn, obj, opts) { - 'use strict'; + opts = opts || {}; - /** - * Install plugin. - */ + if (isFunction(opts)) { + opts = opts.call(obj); + } - function plugin(Vue) { + return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts }); + } - if (plugin.installed) { - return; - } + function each(obj, iterator) { - var _ = __webpack_require__(1); + var i, key; - _.config = Vue.config; - _.warning = Vue.util.warn; - _.nextTick = Vue.util.nextTick; + 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); + } + } + } - Vue.url = __webpack_require__(2); - Vue.http = __webpack_require__(8); - Vue.resource = __webpack_require__(23); - Vue.Promise = __webpack_require__(10); + return obj; + } - Object.defineProperties(Vue.prototype, { + function extend(target) { - $url: { - get: function get() { - return _.options(Vue.url, this, this.$options.url); - } - }, + var args = array.slice.call(arguments, 1); - $http: { - get: function get() { - return _.options(Vue.http, this, this.$options.http); - } - }, + args.forEach(function (arg) { + _merge(target, arg); + }); - $resource: { - get: function get() { - return Vue.resource.bind(this); - } - }, + return target; + } - $promise: { - get: function get() { - var _this = this; + function merge(target) { - return function (executor) { - return new Vue.Promise(executor, _this); - }; - } - } + var args = array.slice.call(arguments, 1); - }); - } + args.forEach(function (arg) { + _merge(target, arg, true); + }); - if (typeof window !== 'undefined' && window.Vue) { - window.Vue.use(plugin); - } + return target; + } - module.exports = plugin; + 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]; + } + } + } -/***/ }, -/* 1 */ -/***/ function(module, exports) { + function root (options, next) { - 'use strict'; + var url = next(options); - var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + if (isString(options.root) && !url.match(/^(https?:)?\//)) { + url = options.root + '/' + url; + } - /** - * Utility functions. - */ + return url; + } - var _ = exports, - array = [], - console = window.console; + function query (options, next) { - _.warn = function (msg) { - if (console && _.warning && (!_.config.silent || _.config.debug)) { - console.warn('[VueResource warn]: ' + msg); - } - }; + var urlParams = Object.keys(Url.options.params), + query = {}, + url = next(options); - _.error = function (msg) { - if (console) { - console.error(msg); - } - }; + each(options.params, function (value, key) { + if (urlParams.indexOf(key) === -1) { + query[key] = value; + } + }); - _.trim = function (str) { - return str.replace(/^\s*|\s*$/g, ''); - }; + query = Url.params(query); - _.toLower = function (str) { - return str ? str.toLowerCase() : ''; - }; + if (query) { + url += (url.indexOf('?') == -1 ? '?' : '&') + query; + } - _.isArray = Array.isArray; + return url; + } - _.isString = function (val) { - return typeof val === 'string'; - }; + function legacy (options, next) { - _.isFunction = function (val) { - return typeof val === 'function'; - }; + var variables = [], + url = next(options); - _.isObject = function (obj) { - return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; - }; + url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { - _.isPlainObject = function (obj) { - return _.isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype; - }; + warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); - _.options = function (fn, obj, options) { + if (options.params[name]) { + variables.push(name); + return slash + encodeUriSegment(options.params[name]); + } - options = options || {}; + return ''; + }); - if (_.isFunction(options)) { - options = options.call(obj); - } + variables.forEach(function (key) { + delete options.params[key]; + }); - return _.merge(fn.bind({ $vm: obj, $options: options }), fn, { $options: options }); - }; + return url; + } - _.each = function (obj, iterator) { + function encodeUriSegment(value) { - var i, key; + return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+'); + } - 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 encodeUriQuery(value, spaces) { - return obj; - }; + return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+'); + } - _.defaults = function (target, source) { + /** + * URL Template v2.0.6 (https://github.com/bramstein/url-template) + */ + + function expand(url, params, variables) { + + var tmpl = parse(url), + expanded = tmpl.expand(params); + + if (variables) { + variables.push.apply(variables, tmpl.vars); + } + + return expanded; + } + + function parse(template) { + + var operators = ['+', '#', '.', '/', ';', '?', '&'], + variables = []; + + return { + vars: variables, + expand: function expand(context) { + return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { + if (expression) { + + var operator = null, + values = []; + + if (operators.indexOf(expression.charAt(0)) !== -1) { + operator = expression.charAt(0); + expression = expression.substr(1); + } + + 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]); + }); + + if (operator && operator !== '+') { + + var separator = ','; + + if (operator === '?') { + separator = '&'; + } else if (operator !== '#') { + separator = operator; + } + + return (values.length !== 0 ? operator : '') + values.join(separator); + } else { + return values.join(','); + } + } else { + return encodeReserved(literal); + } + }); + } + }; + } + + function getValues(context, operator, key, modifier) { + + var value = context[key], + result = []; + + if (isDefined(value) && value !== '') { + if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { + value = value.toString(); + + if (modifier && modifier !== '*') { + value = value.substring(0, parseInt(modifier, 10)); + } + + 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 = []; + + 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())); + } + }); + } + + 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(''); + } + } + + return result; + } + + function isDefined(value) { + return value !== undefined && value !== null; + } + + function isKeyOperator(operator) { + return operator === ';' || operator === '&' || operator === '?'; + } + + function encodeValue(operator, value, key) { + + value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value); + + if (key) { + return encodeURIComponent(key) + '=' + value; + } else { + return value; + } + } + + 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(''); + } + + function template (options) { + + var variables = [], + url = expand(options.url, options.params, variables); + + variables.forEach(function (key) { + delete options.params[key]; + }); + + return url; + } + + /** + * Service for URL templating. + */ + + var ie = document.documentMode; + var el = document.createElement('a'); + + function Url(url, params) { + + var self = this || {}, + options = url, + transform; + + if (isString(url)) { + options = { url: url, params: params }; + } + + options = merge({}, Url.options, self.$options, options); + + Url.transforms.forEach(function (handler) { + transform = factory(handler, transform, self.$vm); + }); + + return transform(options); + } + + /** + * Url options. + */ + + Url.options = { + url: '', + root: null, + params: {} + }; + + /** + * Url transforms. + */ + + Url.transforms = [template, legacy, query, root]; + + /** + * Encodes a Url parameter string. + * + * @param {Object} obj + */ - for (var key in source) { - if (target[key] === undefined) { - target[key] = source[key]; - } - } + Url.params = function (obj) { - return target; - }; + var params = [], + escape = encodeURIComponent; - _.extend = function (target) { + params.add = function (key, value) { - var args = array.slice.call(arguments, 1); + if (isFunction(value)) { + value = value(); + } - args.forEach(function (arg) { - merge(target, arg); - }); + if (value === null) { + value = ''; + } - return target; - }; + this.push(escape(key) + '=' + escape(value)); + }; + + serialize(params, obj); - _.merge = function (target) { + return params.join('&').replace(/%20/g, '+'); + }; + + /** + * Parse a URL and return its components. + * + * @param {String} url + */ + + Url.parse = function (url) { + + if (ie) { + el.href = url; + url = el.href; + } + + el.href = url; + + 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(/^#/, '') : '' + }; + }; + + function factory(handler, next, vm) { + return function (options) { + return handler.call(vm, options, next); + }; + } + + function serialize(params, obj, scope) { + + var array = isArray(obj), + plain = isPlainObject(obj), + hash; + + each(obj, function (value, key) { + + hash = isObject(value) || isArray(value); + + if (scope) { + key = scope + '[' + (plain || hash ? key : '') + ']'; + } + + if (!scope && array) { + params.add(value.name, value.value); + } else if (hash) { + serialize(params, value, key); + } else { + params.add(key, value); + } + }); + } + + /** + * 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 === 'undefined' ? 'undefined' : _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) { + + if (executor instanceof PromiseObj) { + this.promise = executor; + } else { + this.promise = new PromiseObj(executor.bind(context)); + } + + this.context = context; + } + + Promise$1.all = function (iterable, context) { + return new Promise$1(PromiseObj.all(iterable), context); + }; + + Promise$1.resolve = function (value, context) { + return new Promise$1(PromiseObj.resolve(value), context); + }; + + Promise$1.reject = function (reason, context) { + return new Promise$1(PromiseObj.reject(reason), context); + }; + + Promise$1.race = function (iterable, context) { + return new Promise$1(PromiseObj.race(iterable), context); + }; + + var p = Promise$1.prototype; - var args = array.slice.call(arguments, 1); + p.bind = function (context) { + this.context = context; + return this; + }; - args.forEach(function (arg) { - merge(target, arg, true); - }); + p.then = function (fulfilled, rejected) { - return target; - }; + if (fulfilled && fulfilled.bind && this.context) { + fulfilled = fulfilled.bind(this.context); + } - 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]; - } - } - } + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } -/***/ }, -/* 2 */ -/***/ function(module, exports, __webpack_require__) { + this.promise = this.promise.then(fulfilled, rejected); - 'use strict'; + return this; + }; - /** - * Service for URL templating. - */ + p.catch = function (rejected) { - var _ = __webpack_require__(1); - var ie = document.documentMode; - var el = document.createElement('a'); + if (rejected && rejected.bind && this.context) { + rejected = rejected.bind(this.context); + } - function Url(url, params) { + this.promise = this.promise.catch(rejected); - var options = url, - transform; + return this; + }; - if (_.isString(url)) { - options = { url: url, params: params }; - } + p.finally = function (callback) { - options = _.merge({}, Url.options, this.$options, options); + return this.then(function (value) { + callback.call(this); + return value; + }, function (reason) { + callback.call(this); + return PromiseObj.reject(reason); + }); + }; - Url.transforms.forEach(function (handler) { - transform = factory(handler, transform, this.$vm); - }, this); + p.success = function (callback) { - return transform(options); - }; + warn('The `success` method has been deprecated. Use the `then` method instead.'); - /** - * Url options. - */ + return this.then(function (response) { + return callback.call(this, response.data, response.status, response) || response; + }); + }; - Url.options = { - url: '', - root: null, - params: {} - }; + p.error = function (callback) { - /** - * Url transforms. - */ + warn('The `error` method has been deprecated. Use the `catch` method instead.'); - Url.transforms = [__webpack_require__(3), __webpack_require__(5), __webpack_require__(6), __webpack_require__(7)]; + return this.catch(function (response) { + return callback.call(this, response.data, response.status, response) || response; + }); + }; - /** - * Encodes a Url parameter string. - * - * @param {Object} obj - */ + p.always = function (callback) { - Url.params = function (obj) { + warn('The `always` method has been deprecated. Use the `finally` method instead.'); - var params = [], - escape = encodeURIComponent; + var cb = function cb(response) { + return callback.call(this, response.data, response.status, response) || response; + }; - params.add = function (key, value) { + return this.then(cb, cb); + }; - if (_.isFunction(value)) { - value = value(); - } + function xdrClient (request) { + return new Promise$1(function (resolve) { - if (value === null) { - value = ''; - } + var xdr = new XDomainRequest(), + response = { request: request }, + handler; - this.push(escape(key) + '=' + escape(value)); - }; + request.cancel = function () { + xdr.abort(); + }; - serialize(params, obj); + xdr.open(request.method, Url(request), true); - return params.join('&').replace(/%20/g, '+'); - }; + handler = function handler(event) { - /** - * Parse a URL and return its components. - * - * @param {String} url - */ + response.data = xdr.responseText; + response.status = xdr.status; + response.statusText = xdr.statusText || ''; - Url.parse = function (url) { + resolve(response); + }; - if (ie) { - el.href = url; - url = el.href; - } + xdr.timeout = 0; + xdr.onload = handler; + xdr.onabort = handler; + xdr.onerror = handler; + xdr.ontimeout = function () {}; + xdr.onprogress = function () {}; - el.href = url; + xdr.send(request.data); + }); + } - 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(/^#/, '') : '' - }; - }; + var originUrl = Url.parse(location.href); + var supportCors = 'withCredentials' in new XMLHttpRequest(); - function factory(handler, next, vm) { - return function (options) { - return handler.call(vm, options, next); - }; - } + var exports$1 = { + request: function request(_request) { - function serialize(params, obj, scope) { + if (_request.crossOrigin === null) { + _request.crossOrigin = crossOrigin(_request); + } - var array = _.isArray(obj), - plain = _.isPlainObject(obj), - hash; + if (_request.crossOrigin) { - _.each(obj, function (value, key) { + if (!supportCors) { + _request.client = xdrClient; + } - hash = _.isObject(value) || _.isArray(value); + _request.emulateHTTP = false; + } - if (scope) { - key = scope + '[' + (plain || hash ? key : '') + ']'; - } + return _request; + } + }; - if (!scope && array) { - params.add(value.name, value.value); - } else if (hash) { - serialize(params, value, key); - } else { - params.add(key, value); - } - }); - } + function crossOrigin(request) { - module.exports = _.url = Url; + var requestUrl = Url.parse(Url(request)); -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { + return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host; + } - 'use strict'; + var exports$2 = { + request: function request(_request) { - /** - * URL Template (RFC 6570) Transform. - */ + if (_request.emulateJSON && isPlainObject(_request.data)) { + _request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; + _request.data = Url.params(_request.data); + } - var UrlTemplate = __webpack_require__(4); + if (isObject(_request.data) && /FormData/i.test(_request.data.toString())) { + delete _request.headers['Content-Type']; + } - module.exports = function (options) { + if (isPlainObject(_request.data)) { + _request.data = JSON.stringify(_request.data); + } - var variables = [], - url = UrlTemplate.expand(options.url, options.params, variables); + return _request; + }, + response: function response(_response) { - variables.forEach(function (key) { - delete options.params[key]; - }); - - return url; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports) { - - 'use strict'; - - /** - * URL Template v2.0.6 (https://github.com/bramstein/url-template) - */ - - exports.expand = function (url, params, variables) { - - var tmpl = this.parse(url), - expanded = tmpl.expand(params); - - if (variables) { - variables.push.apply(variables, tmpl.vars); - } - - return expanded; - }; - - exports.parse = function (template) { - - var operators = ['+', '#', '.', '/', ';', '?', '&'], - variables = []; - - return { - vars: variables, - expand: function expand(context) { - return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) { - if (expression) { - - var operator = null, - values = []; - - if (operators.indexOf(expression.charAt(0)) !== -1) { - operator = expression.charAt(0); - expression = expression.substr(1); - } - - expression.split(/,/g).forEach(function (variable) { - var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable); - values.push.apply(values, exports.getValues(context, operator, tmp[1], tmp[2] || tmp[3])); - variables.push(tmp[1]); - }); - - if (operator && operator !== '+') { - - var separator = ','; - - if (operator === '?') { - separator = '&'; - } else if (operator !== '#') { - separator = operator; - } - - return (values.length !== 0 ? operator : '') + values.join(separator); - } else { - return values.join(','); - } - } else { - return exports.encodeReserved(literal); - } - }); - } - }; - }; - - exports.getValues = function (context, operator, key, modifier) { - - var value = context[key], - result = []; - - if (this.isDefined(value) && value !== '') { - if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { - value = value.toString(); - - if (modifier && modifier !== '*') { - value = value.substring(0, parseInt(modifier, 10)); - } - - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); - } else { - if (modifier === '*') { - if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null)); - }, this); - } else { - Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { - result.push(this.encodeValue(operator, value[k], k)); - } - }, this); - } - } else { - var tmp = []; - - if (Array.isArray(value)) { - value.filter(this.isDefined).forEach(function (value) { - tmp.push(this.encodeValue(operator, value)); - }, this); - } else { - Object.keys(value).forEach(function (k) { - if (this.isDefined(value[k])) { - tmp.push(encodeURIComponent(k)); - tmp.push(this.encodeValue(operator, value[k].toString())); - } - }, this); - } - - if (this.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(''); - } - } - - return result; - }; - - exports.isDefined = function (value) { - return value !== undefined && value !== null; - }; - - exports.isKeyOperator = function (operator) { - return operator === ';' || operator === '&' || operator === '?'; - }; - - exports.encodeValue = function (operator, value, key) { - - value = operator === '+' || operator === '#' ? this.encodeReserved(value) : encodeURIComponent(value); - - if (key) { - return encodeURIComponent(key) + '=' + value; - } else { - return value; - } - }; - - exports.encodeReserved = function (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(''); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; + try { + _response.data = JSON.parse(_response.data); + } catch (e) {} - /** - * Legacy Transform. - */ + return _response; + } + }; - var _ = __webpack_require__(1); + function jsonpClient (request) { + return new Promise$1(function (resolve) { - module.exports = function (options, next) { + var callback = '_jsonp' + Math.random().toString(36).substr(2), + response = { request: request, data: null }, + handler, + script; - var variables = [], - url = next(options); - - url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) { - - _.warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.'); + request.params[request.jsonp] = callback; + request.cancel = function () { + handler({ type: 'cancel' }); + }; - if (options.params[name]) { - variables.push(name); - return slash + encodeUriSegment(options.params[name]); - } + script = document.createElement('script'); + script.src = Url(request); + script.type = 'text/javascript'; + script.async = true; - return ''; - }); + window[callback] = function (data) { + response.data = data; + }; - variables.forEach(function (key) { - delete options.params[key]; - }); + handler = function handler(event) { - return url; - }; + if (event.type === 'load' && response.data !== null) { + response.status = 200; + } else if (event.type === 'error') { + response.status = 404; + } else { + response.status = 0; + } - function encodeUriSegment(value) { + resolve(response); - return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+'); - } + delete window[callback]; + document.body.removeChild(script); + }; - function encodeUriQuery(value, spaces) { + script.onload = handler; + script.onerror = handler; - return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+'); - } + document.body.appendChild(script); + }); + } -/***/ }, -/* 6 */ -/***/ function(module, exports, __webpack_require__) { + var exports$3 = { + request: function request(_request) { - 'use strict'; + if (_request.method == 'JSONP') { + _request.client = jsonpClient; + } - /** - * Query Parameter Transform. - */ + return _request; + } + }; - var _ = __webpack_require__(1); + var exports$4 = { + request: function request(_request) { - module.exports = function (options, next) { + if (isFunction(_request.beforeSend)) { + _request.beforeSend.call(this, _request); + } - var urlParams = Object.keys(_.url.options.params), - query = {}, - url = next(options); + return _request; + } + }; - _.each(options.params, function (value, key) { - if (urlParams.indexOf(key) === -1) { - query[key] = value; - } - }); + /** + * HTTP method override Interceptor. + */ - query = _.url.params(query); + var exports$5 = { + request: function request(_request) { - if (query) { - url += (url.indexOf('?') == -1 ? '?' : '&') + query; - } + if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { + _request.headers['X-HTTP-Method-Override'] = _request.method; + _request.method = 'POST'; + } - return url; - }; + return _request; + } + }; -/***/ }, -/* 7 */ -/***/ function(module, exports, __webpack_require__) { + var exports$6 = { + request: function request(_request) { - 'use strict'; + _request.method = _request.method.toUpperCase(); + _request.headers = extend({}, Http.headers.common, !_request.crossOrigin ? Http.headers.custom : {}, Http.headers[_request.method.toLowerCase()], _request.headers); - /** - * Root Prefix Transform. - */ + if (isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { + extend(_request.params, _request.data); + delete _request.data; + } - var _ = __webpack_require__(1); + return _request; + } + }; - module.exports = function (options, next) { + /** + * Timeout Interceptor. + */ - var url = next(options); + var exports$7 = function exports() { - if (_.isString(options.root) && !url.match(/^(https?:)?\//)) { - url = options.root + '/' + url; - } + var timeout; - return url; - }; + return { + request: function request(_request) { -/***/ }, -/* 8 */ -/***/ function(module, exports, __webpack_require__) { + if (_request.timeout) { + timeout = setTimeout(function () { + _request.cancel(); + }, _request.timeout); + } - 'use strict'; + return _request; + }, + response: function response(_response) { - /** - * Service for sending network requests. - */ + clearTimeout(timeout); - var _ = __webpack_require__(1); - var Client = __webpack_require__(9); - var Promise = __webpack_require__(10); - var interceptor = __webpack_require__(13); - var jsonType = { 'Content-Type': 'application/json' }; + return _response; + } + }; + }; - function Http(url, options) { + function interceptor (handler, vm) { - var self = this || {}, - client = Client, - request, - promise; + return function (client) { - Http.interceptors.forEach(function (handler) { - client = interceptor(handler, self.$vm)(client); - }); + if (isFunction(handler)) { + handler = handler.call(vm, Promise$1); + } - options = _.isObject(url) ? url : _.extend({ url: url }, options); - request = _.merge({}, Http.options, self.$options, options); - promise = client(request).bind(self.$vm).then(function (response) { + return function (request) { - return response.ok ? response : Promise.reject(response); - }, function (response) { + if (isFunction(handler.request)) { + request = handler.request.call(vm, request); + } - if (response instanceof Error) { - _.error(response); - } + return when(request, function (request) { + return when(client(request), function (response) { - return Promise.reject(response); - }); + if (isFunction(handler.response)) { + response = handler.response.call(vm, response); + } - if (request.success) { - promise.success(request.success); - } + return response; + }); + }); + }; + }; + } - if (request.error) { - promise.error(request.error); - } + function when(value, fulfilled, rejected) { - return promise; - } + var promise = Promise$1.resolve(value); - Http.options = { - method: 'get', - data: '', - params: {}, - headers: {}, - xhr: null, - upload: null, - jsonp: 'callback', - beforeSend: null, - crossOrigin: null, - emulateHTTP: false, - emulateJSON: false, - timeout: 0 - }; + if (arguments.length < 2) { + return promise; + } - Http.interceptors = [__webpack_require__(14), __webpack_require__(15), __webpack_require__(16), __webpack_require__(18), __webpack_require__(19), __webpack_require__(20), __webpack_require__(21)]; + return promise.then(fulfilled, rejected); + } - Http.headers = { - put: jsonType, - post: jsonType, - patch: jsonType, - delete: jsonType, - common: { 'Accept': 'application/json, text/plain, */*' }, - custom: { 'X-Requested-With': 'XMLHttpRequest' } - }; + function xhrClient (request) { + return new Promise$1(function (resolve) { - ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { + var xhr = new XMLHttpRequest(), + response = { request: request }, + handler; - Http[method] = function (url, data, success, options) { + request.cancel = function () { + xhr.abort(); + }; - if (_.isFunction(data)) { - options = success; - success = data; - data = undefined; - } + xhr.open(request.method, Url(request), true); - if (_.isObject(success)) { - options = success; - success = undefined; - } + handler = function handler(event) { - return this(url, _.extend({ method: method, data: data, success: success }, options)); - }; - }); + response.data = 'response' in xhr ? xhr.response : xhr.responseText; + response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug + response.statusText = trim(xhr.statusText || ''); + response.headers = xhr.getAllResponseHeaders(); - module.exports = _.http = Http; + resolve(response); + }; -/***/ }, -/* 9 */ -/***/ function(module, exports, __webpack_require__) { + xhr.timeout = 0; + xhr.onload = handler; + xhr.onabort = handler; + xhr.onerror = handler; + xhr.ontimeout = function () {}; + xhr.onprogress = function () {}; - 'use strict'; + if (isPlainObject(request.xhr)) { + extend(xhr, request.xhr); + } - /** - * Base client. - */ + if (isPlainObject(request.upload)) { + extend(xhr.upload, request.upload); + } - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - var xhrClient = __webpack_require__(12); + each(request.headers || {}, function (value, header) { + xhr.setRequestHeader(header, value); + }); - module.exports = function (request) { + xhr.send(request.data); + }); + } - var response = (request.client || xhrClient)(request); + function Client (request) { - return Promise.resolve(response).then(function (response) { + var response = (request.client || xhrClient)(request); - if (response.headers) { + return Promise$1.resolve(response).then(function (response) { - var headers = parseHeaders(response.headers); + if (response.headers) { - response.headers = function (name) { + var headers = parseHeaders(response.headers); - if (name) { - return headers[_.toLower(name)]; - } + response.headers = function (name) { - return headers; - }; - } + if (name) { + return headers[toLower(name)]; + } - response.ok = response.status >= 200 && response.status < 300; + return headers; + }; + } - return response; - }); - }; + response.ok = response.status >= 200 && response.status < 300; - function parseHeaders(str) { + return response; + }); + } - var headers = {}, - value, - name, - i; + function parseHeaders(str) { - if (_.isString(str)) { - _.each(str.split('\n'), function (row) { + var headers = {}, + value, + name, + i; - i = row.indexOf(':'); - name = _.trim(_.toLower(row.slice(0, i))); - value = _.trim(row.slice(i + 1)); + if (isString(str)) { + each(str.split('\n'), function (row) { - if (headers[name]) { + i = row.indexOf(':'); + name = trim(toLower(row.slice(0, i))); + value = trim(row.slice(i + 1)); - if (_.isArray(headers[name])) { - headers[name].push(value); - } else { - headers[name] = [headers[name], value]; - } - } else { + if (headers[name]) { - headers[name] = value; - } - }); - } + if (isArray(headers[name])) { + headers[name].push(value); + } else { + headers[name] = [headers[name], value]; + } + } else { - return headers; - } + headers[name] = value; + } + }); + } -/***/ }, -/* 10 */ -/***/ function(module, exports, __webpack_require__) { + return headers; + } - 'use strict'; + /** + * Service for sending network requests. + */ - /** - * Promise adapter. - */ + var jsonType = { 'Content-Type': 'application/json' }; - var _ = __webpack_require__(1); - var PromiseObj = window.Promise || __webpack_require__(11); + function Http(url, options) { - function Promise(executor, context) { + var self = this || {}, + client = Client, + request, + promise; - if (executor instanceof PromiseObj) { - this.promise = executor; - } else { - this.promise = new PromiseObj(executor.bind(context)); - } + Http.interceptors.forEach(function (handler) { + client = interceptor(handler, self.$vm)(client); + }); - this.context = context; - } + options = isObject(url) ? url : extend({ url: url }, options); + request = merge({}, Http.options, self.$options, options); + promise = client(request).bind(self.$vm).then(function (response) { - Promise.all = function (iterable, context) { - return new Promise(PromiseObj.all(iterable), context); - }; + return response.ok ? response : Promise$1.reject(response); + }, function (response) { - Promise.resolve = function (value, context) { - return new Promise(PromiseObj.resolve(value), context); - }; + if (response instanceof Error) { + error(response); + } - Promise.reject = function (reason, context) { - return new Promise(PromiseObj.reject(reason), context); - }; + return Promise$1.reject(response); + }); - Promise.race = function (iterable, context) { - return new Promise(PromiseObj.race(iterable), context); - }; + if (request.success) { + promise.success(request.success); + } - var p = Promise.prototype; + if (request.error) { + promise.error(request.error); + } - p.bind = function (context) { - this.context = context; - return this; - }; + return promise; + } - p.then = function (fulfilled, rejected) { + Http.options = { + method: 'get', + data: '', + params: {}, + headers: {}, + xhr: null, + upload: null, + jsonp: 'callback', + beforeSend: null, + crossOrigin: null, + emulateHTTP: false, + emulateJSON: false, + timeout: 0 + }; - if (fulfilled && fulfilled.bind && this.context) { - fulfilled = fulfilled.bind(this.context); - } + Http.headers = { + put: jsonType, + post: jsonType, + patch: jsonType, + delete: jsonType, + common: { 'Accept': 'application/json, text/plain, */*' }, + custom: { 'X-Requested-With': 'XMLHttpRequest' } + }; - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } + Http.interceptors = [exports$4, exports$7, exports$3, exports$5, exports$2, exports$6, exports$1]; - this.promise = this.promise.then(fulfilled, rejected); + ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) { - return this; - }; + Http[method] = function (url, data, success, options) { - p.catch = function (rejected) { + if (isFunction(data)) { + options = success; + success = data; + data = undefined; + } - if (rejected && rejected.bind && this.context) { - rejected = rejected.bind(this.context); - } + if (isObject(success)) { + options = success; + success = undefined; + } - this.promise = this.promise.catch(rejected); + return this(url, extend({ method: method, data: data, success: success }, options)); + }; + }); - return this; - }; + function Resource(url, params, actions, options) { - p.finally = function (callback) { + var self = this || {}, + resource = {}; - return this.then(function (value) { - callback.call(this); - return value; - }, function (reason) { - callback.call(this); - return PromiseObj.reject(reason); - }); - }; + actions = extend({}, Resource.actions, actions); - p.success = function (callback) { + each(actions, function (action, name) { - _.warn('The `success` method has been deprecated. Use the `then` method instead.'); + action = merge({ url: url, params: params || {} }, options, action); - return this.then(function (response) { - return callback.call(this, response.data, response.status, response) || response; - }); - }; + resource[name] = function () { + return (self.$http || Http)(opts(action, arguments)); + }; + }); - p.error = function (callback) { + return resource; + } - _.warn('The `error` method has been deprecated. Use the `catch` method instead.'); + function opts(action, args) { - return this.catch(function (response) { - return callback.call(this, response.data, response.status, response) || response; - }); - }; + var options = extend({}, action), + params = {}, + data, + success, + error; - p.always = function (callback) { + switch (args.length) { - _.warn('The `always` method has been deprecated. Use the `finally` method instead.'); + case 4: - var cb = function cb(response) { - return callback.call(this, response.data, response.status, response) || response; - }; + error = args[3]; + success = args[2]; - return this.then(cb, cb); - }; + case 3: + case 2: - module.exports = Promise; + if (isFunction(args[1])) { -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { + if (isFunction(args[0])) { - 'use strict'; + success = args[0]; + error = args[1]; - var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + break; + } - /** - * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis) - */ + success = args[1]; + error = args[2]; + } else { - var _ = __webpack_require__(1); + params = args[0]; + data = args[1]; + success = args[2]; - var RESOLVED = 0; - var REJECTED = 1; - var PENDING = 2; - - function Promise(executor) { + break; + } - 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.reject = function (r) { - return new Promise(function (resolve, reject) { - reject(r); - }); - }; - - Promise.resolve = function (x) { - return new Promise(function (resolve, reject) { - resolve(x); - }); - }; - - Promise.all = function all(iterable) { - return new Promise(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.resolve(iterable[i]).then(resolver(i), reject); - } - }); - }; - - Promise.race = function race(iterable) { - return new Promise(function (resolve, reject) { - for (var i = 0; i < iterable.length; i += 1) { - Promise.resolve(iterable[i]).then(resolve, reject); - } - }); - }; - - var p = Promise.prototype; - - p.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 === 'undefined' ? 'undefined' : _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.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.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.then = function then(onResolved, onRejected) { - var promise = this; - - return new Promise(function (resolve, reject) { - promise.deferred.push([onResolved, onRejected, resolve, reject]); - promise.notify(); - }); - }; - - p.catch = function (onRejected) { - return this.then(undefined, onRejected); - }; - - module.exports = Promise; - -/***/ }, -/* 12 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * XMLHttp client. - */ - - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - - module.exports = function (request) { - return new Promise(function (resolve) { - - var xhr = new XMLHttpRequest(), - response = { request: request }, - handler; - - request.cancel = function () { - xhr.abort(); - }; - - xhr.open(request.method, _.url(request), true); - - handler = function handler(event) { + case 1: - response.data = xhr.responseText; - response.status = xhr.status; - response.statusText = xhr.statusText; - response.headers = xhr.getAllResponseHeaders(); + if (isFunction(args[0])) { + success = args[0]; + } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) { + data = args[0]; + } else { + params = args[0]; + } - resolve(response); - }; + break; - xhr.timeout = 0; - xhr.onload = handler; - xhr.onabort = handler; - xhr.onerror = handler; - xhr.ontimeout = function () {}; - xhr.onprogress = function () {}; + case 0: - if (_.isPlainObject(request.xhr)) { - _.extend(xhr, request.xhr); - } + break; - if (_.isPlainObject(request.upload)) { - _.extend(xhr.upload, request.upload); - } + default: - _.each(request.headers || {}, function (value, header) { - xhr.setRequestHeader(header, value); - }); + throw 'Expected up to 4 arguments [params, data, success, error], got ' + args.length + ' arguments'; + } - xhr.send(request.data); - }); - }; + options.data = data; + options.params = extend({}, options.params, params); -/***/ }, -/* 13 */ -/***/ function(module, exports, __webpack_require__) { + if (success) { + options.success = success; + } - 'use strict'; + if (error) { + options.error = error; + } - /** - * Interceptor factory. - */ + return options; + } - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); + Resource.actions = { - module.exports = function (handler, vm) { + get: { method: 'GET' }, + save: { method: 'POST' }, + query: { method: 'GET' }, + update: { method: 'PUT' }, + remove: { method: 'DELETE' }, + delete: { method: 'DELETE' } - return function (client) { + }; - if (_.isFunction(handler)) { - handler = handler.call(vm, Promise); - } + function plugin(Vue) { - return function (request) { + if (plugin.installed) { + return; + } - if (_.isFunction(handler.request)) { - request = handler.request.call(vm, request); - } + Util(Vue); - return when(request, function (request) { - return when(client(request), function (response) { + Vue.url = Url; + Vue.http = Http; + Vue.resource = Resource; + Vue.Promise = Promise$1; - if (_.isFunction(handler.response)) { - response = handler.response.call(vm, response); - } + Object.defineProperties(Vue.prototype, { - return response; - }); - }); - }; - }; - }; + $url: { + get: function get() { + return options(Vue.url, this, this.$options.url); + } + }, - function when(value, fulfilled, rejected) { + $http: { + get: function get() { + return options(Vue.http, this, this.$options.http); + } + }, - var promise = Promise.resolve(value); + $resource: { + get: function get() { + return Vue.resource.bind(this); + } + }, - if (arguments.length < 2) { - return promise; - } + $promise: { + get: function get() { + var _this = this; - return promise.then(fulfilled, rejected); - } + return function (executor) { + return new Vue.Promise(executor, _this); + }; + } + } -/***/ }, -/* 14 */ -/***/ function(module, exports, __webpack_require__) { + }); + } - 'use strict'; + if (typeof window !== 'undefined' && window.Vue) { + window.Vue.use(plugin); + } - /** - * Before Interceptor. - */ + return plugin; - var _ = __webpack_require__(1); - - module.exports = { - - request: function request(_request) { - - if (_.isFunction(_request.beforeSend)) { - _request.beforeSend.call(this, _request); - } - - return _request; - } - - }; - -/***/ }, -/* 15 */ -/***/ function(module, exports) { - - "use strict"; - - /** - * Timeout Interceptor. - */ - - module.exports = function () { - - var timeout; - - return { - - request: function request(_request) { - - if (_request.timeout) { - timeout = setTimeout(function () { - _request.cancel(); - }, _request.timeout); - } - - return _request; - }, - - response: function response(_response) { - - clearTimeout(timeout); - - return _response; - } - - }; - }; - -/***/ }, -/* 16 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * JSONP Interceptor. - */ - - var jsonpClient = __webpack_require__(17); - - module.exports = { - - request: function request(_request) { - - if (_request.method == 'JSONP') { - _request.client = jsonpClient; - } - - return _request; - } - - }; - -/***/ }, -/* 17 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * JSONP client. - */ - - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - - module.exports = function (request) { - return new Promise(function (resolve) { - - var callback = '_jsonp' + Math.random().toString(36).substr(2), - response = { request: request, data: null }, - handler, - script; - - request.params[request.jsonp] = callback; - request.cancel = function () { - handler({ type: 'cancel' }); - }; - - script = document.createElement('script'); - script.src = _.url(request); - script.type = 'text/javascript'; - script.async = true; - - window[callback] = function (data) { - response.data = data; - }; - - handler = function handler(event) { - - if (event.type === 'load' && response.data !== null) { - response.status = 200; - } else if (event.type === 'error') { - response.status = 404; - } else { - response.status = 0; - } - - resolve(response); - - delete window[callback]; - document.body.removeChild(script); - }; - - script.onload = handler; - script.onerror = handler; - - document.body.appendChild(script); - }); - }; - -/***/ }, -/* 18 */ -/***/ function(module, exports) { - - 'use strict'; - - /** - * HTTP method override Interceptor. - */ - - module.exports = { - - request: function request(_request) { - - if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) { - _request.headers['X-HTTP-Method-Override'] = _request.method; - _request.method = 'POST'; - } - - return _request; - } - - }; - -/***/ }, -/* 19 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Mime Interceptor. - */ - - var _ = __webpack_require__(1); - - module.exports = { - - request: function request(_request) { - - if (_request.emulateJSON && _.isPlainObject(_request.data)) { - _request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - _request.data = _.url.params(_request.data); - } - - if (_.isObject(_request.data) && /FormData/i.test(_request.data.toString())) { - delete _request.headers['Content-Type']; - } - - if (_.isPlainObject(_request.data)) { - _request.data = JSON.stringify(_request.data); - } - - return _request; - }, - - response: function response(_response) { - - try { - _response.data = JSON.parse(_response.data); - } catch (e) {} - - return _response; - } - - }; - -/***/ }, -/* 20 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Header Interceptor. - */ - - var _ = __webpack_require__(1); - - module.exports = { - - request: function request(_request) { - - _request.method = _request.method.toUpperCase(); - _request.headers = _.extend({}, _.http.headers.common, !_request.crossOrigin ? _.http.headers.custom : {}, _.http.headers[_request.method.toLowerCase()], _request.headers); - - if (_.isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) { - _.extend(_request.params, _request.data); - delete _request.data; - } - - return _request; - } - - }; - -/***/ }, -/* 21 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * CORS Interceptor. - */ - - var _ = __webpack_require__(1); - var xdrClient = __webpack_require__(22); - var xhrCors = 'withCredentials' in new XMLHttpRequest(); - var originUrl = _.url.parse(location.href); - - module.exports = { - - request: function request(_request) { - - if (_request.crossOrigin === null) { - _request.crossOrigin = crossOrigin(_request); - } - - if (_request.crossOrigin) { - - if (!xhrCors) { - _request.client = xdrClient; - } - - _request.emulateHTTP = false; - } - - return _request; - } - - }; - - function crossOrigin(request) { - - var requestUrl = _.url.parse(_.url(request)); - - return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host; - } - -/***/ }, -/* 22 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * XDomain client (Internet Explorer). - */ - - var _ = __webpack_require__(1); - var Promise = __webpack_require__(10); - - module.exports = function (request) { - return new Promise(function (resolve) { - - var xdr = new XDomainRequest(), - response = { request: request }, - handler; - - request.cancel = function () { - xdr.abort(); - }; - - xdr.open(request.method, _.url(request), true); - - handler = function handler(event) { - - response.data = xdr.responseText; - response.status = xdr.status; - response.statusText = xdr.statusText; - - resolve(response); - }; - - xdr.timeout = 0; - xdr.onload = handler; - xdr.onabort = handler; - xdr.onerror = handler; - xdr.ontimeout = function () {}; - xdr.onprogress = function () {}; - - xdr.send(request.data); - }); - }; - -/***/ }, -/* 23 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - /** - * Service for interacting with RESTful services. - */ - - var _ = __webpack_require__(1); - - function Resource(url, params, actions, options) { - - var self = this, - resource = {}; - - actions = _.extend({}, Resource.actions, actions); - - _.each(actions, function (action, name) { - - action = _.merge({ url: url, params: params || {} }, options, action); - - resource[name] = function () { - return (self.$http || _.http)(opts(action, arguments)); - }; - }); - - return resource; - } - - function opts(action, args) { - - var options = _.extend({}, action), - params = {}, - data, - success, - error; - - switch (args.length) { - - case 4: - - error = args[3]; - success = args[2]; - - case 3: - case 2: - - if (_.isFunction(args[1])) { - - if (_.isFunction(args[0])) { - - success = args[0]; - error = args[1]; - - break; - } - - success = args[1]; - error = args[2]; - } else { - - params = args[0]; - data = args[1]; - success = args[2]; - - break; - } - - case 1: - - if (_.isFunction(args[0])) { - success = args[0]; - } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) { - data = args[0]; - } else { - params = args[0]; - } - - break; - - case 0: - - break; - - default: - - throw 'Expected up to 4 arguments [params, data, success, error], got ' + args.length + ' arguments'; - } - - options.data = data; - options.params = _.extend({}, options.params, params); - - if (success) { - options.success = success; - } - - if (error) { - options.error = error; - } - - return options; - } - - Resource.actions = { - - get: { method: 'GET' }, - save: { method: 'POST' }, - query: { method: 'GET' }, - update: { method: 'PUT' }, - remove: { method: 'DELETE' }, - delete: { method: 'DELETE' } - - }; - - module.exports = _.resource = Resource; - -/***/ } -/******/ ]) -}); -; \ No newline at end of file +})); \ No newline at end of file diff --git a/dist/vue-resource.min.js b/dist/vue-resource.min.js index 295c65d5..cfff976d 100644 --- a/dist/vue-resource.min.js +++ b/dist/vue-resource.min.js @@ -1,7 +1,7 @@ -/** - * vue-resource v0.7.3 +/*! + * vue-resource v0.7.4 * https://github.com/vuejs/vue-resource * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueResource=e():t.VueResource=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){if(!r.installed){var e=n(1);e.config=t.config,e.warning=t.util.warn,e.nextTick=t.util.nextTick,t.url=n(2),t.http=n(8),t.resource=n(23),t.Promise=n(10),Object.defineProperties(t.prototype,{$url:{get:function(){return e.options(t.url,this,this.$options.url)}},$http:{get:function(){return e.options(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var e=this;return function(n){return new t.Promise(n,e)}}}})}}"undefined"!=typeof window&&window.Vue&&window.Vue.use(r),t.exports=r},function(t,e){"use strict";function n(t,e,r){for(var i in e)r&&(o.isPlainObject(e[i])||o.isArray(e[i]))?(o.isPlainObject(e[i])&&!o.isPlainObject(t[i])&&(t[i]={}),o.isArray(e[i])&&!o.isArray(t[i])&&(t[i]=[]),n(t[i],e[i],r)):void 0!==e[i]&&(t[i]=e[i])}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},o=e,i=[],s=window.console;o.warn=function(t){s&&o.warning&&(!o.config.silent||o.config.debug)&&s.warn("[VueResource warn]: "+t)},o.error=function(t){s&&s.error(t)},o.trim=function(t){return t.replace(/^\s*|\s*$/g,"")},o.toLower=function(t){return t?t.toLowerCase():""},o.isArray=Array.isArray,o.isString=function(t){return"string"==typeof t},o.isFunction=function(t){return"function"==typeof t},o.isObject=function(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":r(t))},o.isPlainObject=function(t){return o.isObject(t)&&Object.getPrototypeOf(t)==Object.prototype},o.options=function(t,e,n){return n=n||{},o.isFunction(n)&&(n=n.call(e)),o.merge(t.bind({$vm:e,$options:n}),t,{$options:n})},o.each=function(t,e){var n,r;if("number"==typeof t.length)for(n=0;n=200&&t.status<300,t})}},function(t,e,n){"use strict";function r(t,e){t instanceof i?this.promise=t:this.promise=new i(t.bind(e)),this.context=e}var o=n(1),i=window.Promise||n(11);r.all=function(t,e){return new r(i.all(t),e)},r.resolve=function(t,e){return new r(i.resolve(t),e)},r.reject=function(t,e){return new r(i.reject(t),e)},r.race=function(t,e){return new r(i.race(t),e)};var s=r.prototype;s.bind=function(t){return this.context=t,this},s.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)),this.promise=this.promise.then(t,e),this},s["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),this.promise=this.promise["catch"](t),this},s["finally"]=function(t){return this.then(function(e){return t.call(this),e},function(e){return t.call(this),i.reject(e)})},s.success=function(t){return o.warn("The `success` method has been deprecated. Use the `then` method instead."),this.then(function(e){return t.call(this,e.data,e.status,e)||e})},s.error=function(t){return o.warn("The `error` method has been deprecated. Use the `catch` method instead."),this["catch"](function(e){return t.call(this,e.data,e.status,e)||e})},s.always=function(t){o.warn("The `always` method has been deprecated. Use the `finally` method instead.");var e=function(e){return t.call(this,e.data,e.status,e)||e};return this.then(e,e)},t.exports=r},function(t,e,n){"use strict";function r(t){this.state=c,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(n){e.reject(n)}}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},i=n(1),s=0,u=1,c=2;r.reject=function(t){return new r(function(e,n){n(t)})},r.resolve=function(t){return new r(function(e,n){e(t)})},r.all=function(t){return new r(function(e,n){function o(n){return function(r){s[n]=r,i+=1,i===t.length&&e(s)}}var i=0,s=[];0===t.length&&e(s);for(var u=0;u=200&&t.status<300,t})}function M(t){var e,n,r,a={};return i(t)&&h(t.split("\n"),function(t){r=t.indexOf(":"),n=o(u(t.slice(0,r))),e=o(t.slice(r+1)),a[n]?K(a[n])?a[n].push(e):a[n]=[a[n],e]:a[n]=e}),a}function N(t,e){var r,o,u=this||{},i=J;return N.interceptors.forEach(function(t){i=I(t,u.$vm)(i)}),e=s(t)?t:l({url:t},e),r=p({},N.options,u.$options,e),o=i(r).bind(u.$vm).then(function(t){return t.ok?t:U.reject(t)},function(t){return t instanceof Error&&n(t),U.reject(t)}),r.success&&o.success(r.success),r.error&&o.error(r.error),o}function X(t,e,n,r){var o=this||{},u={};return n=l({},X.actions,n),h(n,function(n,i){n=p({url:t,params:e||{}},r,n),u[i]=function(){return(o.$http||N)(V(n,arguments))}}),u}function V(t,e){var n,r,o,u=l({},t),i={};switch(e.length){case 4:o=e[3],r=e[2];case 3:case 2:if(!a(e[1])){i=e[0],n=e[1],r=e[2];break}if(a(e[0])){r=e[0],o=e[1];break}r=e[1],o=e[2];case 1:a(e[0])?r=e[0]:/^(POST|PUT|PATCH)$/i.test(u.method)?n=e[0]:i=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return u.data=n,u.params=l({},u.params,i),r&&(u.success=r),o&&(u.error=o),u}function F(e){F.installed||(t(e),e.url=C,e.http=N,e.resource=X,e.Promise=U,Object.defineProperties(e.prototype,{$url:{get:function(){return f(e.url,this,this.$options.url)}},$http:{get:function(){return f(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 G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},z={},B={},W=[],_=window.console,K=Array.isArray,Q=document.documentMode,Y=document.createElement("a");C.options={url:"",root:null,params:{}},C.transforms=[$,y,v,m],C.params=function(t){var e=[],n=encodeURIComponent;return e.add=function(t,e){a(e)&&(e=e()),null===e&&(e=""),this.push(n(t)+"="+n(e))},q(e,t),e.join("&").replace(/%20/g,"+")},C.parse=function(t){return Q&&(Y.href=t,t=Y.href),Y.href=t,{href:Y.href,protocol:Y.protocol?Y.protocol.replace(/:$/,""):"",port:Y.port,host:Y.host,hostname:Y.hostname,pathname:"/"===Y.pathname.charAt(0)?Y.pathname:"/"+Y.pathname,search:Y.search?Y.search.replace(/^\?/,""):"",hash:Y.hash?Y.hash.replace(/^#/,""):""}};var Z=0,tt=1,et=2;R.reject=function(t){return new R(function(e,n){n(t)})},R.resolve=function(t){return new R(function(e,n){e(t)})},R.all=function(t){return new R(function(e,n){function r(n){return function(r){u[n]=r,o+=1,o===t.length&&e(u)}}var o=0,u=[];0===t.length&&e(u);for(var i=0;i