vuejs 1.0.27 → 1.0.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b8fe823b5c0798ab7d7289029b17fbee80c38e2
4
- data.tar.gz: 05b95e8a0069416315a7ce94c26116307dc89a1b
3
+ metadata.gz: 2f737043f53f61ba47212bfa3b8351aa6096ffe9
4
+ data.tar.gz: 0eb0df43f061b60f5f525926d0d78296295cf4be
5
5
  SHA512:
6
- metadata.gz: 0f840bf40a829a362248484d5042ec354f1752f095d16e5dd101bc4c7e9dee0450149f7474a4e319e8248ec805f870a3e00f882479b2638f9634c2b61dfc3e92
7
- data.tar.gz: 766008ae4e35ad265d7c0b3a65b74625277ec259c5dba45bd46b433f154e9c1a37f55f73d65001ab38c96f339e59918df6818a3acfde6154a28677e18e7bf27f
6
+ metadata.gz: e336f2a9ff8028f9474a42b826b233f386c5f12dc19184139b8741fe1e957523374a150d6780727703386ab021307645330c1657ab6916adf5593f1c3bdcd0f3
7
+ data.tar.gz: f4cea0fcfdba4eed34c4ed1eaa5b85767e53971d446e3c0d6ce902bd0765a632c3a266f2db0b31e4fc3dacb8f156996c623664d88116b29598e895b1ac873d76
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Vuejs ships with the latest [Vue.js + router + resource](http://vuejs.org/) and integrate with Rails' asset pipeline. Vue.js is created by Evan You.
4
4
 
5
- The current version is Vue.js (v1.0.25) + vue-router (v0.7.13) + vue-resource (v0.7.4)
5
+ The current 2.x version is Vue.js (v2.0.1) + vue-router (v2.0.0). Note that Vue 2.x is not compatible with 1.x. vue-router 2.0 only works with Vue 2.x
6
+
7
+ The current 1.x version is Vue.js (v1.0.28) + vue-router (v0.7.13) + vue-resource (v1.0.3)
6
8
 
7
9
  > Reactive Components for Modern Web Interfaces
8
10
 
@@ -34,6 +36,11 @@ Or install it yourself as:
34
36
  //= require_tree .
35
37
  ```
36
38
 
39
+ For 2.x Vue & Router
40
+ ```
41
+ //= require vue2
42
+ //= require vue-router2
43
+ ```
37
44
  ## Development
38
45
 
39
46
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/vuejs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vuejs
2
- VERSION = "1.0.27"
2
+ VERSION = "1.0.28"
3
3
  end
@@ -0,0 +1,13 @@
1
+ # 1.0.28
2
+
3
+ added
4
+ - vuejs v1.0.28
5
+ - vuejs v2.0.1
6
+ - vue-router v2.0.0
7
+ - vue-resource v1.0.3
8
+
9
+ # 1.0.27
10
+
11
+ - vuejs v1.0.26
12
+ - vue-router v0.7.13
13
+ - vue-resource v0.7.3
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-resource v0.7.4
2
+ * vue-resource v1.0.3
3
3
  * https://github.com/vuejs/vue-resource
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,1375 +8,1517 @@
8
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9
9
  typeof define === 'function' && define.amd ? define(factory) :
10
10
  (global.VueResource = factory());
11
- }(this, function () { 'use strict';
12
-
13
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
14
- return typeof obj;
15
- } : function (obj) {
16
- return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
17
- };
18
-
19
- /**
20
- * Utility functions.
21
- */
22
-
23
- var util = {};
24
- var config = {};
25
- var array = [];
26
- var console = window.console;
27
- function Util (Vue) {
28
- util = Vue.util;
29
- config = Vue.config;
30
- }
11
+ }(this, (function () { 'use strict';
31
12
 
32
- var isArray = Array.isArray;
13
+ /**
14
+ * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
15
+ */
33
16
 
34
- function warn(msg) {
35
- if (console && util.warn && (!config.silent || config.debug)) {
36
- console.warn('[VueResource warn]: ' + msg);
37
- }
38
- }
17
+ var RESOLVED = 0;
18
+ var REJECTED = 1;
19
+ var PENDING = 2;
20
+
21
+ function Promise$1(executor) {
22
+
23
+ this.state = PENDING;
24
+ this.value = undefined;
25
+ this.deferred = [];
26
+
27
+ var promise = this;
28
+
29
+ try {
30
+ executor(function (x) {
31
+ promise.resolve(x);
32
+ }, function (r) {
33
+ promise.reject(r);
34
+ });
35
+ } catch (e) {
36
+ promise.reject(e);
37
+ }
38
+ }
39
+
40
+ Promise$1.reject = function (r) {
41
+ return new Promise$1(function (resolve, reject) {
42
+ reject(r);
43
+ });
44
+ };
45
+
46
+ Promise$1.resolve = function (x) {
47
+ return new Promise$1(function (resolve, reject) {
48
+ resolve(x);
49
+ });
50
+ };
51
+
52
+ Promise$1.all = function all(iterable) {
53
+ return new Promise$1(function (resolve, reject) {
54
+ var count = 0,
55
+ result = [];
56
+
57
+ if (iterable.length === 0) {
58
+ resolve(result);
59
+ }
60
+
61
+ function resolver(i) {
62
+ return function (x) {
63
+ result[i] = x;
64
+ count += 1;
65
+
66
+ if (count === iterable.length) {
67
+ resolve(result);
68
+ }
69
+ };
70
+ }
71
+
72
+ for (var i = 0; i < iterable.length; i += 1) {
73
+ Promise$1.resolve(iterable[i]).then(resolver(i), reject);
74
+ }
75
+ });
76
+ };
77
+
78
+ Promise$1.race = function race(iterable) {
79
+ return new Promise$1(function (resolve, reject) {
80
+ for (var i = 0; i < iterable.length; i += 1) {
81
+ Promise$1.resolve(iterable[i]).then(resolve, reject);
82
+ }
83
+ });
84
+ };
85
+
86
+ var p$1 = Promise$1.prototype;
87
+
88
+ p$1.resolve = function resolve(x) {
89
+ var promise = this;
90
+
91
+ if (promise.state === PENDING) {
92
+ if (x === promise) {
93
+ throw new TypeError('Promise settled with itself.');
94
+ }
95
+
96
+ var called = false;
97
+
98
+ try {
99
+ var then = x && x['then'];
100
+
101
+ if (x !== null && typeof x === 'object' && typeof then === 'function') {
102
+ then.call(x, function (x) {
103
+ if (!called) {
104
+ promise.resolve(x);
105
+ }
106
+ called = true;
107
+ }, function (r) {
108
+ if (!called) {
109
+ promise.reject(r);
110
+ }
111
+ called = true;
112
+ });
113
+ return;
114
+ }
115
+ } catch (e) {
116
+ if (!called) {
117
+ promise.reject(e);
118
+ }
119
+ return;
120
+ }
121
+
122
+ promise.state = RESOLVED;
123
+ promise.value = x;
124
+ promise.notify();
125
+ }
126
+ };
127
+
128
+ p$1.reject = function reject(reason) {
129
+ var promise = this;
130
+
131
+ if (promise.state === PENDING) {
132
+ if (reason === promise) {
133
+ throw new TypeError('Promise settled with itself.');
134
+ }
135
+
136
+ promise.state = REJECTED;
137
+ promise.value = reason;
138
+ promise.notify();
139
+ }
140
+ };
141
+
142
+ p$1.notify = function notify() {
143
+ var promise = this;
144
+
145
+ nextTick(function () {
146
+ if (promise.state !== PENDING) {
147
+ while (promise.deferred.length) {
148
+ var deferred = promise.deferred.shift(),
149
+ onResolved = deferred[0],
150
+ onRejected = deferred[1],
151
+ resolve = deferred[2],
152
+ reject = deferred[3];
153
+
154
+ try {
155
+ if (promise.state === RESOLVED) {
156
+ if (typeof onResolved === 'function') {
157
+ resolve(onResolved.call(undefined, promise.value));
158
+ } else {
159
+ resolve(promise.value);
160
+ }
161
+ } else if (promise.state === REJECTED) {
162
+ if (typeof onRejected === 'function') {
163
+ resolve(onRejected.call(undefined, promise.value));
164
+ } else {
165
+ reject(promise.value);
166
+ }
167
+ }
168
+ } catch (e) {
169
+ reject(e);
170
+ }
171
+ }
172
+ }
173
+ });
174
+ };
175
+
176
+ p$1.then = function then(onResolved, onRejected) {
177
+ var promise = this;
178
+
179
+ return new Promise$1(function (resolve, reject) {
180
+ promise.deferred.push([onResolved, onRejected, resolve, reject]);
181
+ promise.notify();
182
+ });
183
+ };
184
+
185
+ p$1.catch = function (onRejected) {
186
+ return this.then(undefined, onRejected);
187
+ };
188
+
189
+ /**
190
+ * Promise adapter.
191
+ */
39
192
 
40
- function error(msg) {
41
- if (console) {
42
- console.error(msg);
43
- }
44
- }
193
+ if (typeof Promise === 'undefined') {
194
+ window.Promise = Promise$1;
195
+ }
45
196
 
46
- function nextTick(cb, ctx) {
47
- return util.nextTick(cb, ctx);
48
- }
197
+ function PromiseObj(executor, context) {
49
198
 
50
- function trim(str) {
51
- return str.replace(/^\s*|\s*$/g, '');
52
- }
199
+ if (executor instanceof Promise) {
200
+ this.promise = executor;
201
+ } else {
202
+ this.promise = new Promise(executor.bind(context));
203
+ }
53
204
 
54
- function toLower(str) {
55
- return str ? str.toLowerCase() : '';
56
- }
205
+ this.context = context;
206
+ }
57
207
 
58
- function isString(val) {
59
- return typeof val === 'string';
60
- }
208
+ PromiseObj.all = function (iterable, context) {
209
+ return new PromiseObj(Promise.all(iterable), context);
210
+ };
61
211
 
62
- function isFunction(val) {
63
- return typeof val === 'function';
64
- }
212
+ PromiseObj.resolve = function (value, context) {
213
+ return new PromiseObj(Promise.resolve(value), context);
214
+ };
65
215
 
66
- function isObject(obj) {
67
- return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
68
- }
216
+ PromiseObj.reject = function (reason, context) {
217
+ return new PromiseObj(Promise.reject(reason), context);
218
+ };
69
219
 
70
- function isPlainObject(obj) {
71
- return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
72
- }
220
+ PromiseObj.race = function (iterable, context) {
221
+ return new PromiseObj(Promise.race(iterable), context);
222
+ };
73
223
 
74
- function options(fn, obj, opts) {
224
+ var p = PromiseObj.prototype;
75
225
 
76
- opts = opts || {};
226
+ p.bind = function (context) {
227
+ this.context = context;
228
+ return this;
229
+ };
77
230
 
78
- if (isFunction(opts)) {
79
- opts = opts.call(obj);
80
- }
231
+ p.then = function (fulfilled, rejected) {
81
232
 
82
- return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
83
- }
233
+ if (fulfilled && fulfilled.bind && this.context) {
234
+ fulfilled = fulfilled.bind(this.context);
235
+ }
84
236
 
85
- function each(obj, iterator) {
237
+ if (rejected && rejected.bind && this.context) {
238
+ rejected = rejected.bind(this.context);
239
+ }
86
240
 
87
- var i, key;
241
+ return new PromiseObj(this.promise.then(fulfilled, rejected), this.context);
242
+ };
88
243
 
89
- if (typeof obj.length == 'number') {
90
- for (i = 0; i < obj.length; i++) {
91
- iterator.call(obj[i], obj[i], i);
92
- }
93
- } else if (isObject(obj)) {
94
- for (key in obj) {
95
- if (obj.hasOwnProperty(key)) {
96
- iterator.call(obj[key], obj[key], key);
97
- }
98
- }
99
- }
244
+ p.catch = function (rejected) {
100
245
 
101
- return obj;
102
- }
246
+ if (rejected && rejected.bind && this.context) {
247
+ rejected = rejected.bind(this.context);
248
+ }
103
249
 
104
- function extend(target) {
250
+ return new PromiseObj(this.promise.catch(rejected), this.context);
251
+ };
105
252
 
106
- var args = array.slice.call(arguments, 1);
253
+ p.finally = function (callback) {
107
254
 
108
- args.forEach(function (arg) {
109
- _merge(target, arg);
110
- });
255
+ return this.then(function (value) {
256
+ callback.call(this);
257
+ return value;
258
+ }, function (reason) {
259
+ callback.call(this);
260
+ return Promise.reject(reason);
261
+ });
262
+ };
111
263
 
112
- return target;
113
- }
264
+ /**
265
+ * Utility functions.
266
+ */
114
267
 
115
- function merge(target) {
268
+ var debug = false;var util = {};var slice = [].slice;
116
269
 
117
- var args = array.slice.call(arguments, 1);
118
270
 
119
- args.forEach(function (arg) {
120
- _merge(target, arg, true);
121
- });
271
+ function Util (Vue) {
272
+ util = Vue.util;
273
+ debug = Vue.config.debug || !Vue.config.silent;
274
+ }
122
275
 
123
- return target;
124
- }
276
+ function warn(msg) {
277
+ if (typeof console !== 'undefined' && debug) {
278
+ console.warn('[VueResource warn]: ' + msg);
279
+ }
280
+ }
125
281
 
126
- function _merge(target, source, deep) {
127
- for (var key in source) {
128
- if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
129
- if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
130
- target[key] = {};
131
- }
132
- if (isArray(source[key]) && !isArray(target[key])) {
133
- target[key] = [];
134
- }
135
- _merge(target[key], source[key], deep);
136
- } else if (source[key] !== undefined) {
137
- target[key] = source[key];
138
- }
139
- }
140
- }
282
+ function error(msg) {
283
+ if (typeof console !== 'undefined') {
284
+ console.error(msg);
285
+ }
286
+ }
141
287
 
142
- function root (options, next) {
288
+ function nextTick(cb, ctx) {
289
+ return util.nextTick(cb, ctx);
290
+ }
143
291
 
144
- var url = next(options);
292
+ function trim(str) {
293
+ return str.replace(/^\s*|\s*$/g, '');
294
+ }
145
295
 
146
- if (isString(options.root) && !url.match(/^(https?:)?\//)) {
147
- url = options.root + '/' + url;
148
- }
296
+ function toLower(str) {
297
+ return str ? str.toLowerCase() : '';
298
+ }
149
299
 
150
- return url;
151
- }
300
+ function toUpper(str) {
301
+ return str ? str.toUpperCase() : '';
302
+ }
152
303
 
153
- function query (options, next) {
304
+ var isArray = Array.isArray;
154
305
 
155
- var urlParams = Object.keys(Url.options.params),
156
- query = {},
157
- url = next(options);
306
+ function isString(val) {
307
+ return typeof val === 'string';
308
+ }
158
309
 
159
- each(options.params, function (value, key) {
160
- if (urlParams.indexOf(key) === -1) {
161
- query[key] = value;
162
- }
163
- });
310
+ function isBoolean(val) {
311
+ return val === true || val === false;
312
+ }
164
313
 
165
- query = Url.params(query);
314
+ function isFunction(val) {
315
+ return typeof val === 'function';
316
+ }
166
317
 
167
- if (query) {
168
- url += (url.indexOf('?') == -1 ? '?' : '&') + query;
169
- }
318
+ function isObject(obj) {
319
+ return obj !== null && typeof obj === 'object';
320
+ }
170
321
 
171
- return url;
172
- }
322
+ function isPlainObject(obj) {
323
+ return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
324
+ }
173
325
 
174
- function legacy (options, next) {
326
+ function isBlob(obj) {
327
+ return typeof Blob !== 'undefined' && obj instanceof Blob;
328
+ }
175
329
 
176
- var variables = [],
177
- url = next(options);
330
+ function isFormData(obj) {
331
+ return typeof FormData !== 'undefined' && obj instanceof FormData;
332
+ }
178
333
 
179
- url = url.replace(/(\/?):([a-z]\w*)/gi, function (match, slash, name) {
334
+ function when(value, fulfilled, rejected) {
180
335
 
181
- warn('The `:' + name + '` parameter syntax has been deprecated. Use the `{' + name + '}` syntax instead.');
336
+ var promise = PromiseObj.resolve(value);
182
337
 
183
- if (options.params[name]) {
184
- variables.push(name);
185
- return slash + encodeUriSegment(options.params[name]);
186
- }
338
+ if (arguments.length < 2) {
339
+ return promise;
340
+ }
187
341
 
188
- return '';
189
- });
342
+ return promise.then(fulfilled, rejected);
343
+ }
190
344
 
191
- variables.forEach(function (key) {
192
- delete options.params[key];
193
- });
345
+ function options(fn, obj, opts) {
194
346
 
195
- return url;
196
- }
347
+ opts = opts || {};
197
348
 
198
- function encodeUriSegment(value) {
349
+ if (isFunction(opts)) {
350
+ opts = opts.call(obj);
351
+ }
199
352
 
200
- return encodeUriQuery(value, true).replace(/%26/gi, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+');
201
- }
353
+ return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
354
+ }
202
355
 
203
- function encodeUriQuery(value, spaces) {
356
+ function each(obj, iterator) {
204
357
 
205
- return encodeURIComponent(value).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, spaces ? '%20' : '+');
206
- }
358
+ var i, key;
207
359
 
208
- /**
209
- * URL Template v2.0.6 (https://github.com/bramstein/url-template)
210
- */
360
+ if (obj && typeof obj.length == 'number') {
361
+ for (i = 0; i < obj.length; i++) {
362
+ iterator.call(obj[i], obj[i], i);
363
+ }
364
+ } else if (isObject(obj)) {
365
+ for (key in obj) {
366
+ if (obj.hasOwnProperty(key)) {
367
+ iterator.call(obj[key], obj[key], key);
368
+ }
369
+ }
370
+ }
211
371
 
212
- function expand(url, params, variables) {
372
+ return obj;
373
+ }
213
374
 
214
- var tmpl = parse(url),
215
- expanded = tmpl.expand(params);
375
+ var assign = Object.assign || _assign;
216
376
 
217
- if (variables) {
218
- variables.push.apply(variables, tmpl.vars);
219
- }
377
+ function merge(target) {
220
378
 
221
- return expanded;
222
- }
379
+ var args = slice.call(arguments, 1);
223
380
 
224
- function parse(template) {
225
-
226
- var operators = ['+', '#', '.', '/', ';', '?', '&'],
227
- variables = [];
228
-
229
- return {
230
- vars: variables,
231
- expand: function expand(context) {
232
- return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
233
- if (expression) {
234
-
235
- var operator = null,
236
- values = [];
237
-
238
- if (operators.indexOf(expression.charAt(0)) !== -1) {
239
- operator = expression.charAt(0);
240
- expression = expression.substr(1);
241
- }
242
-
243
- expression.split(/,/g).forEach(function (variable) {
244
- var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
245
- values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
246
- variables.push(tmp[1]);
247
- });
248
-
249
- if (operator && operator !== '+') {
250
-
251
- var separator = ',';
252
-
253
- if (operator === '?') {
254
- separator = '&';
255
- } else if (operator !== '#') {
256
- separator = operator;
257
- }
258
-
259
- return (values.length !== 0 ? operator : '') + values.join(separator);
260
- } else {
261
- return values.join(',');
262
- }
263
- } else {
264
- return encodeReserved(literal);
265
- }
266
- });
267
- }
268
- };
269
- }
381
+ args.forEach(function (source) {
382
+ _merge(target, source, true);
383
+ });
270
384
 
271
- function getValues(context, operator, key, modifier) {
272
-
273
- var value = context[key],
274
- result = [];
275
-
276
- if (isDefined(value) && value !== '') {
277
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
278
- value = value.toString();
279
-
280
- if (modifier && modifier !== '*') {
281
- value = value.substring(0, parseInt(modifier, 10));
282
- }
283
-
284
- result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
285
- } else {
286
- if (modifier === '*') {
287
- if (Array.isArray(value)) {
288
- value.filter(isDefined).forEach(function (value) {
289
- result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
290
- });
291
- } else {
292
- Object.keys(value).forEach(function (k) {
293
- if (isDefined(value[k])) {
294
- result.push(encodeValue(operator, value[k], k));
295
- }
296
- });
297
- }
298
- } else {
299
- var tmp = [];
300
-
301
- if (Array.isArray(value)) {
302
- value.filter(isDefined).forEach(function (value) {
303
- tmp.push(encodeValue(operator, value));
304
- });
305
- } else {
306
- Object.keys(value).forEach(function (k) {
307
- if (isDefined(value[k])) {
308
- tmp.push(encodeURIComponent(k));
309
- tmp.push(encodeValue(operator, value[k].toString()));
310
- }
311
- });
312
- }
313
-
314
- if (isKeyOperator(operator)) {
315
- result.push(encodeURIComponent(key) + '=' + tmp.join(','));
316
- } else if (tmp.length !== 0) {
317
- result.push(tmp.join(','));
318
- }
319
- }
320
- }
321
- } else {
322
- if (operator === ';') {
323
- result.push(encodeURIComponent(key));
324
- } else if (value === '' && (operator === '&' || operator === '?')) {
325
- result.push(encodeURIComponent(key) + '=');
326
- } else if (value === '') {
327
- result.push('');
328
- }
329
- }
330
-
331
- return result;
332
- }
385
+ return target;
386
+ }
333
387
 
334
- function isDefined(value) {
335
- return value !== undefined && value !== null;
336
- }
388
+ function defaults(target) {
337
389
 
338
- function isKeyOperator(operator) {
339
- return operator === ';' || operator === '&' || operator === '?';
340
- }
390
+ var args = slice.call(arguments, 1);
341
391
 
342
- function encodeValue(operator, value, key) {
392
+ args.forEach(function (source) {
343
393
 
344
- value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value);
394
+ for (var key in source) {
395
+ if (target[key] === undefined) {
396
+ target[key] = source[key];
397
+ }
398
+ }
399
+ });
345
400
 
346
- if (key) {
347
- return encodeURIComponent(key) + '=' + value;
348
- } else {
349
- return value;
350
- }
351
- }
401
+ return target;
402
+ }
352
403
 
353
- function encodeReserved(str) {
354
- return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
355
- if (!/%[0-9A-Fa-f]/.test(part)) {
356
- part = encodeURI(part);
357
- }
358
- return part;
359
- }).join('');
360
- }
404
+ function _assign(target) {
361
405
 
362
- function template (options) {
406
+ var args = slice.call(arguments, 1);
363
407
 
364
- var variables = [],
365
- url = expand(options.url, options.params, variables);
408
+ args.forEach(function (source) {
409
+ _merge(target, source);
410
+ });
366
411
 
367
- variables.forEach(function (key) {
368
- delete options.params[key];
369
- });
412
+ return target;
413
+ }
370
414
 
371
- return url;
372
- }
415
+ function _merge(target, source, deep) {
416
+ for (var key in source) {
417
+ if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
418
+ if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
419
+ target[key] = {};
420
+ }
421
+ if (isArray(source[key]) && !isArray(target[key])) {
422
+ target[key] = [];
423
+ }
424
+ _merge(target[key], source[key], deep);
425
+ } else if (source[key] !== undefined) {
426
+ target[key] = source[key];
427
+ }
428
+ }
429
+ }
373
430
 
374
- /**
375
- * Service for URL templating.
376
- */
431
+ /**
432
+ * Root Prefix Transform.
433
+ */
377
434
 
378
- var ie = document.documentMode;
379
- var el = document.createElement('a');
435
+ function root (options, next) {
380
436
 
381
- function Url(url, params) {
437
+ var url = next(options);
382
438
 
383
- var self = this || {},
384
- options = url,
385
- transform;
439
+ if (isString(options.root) && !url.match(/^(https?:)?\//)) {
440
+ url = options.root + '/' + url;
441
+ }
386
442
 
387
- if (isString(url)) {
388
- options = { url: url, params: params };
389
- }
443
+ return url;
444
+ }
390
445
 
391
- options = merge({}, Url.options, self.$options, options);
446
+ /**
447
+ * Query Parameter Transform.
448
+ */
392
449
 
393
- Url.transforms.forEach(function (handler) {
394
- transform = factory(handler, transform, self.$vm);
395
- });
450
+ function query (options, next) {
396
451
 
397
- return transform(options);
398
- }
452
+ var urlParams = Object.keys(Url.options.params),
453
+ query = {},
454
+ url = next(options);
399
455
 
400
- /**
401
- * Url options.
402
- */
456
+ each(options.params, function (value, key) {
457
+ if (urlParams.indexOf(key) === -1) {
458
+ query[key] = value;
459
+ }
460
+ });
403
461
 
404
- Url.options = {
405
- url: '',
406
- root: null,
407
- params: {}
408
- };
462
+ query = Url.params(query);
409
463
 
410
- /**
411
- * Url transforms.
412
- */
464
+ if (query) {
465
+ url += (url.indexOf('?') == -1 ? '?' : '&') + query;
466
+ }
413
467
 
414
- Url.transforms = [template, legacy, query, root];
468
+ return url;
469
+ }
415
470
 
416
- /**
417
- * Encodes a Url parameter string.
418
- *
419
- * @param {Object} obj
420
- */
471
+ /**
472
+ * URL Template v2.0.6 (https://github.com/bramstein/url-template)
473
+ */
421
474
 
422
- Url.params = function (obj) {
475
+ function expand(url, params, variables) {
476
+
477
+ var tmpl = parse(url),
478
+ expanded = tmpl.expand(params);
479
+
480
+ if (variables) {
481
+ variables.push.apply(variables, tmpl.vars);
482
+ }
483
+
484
+ return expanded;
485
+ }
486
+
487
+ function parse(template) {
488
+
489
+ var operators = ['+', '#', '.', '/', ';', '?', '&'],
490
+ variables = [];
491
+
492
+ return {
493
+ vars: variables,
494
+ expand: function (context) {
495
+ return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
496
+ if (expression) {
497
+
498
+ var operator = null,
499
+ values = [];
500
+
501
+ if (operators.indexOf(expression.charAt(0)) !== -1) {
502
+ operator = expression.charAt(0);
503
+ expression = expression.substr(1);
504
+ }
505
+
506
+ expression.split(/,/g).forEach(function (variable) {
507
+ var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
508
+ values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
509
+ variables.push(tmp[1]);
510
+ });
511
+
512
+ if (operator && operator !== '+') {
513
+
514
+ var separator = ',';
515
+
516
+ if (operator === '?') {
517
+ separator = '&';
518
+ } else if (operator !== '#') {
519
+ separator = operator;
520
+ }
521
+
522
+ return (values.length !== 0 ? operator : '') + values.join(separator);
523
+ } else {
524
+ return values.join(',');
525
+ }
526
+ } else {
527
+ return encodeReserved(literal);
528
+ }
529
+ });
530
+ }
531
+ };
532
+ }
533
+
534
+ function getValues(context, operator, key, modifier) {
535
+
536
+ var value = context[key],
537
+ result = [];
538
+
539
+ if (isDefined(value) && value !== '') {
540
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
541
+ value = value.toString();
542
+
543
+ if (modifier && modifier !== '*') {
544
+ value = value.substring(0, parseInt(modifier, 10));
545
+ }
546
+
547
+ result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
548
+ } else {
549
+ if (modifier === '*') {
550
+ if (Array.isArray(value)) {
551
+ value.filter(isDefined).forEach(function (value) {
552
+ result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
553
+ });
554
+ } else {
555
+ Object.keys(value).forEach(function (k) {
556
+ if (isDefined(value[k])) {
557
+ result.push(encodeValue(operator, value[k], k));
558
+ }
559
+ });
560
+ }
561
+ } else {
562
+ var tmp = [];
563
+
564
+ if (Array.isArray(value)) {
565
+ value.filter(isDefined).forEach(function (value) {
566
+ tmp.push(encodeValue(operator, value));
567
+ });
568
+ } else {
569
+ Object.keys(value).forEach(function (k) {
570
+ if (isDefined(value[k])) {
571
+ tmp.push(encodeURIComponent(k));
572
+ tmp.push(encodeValue(operator, value[k].toString()));
573
+ }
574
+ });
575
+ }
576
+
577
+ if (isKeyOperator(operator)) {
578
+ result.push(encodeURIComponent(key) + '=' + tmp.join(','));
579
+ } else if (tmp.length !== 0) {
580
+ result.push(tmp.join(','));
581
+ }
582
+ }
583
+ }
584
+ } else {
585
+ if (operator === ';') {
586
+ result.push(encodeURIComponent(key));
587
+ } else if (value === '' && (operator === '&' || operator === '?')) {
588
+ result.push(encodeURIComponent(key) + '=');
589
+ } else if (value === '') {
590
+ result.push('');
591
+ }
592
+ }
593
+
594
+ return result;
595
+ }
596
+
597
+ function isDefined(value) {
598
+ return value !== undefined && value !== null;
599
+ }
600
+
601
+ function isKeyOperator(operator) {
602
+ return operator === ';' || operator === '&' || operator === '?';
603
+ }
604
+
605
+ function encodeValue(operator, value, key) {
606
+
607
+ value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value);
608
+
609
+ if (key) {
610
+ return encodeURIComponent(key) + '=' + value;
611
+ } else {
612
+ return value;
613
+ }
614
+ }
615
+
616
+ function encodeReserved(str) {
617
+ return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
618
+ if (!/%[0-9A-Fa-f]/.test(part)) {
619
+ part = encodeURI(part);
620
+ }
621
+ return part;
622
+ }).join('');
623
+ }
624
+
625
+ /**
626
+ * URL Template (RFC 6570) Transform.
627
+ */
423
628
 
424
- var params = [],
425
- escape = encodeURIComponent;
629
+ function template (options) {
426
630
 
427
- params.add = function (key, value) {
631
+ var variables = [],
632
+ url = expand(options.url, options.params, variables);
428
633
 
429
- if (isFunction(value)) {
430
- value = value();
431
- }
634
+ variables.forEach(function (key) {
635
+ delete options.params[key];
636
+ });
432
637
 
433
- if (value === null) {
434
- value = '';
435
- }
638
+ return url;
639
+ }
436
640
 
437
- this.push(escape(key) + '=' + escape(value));
438
- };
641
+ /**
642
+ * Service for URL templating.
643
+ */
439
644
 
440
- serialize(params, obj);
645
+ var ie = document.documentMode;
646
+ var el = document.createElement('a');
441
647
 
442
- return params.join('&').replace(/%20/g, '+');
443
- };
648
+ function Url(url, params) {
444
649
 
445
- /**
446
- * Parse a URL and return its components.
447
- *
448
- * @param {String} url
449
- */
650
+ var self = this || {},
651
+ options = url,
652
+ transform;
450
653
 
451
- Url.parse = function (url) {
654
+ if (isString(url)) {
655
+ options = { url: url, params: params };
656
+ }
452
657
 
453
- if (ie) {
454
- el.href = url;
455
- url = el.href;
456
- }
658
+ options = merge({}, Url.options, self.$options, options);
457
659
 
458
- el.href = url;
660
+ Url.transforms.forEach(function (handler) {
661
+ transform = factory(handler, transform, self.$vm);
662
+ });
459
663
 
460
- return {
461
- href: el.href,
462
- protocol: el.protocol ? el.protocol.replace(/:$/, '') : '',
463
- port: el.port,
464
- host: el.host,
465
- hostname: el.hostname,
466
- pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname,
467
- search: el.search ? el.search.replace(/^\?/, '') : '',
468
- hash: el.hash ? el.hash.replace(/^#/, '') : ''
469
- };
470
- };
664
+ return transform(options);
665
+ }
471
666
 
472
- function factory(handler, next, vm) {
473
- return function (options) {
474
- return handler.call(vm, options, next);
475
- };
476
- }
667
+ /**
668
+ * Url options.
669
+ */
477
670
 
478
- function serialize(params, obj, scope) {
671
+ Url.options = {
672
+ url: '',
673
+ root: null,
674
+ params: {}
675
+ };
479
676
 
480
- var array = isArray(obj),
481
- plain = isPlainObject(obj),
482
- hash;
677
+ /**
678
+ * Url transforms.
679
+ */
483
680
 
484
- each(obj, function (value, key) {
681
+ Url.transforms = [template, query, root];
485
682
 
486
- hash = isObject(value) || isArray(value);
683
+ /**
684
+ * Encodes a Url parameter string.
685
+ *
686
+ * @param {Object} obj
687
+ */
487
688
 
488
- if (scope) {
489
- key = scope + '[' + (plain || hash ? key : '') + ']';
490
- }
689
+ Url.params = function (obj) {
491
690
 
492
- if (!scope && array) {
493
- params.add(value.name, value.value);
494
- } else if (hash) {
495
- serialize(params, value, key);
496
- } else {
497
- params.add(key, value);
498
- }
499
- });
500
- }
691
+ var params = [],
692
+ escape = encodeURIComponent;
501
693
 
502
- /**
503
- * Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
504
- */
694
+ params.add = function (key, value) {
505
695
 
506
- var RESOLVED = 0;
507
- var REJECTED = 1;
508
- var PENDING = 2;
696
+ if (isFunction(value)) {
697
+ value = value();
698
+ }
509
699
 
510
- function Promise$2(executor) {
700
+ if (value === null) {
701
+ value = '';
702
+ }
511
703
 
512
- this.state = PENDING;
513
- this.value = undefined;
514
- this.deferred = [];
704
+ this.push(escape(key) + '=' + escape(value));
705
+ };
515
706
 
516
- var promise = this;
707
+ serialize(params, obj);
517
708
 
518
- try {
519
- executor(function (x) {
520
- promise.resolve(x);
521
- }, function (r) {
522
- promise.reject(r);
523
- });
524
- } catch (e) {
525
- promise.reject(e);
526
- }
527
- }
709
+ return params.join('&').replace(/%20/g, '+');
710
+ };
528
711
 
529
- Promise$2.reject = function (r) {
530
- return new Promise$2(function (resolve, reject) {
531
- reject(r);
532
- });
533
- };
534
-
535
- Promise$2.resolve = function (x) {
536
- return new Promise$2(function (resolve, reject) {
537
- resolve(x);
538
- });
539
- };
540
-
541
- Promise$2.all = function all(iterable) {
542
- return new Promise$2(function (resolve, reject) {
543
- var count = 0,
544
- result = [];
545
-
546
- if (iterable.length === 0) {
547
- resolve(result);
548
- }
549
-
550
- function resolver(i) {
551
- return function (x) {
552
- result[i] = x;
553
- count += 1;
554
-
555
- if (count === iterable.length) {
556
- resolve(result);
557
- }
558
- };
559
- }
560
-
561
- for (var i = 0; i < iterable.length; i += 1) {
562
- Promise$2.resolve(iterable[i]).then(resolver(i), reject);
563
- }
564
- });
565
- };
566
-
567
- Promise$2.race = function race(iterable) {
568
- return new Promise$2(function (resolve, reject) {
569
- for (var i = 0; i < iterable.length; i += 1) {
570
- Promise$2.resolve(iterable[i]).then(resolve, reject);
571
- }
572
- });
573
- };
574
-
575
- var p$1 = Promise$2.prototype;
576
-
577
- p$1.resolve = function resolve(x) {
578
- var promise = this;
579
-
580
- if (promise.state === PENDING) {
581
- if (x === promise) {
582
- throw new TypeError('Promise settled with itself.');
583
- }
584
-
585
- var called = false;
586
-
587
- try {
588
- var then = x && x['then'];
589
-
590
- if (x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && typeof then === 'function') {
591
- then.call(x, function (x) {
592
- if (!called) {
593
- promise.resolve(x);
594
- }
595
- called = true;
596
- }, function (r) {
597
- if (!called) {
598
- promise.reject(r);
599
- }
600
- called = true;
601
- });
602
- return;
603
- }
604
- } catch (e) {
605
- if (!called) {
606
- promise.reject(e);
607
- }
608
- return;
609
- }
610
-
611
- promise.state = RESOLVED;
612
- promise.value = x;
613
- promise.notify();
614
- }
615
- };
616
-
617
- p$1.reject = function reject(reason) {
618
- var promise = this;
619
-
620
- if (promise.state === PENDING) {
621
- if (reason === promise) {
622
- throw new TypeError('Promise settled with itself.');
623
- }
624
-
625
- promise.state = REJECTED;
626
- promise.value = reason;
627
- promise.notify();
628
- }
629
- };
630
-
631
- p$1.notify = function notify() {
632
- var promise = this;
633
-
634
- nextTick(function () {
635
- if (promise.state !== PENDING) {
636
- while (promise.deferred.length) {
637
- var deferred = promise.deferred.shift(),
638
- onResolved = deferred[0],
639
- onRejected = deferred[1],
640
- resolve = deferred[2],
641
- reject = deferred[3];
642
-
643
- try {
644
- if (promise.state === RESOLVED) {
645
- if (typeof onResolved === 'function') {
646
- resolve(onResolved.call(undefined, promise.value));
647
- } else {
648
- resolve(promise.value);
649
- }
650
- } else if (promise.state === REJECTED) {
651
- if (typeof onRejected === 'function') {
652
- resolve(onRejected.call(undefined, promise.value));
653
- } else {
654
- reject(promise.value);
655
- }
656
- }
657
- } catch (e) {
658
- reject(e);
659
- }
660
- }
661
- }
662
- });
663
- };
664
-
665
- p$1.then = function then(onResolved, onRejected) {
666
- var promise = this;
667
-
668
- return new Promise$2(function (resolve, reject) {
669
- promise.deferred.push([onResolved, onRejected, resolve, reject]);
670
- promise.notify();
671
- });
672
- };
673
-
674
- p$1.catch = function (onRejected) {
675
- return this.then(undefined, onRejected);
676
- };
677
-
678
- var PromiseObj = window.Promise || Promise$2;
679
-
680
- function Promise$1(executor, context) {
681
-
682
- if (executor instanceof PromiseObj) {
683
- this.promise = executor;
684
- } else {
685
- this.promise = new PromiseObj(executor.bind(context));
686
- }
687
-
688
- this.context = context;
689
- }
712
+ /**
713
+ * Parse a URL and return its components.
714
+ *
715
+ * @param {String} url
716
+ */
717
+
718
+ Url.parse = function (url) {
719
+
720
+ if (ie) {
721
+ el.href = url;
722
+ url = el.href;
723
+ }
724
+
725
+ el.href = url;
726
+
727
+ return {
728
+ href: el.href,
729
+ protocol: el.protocol ? el.protocol.replace(/:$/, '') : '',
730
+ port: el.port,
731
+ host: el.host,
732
+ hostname: el.hostname,
733
+ pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname,
734
+ search: el.search ? el.search.replace(/^\?/, '') : '',
735
+ hash: el.hash ? el.hash.replace(/^#/, '') : ''
736
+ };
737
+ };
738
+
739
+ function factory(handler, next, vm) {
740
+ return function (options) {
741
+ return handler.call(vm, options, next);
742
+ };
743
+ }
744
+
745
+ function serialize(params, obj, scope) {
746
+
747
+ var array = isArray(obj),
748
+ plain = isPlainObject(obj),
749
+ hash;
750
+
751
+ each(obj, function (value, key) {
752
+
753
+ hash = isObject(value) || isArray(value);
754
+
755
+ if (scope) {
756
+ key = scope + '[' + (plain || hash ? key : '') + ']';
757
+ }
758
+
759
+ if (!scope && array) {
760
+ params.add(value.name, value.value);
761
+ } else if (hash) {
762
+ serialize(params, value, key);
763
+ } else {
764
+ params.add(key, value);
765
+ }
766
+ });
767
+ }
768
+
769
+ /**
770
+ * XDomain client (Internet Explorer).
771
+ */
690
772
 
691
- Promise$1.all = function (iterable, context) {
692
- return new Promise$1(PromiseObj.all(iterable), context);
693
- };
773
+ function xdrClient (request) {
774
+ return new PromiseObj(function (resolve) {
694
775
 
695
- Promise$1.resolve = function (value, context) {
696
- return new Promise$1(PromiseObj.resolve(value), context);
697
- };
776
+ var xdr = new XDomainRequest(),
777
+ handler = function (_ref) {
778
+ var type = _ref.type;
698
779
 
699
- Promise$1.reject = function (reason, context) {
700
- return new Promise$1(PromiseObj.reject(reason), context);
701
- };
702
780
 
703
- Promise$1.race = function (iterable, context) {
704
- return new Promise$1(PromiseObj.race(iterable), context);
705
- };
781
+ var status = 0;
706
782
 
707
- var p = Promise$1.prototype;
783
+ if (type === 'load') {
784
+ status = 200;
785
+ } else if (type === 'error') {
786
+ status = 500;
787
+ }
708
788
 
709
- p.bind = function (context) {
710
- this.context = context;
711
- return this;
712
- };
789
+ resolve(request.respondWith(xdr.responseText, { status: status }));
790
+ };
713
791
 
714
- p.then = function (fulfilled, rejected) {
792
+ request.abort = function () {
793
+ return xdr.abort();
794
+ };
715
795
 
716
- if (fulfilled && fulfilled.bind && this.context) {
717
- fulfilled = fulfilled.bind(this.context);
718
- }
796
+ xdr.open(request.method, request.getUrl());
797
+ xdr.timeout = 0;
798
+ xdr.onload = handler;
799
+ xdr.onerror = handler;
800
+ xdr.ontimeout = handler;
801
+ xdr.onprogress = function () {};
802
+ xdr.send(request.getBody());
803
+ });
804
+ }
719
805
 
720
- if (rejected && rejected.bind && this.context) {
721
- rejected = rejected.bind(this.context);
722
- }
806
+ /**
807
+ * CORS Interceptor.
808
+ */
723
809
 
724
- this.promise = this.promise.then(fulfilled, rejected);
810
+ var ORIGIN_URL = Url.parse(location.href);
811
+ var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
725
812
 
726
- return this;
727
- };
813
+ function cors (request, next) {
728
814
 
729
- p.catch = function (rejected) {
815
+ if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
816
+ request.crossOrigin = true;
817
+ }
730
818
 
731
- if (rejected && rejected.bind && this.context) {
732
- rejected = rejected.bind(this.context);
733
- }
819
+ if (request.crossOrigin) {
734
820
 
735
- this.promise = this.promise.catch(rejected);
821
+ if (!SUPPORTS_CORS) {
822
+ request.client = xdrClient;
823
+ }
736
824
 
737
- return this;
738
- };
825
+ delete request.emulateHTTP;
826
+ }
739
827
 
740
- p.finally = function (callback) {
828
+ next();
829
+ }
741
830
 
742
- return this.then(function (value) {
743
- callback.call(this);
744
- return value;
745
- }, function (reason) {
746
- callback.call(this);
747
- return PromiseObj.reject(reason);
748
- });
749
- };
831
+ function crossOrigin(request) {
750
832
 
751
- p.success = function (callback) {
833
+ var requestUrl = Url.parse(Url(request));
752
834
 
753
- warn('The `success` method has been deprecated. Use the `then` method instead.');
835
+ return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host;
836
+ }
754
837
 
755
- return this.then(function (response) {
756
- return callback.call(this, response.data, response.status, response) || response;
757
- });
758
- };
838
+ /**
839
+ * Body Interceptor.
840
+ */
759
841
 
760
- p.error = function (callback) {
842
+ function body (request, next) {
761
843
 
762
- warn('The `error` method has been deprecated. Use the `catch` method instead.');
844
+ if (isFormData(request.body)) {
763
845
 
764
- return this.catch(function (response) {
765
- return callback.call(this, response.data, response.status, response) || response;
766
- });
767
- };
846
+ request.headers.delete('Content-Type');
847
+ } else if (isObject(request.body) || isArray(request.body)) {
768
848
 
769
- p.always = function (callback) {
849
+ if (request.emulateJSON) {
850
+ request.body = Url.params(request.body);
851
+ request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
852
+ } else {
853
+ request.body = JSON.stringify(request.body);
854
+ }
855
+ }
770
856
 
771
- warn('The `always` method has been deprecated. Use the `finally` method instead.');
857
+ next(function (response) {
772
858
 
773
- var cb = function cb(response) {
774
- return callback.call(this, response.data, response.status, response) || response;
775
- };
859
+ Object.defineProperty(response, 'data', {
860
+ get: function () {
861
+ return this.body;
862
+ },
863
+ set: function (body) {
864
+ this.body = body;
865
+ }
866
+ });
776
867
 
777
- return this.then(cb, cb);
778
- };
868
+ return response.bodyText ? when(response.text(), function (text) {
779
869
 
780
- function xdrClient (request) {
781
- return new Promise$1(function (resolve) {
870
+ var type = response.headers.get('Content-Type');
782
871
 
783
- var xdr = new XDomainRequest(),
784
- response = { request: request },
785
- handler;
872
+ if (isString(type) && type.indexOf('application/json') === 0) {
786
873
 
787
- request.cancel = function () {
788
- xdr.abort();
789
- };
874
+ try {
875
+ response.body = JSON.parse(text);
876
+ } catch (e) {
877
+ response.body = null;
878
+ }
879
+ } else {
880
+ response.body = text;
881
+ }
790
882
 
791
- xdr.open(request.method, Url(request), true);
883
+ return response;
884
+ }) : response;
885
+ });
886
+ }
792
887
 
793
- handler = function handler(event) {
888
+ /**
889
+ * JSONP client.
890
+ */
794
891
 
795
- response.data = xdr.responseText;
796
- response.status = xdr.status;
797
- response.statusText = xdr.statusText || '';
892
+ function jsonpClient (request) {
893
+ return new PromiseObj(function (resolve) {
798
894
 
799
- resolve(response);
800
- };
895
+ var name = request.jsonp || 'callback',
896
+ callback = '_jsonp' + Math.random().toString(36).substr(2),
897
+ body = null,
898
+ handler,
899
+ script;
801
900
 
802
- xdr.timeout = 0;
803
- xdr.onload = handler;
804
- xdr.onabort = handler;
805
- xdr.onerror = handler;
806
- xdr.ontimeout = function () {};
807
- xdr.onprogress = function () {};
901
+ handler = function (_ref) {
902
+ var type = _ref.type;
808
903
 
809
- xdr.send(request.data);
810
- });
811
- }
812
904
 
813
- var originUrl = Url.parse(location.href);
814
- var supportCors = 'withCredentials' in new XMLHttpRequest();
905
+ var status = 0;
815
906
 
816
- var exports$1 = {
817
- request: function request(_request) {
907
+ if (type === 'load' && body !== null) {
908
+ status = 200;
909
+ } else if (type === 'error') {
910
+ status = 500;
911
+ }
818
912
 
819
- if (_request.crossOrigin === null) {
820
- _request.crossOrigin = crossOrigin(_request);
821
- }
913
+ resolve(request.respondWith(body, { status: status }));
822
914
 
823
- if (_request.crossOrigin) {
915
+ delete window[callback];
916
+ document.body.removeChild(script);
917
+ };
824
918
 
825
- if (!supportCors) {
826
- _request.client = xdrClient;
827
- }
919
+ request.params[name] = callback;
828
920
 
829
- _request.emulateHTTP = false;
830
- }
921
+ window[callback] = function (result) {
922
+ body = JSON.stringify(result);
923
+ };
831
924
 
832
- return _request;
833
- }
834
- };
925
+ script = document.createElement('script');
926
+ script.src = request.getUrl();
927
+ script.type = 'text/javascript';
928
+ script.async = true;
929
+ script.onload = handler;
930
+ script.onerror = handler;
835
931
 
836
- function crossOrigin(request) {
932
+ document.body.appendChild(script);
933
+ });
934
+ }
837
935
 
838
- var requestUrl = Url.parse(Url(request));
936
+ /**
937
+ * JSONP Interceptor.
938
+ */
839
939
 
840
- return requestUrl.protocol !== originUrl.protocol || requestUrl.host !== originUrl.host;
841
- }
940
+ function jsonp (request, next) {
842
941
 
843
- var exports$2 = {
844
- request: function request(_request) {
942
+ if (request.method == 'JSONP') {
943
+ request.client = jsonpClient;
944
+ }
845
945
 
846
- if (_request.emulateJSON && isPlainObject(_request.data)) {
847
- _request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
848
- _request.data = Url.params(_request.data);
849
- }
946
+ next(function (response) {
850
947
 
851
- if (isObject(_request.data) && /FormData/i.test(_request.data.toString())) {
852
- delete _request.headers['Content-Type'];
853
- }
948
+ if (request.method == 'JSONP') {
854
949
 
855
- if (isPlainObject(_request.data)) {
856
- _request.data = JSON.stringify(_request.data);
857
- }
950
+ return when(response.json(), function (json) {
858
951
 
859
- return _request;
860
- },
861
- response: function response(_response) {
952
+ response.body = json;
862
953
 
863
- try {
864
- _response.data = JSON.parse(_response.data);
865
- } catch (e) {}
954
+ return response;
955
+ });
956
+ }
957
+ });
958
+ }
866
959
 
867
- return _response;
868
- }
869
- };
960
+ /**
961
+ * Before Interceptor.
962
+ */
870
963
 
871
- function jsonpClient (request) {
872
- return new Promise$1(function (resolve) {
964
+ function before (request, next) {
873
965
 
874
- var callback = '_jsonp' + Math.random().toString(36).substr(2),
875
- response = { request: request, data: null },
876
- handler,
877
- script;
966
+ if (isFunction(request.before)) {
967
+ request.before.call(this, request);
968
+ }
878
969
 
879
- request.params[request.jsonp] = callback;
880
- request.cancel = function () {
881
- handler({ type: 'cancel' });
882
- };
970
+ next();
971
+ }
883
972
 
884
- script = document.createElement('script');
885
- script.src = Url(request);
886
- script.type = 'text/javascript';
887
- script.async = true;
973
+ /**
974
+ * HTTP method override Interceptor.
975
+ */
888
976
 
889
- window[callback] = function (data) {
890
- response.data = data;
891
- };
977
+ function method (request, next) {
892
978
 
893
- handler = function handler(event) {
979
+ if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
980
+ request.headers.set('X-HTTP-Method-Override', request.method);
981
+ request.method = 'POST';
982
+ }
894
983
 
895
- if (event.type === 'load' && response.data !== null) {
896
- response.status = 200;
897
- } else if (event.type === 'error') {
898
- response.status = 404;
899
- } else {
900
- response.status = 0;
901
- }
984
+ next();
985
+ }
902
986
 
903
- resolve(response);
987
+ /**
988
+ * Header Interceptor.
989
+ */
904
990
 
905
- delete window[callback];
906
- document.body.removeChild(script);
907
- };
991
+ function header (request, next) {
908
992
 
909
- script.onload = handler;
910
- script.onerror = handler;
993
+ var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]);
911
994
 
912
- document.body.appendChild(script);
913
- });
914
- }
995
+ each(headers, function (value, name) {
996
+ if (!request.headers.has(name)) {
997
+ request.headers.set(name, value);
998
+ }
999
+ });
915
1000
 
916
- var exports$3 = {
917
- request: function request(_request) {
1001
+ next();
1002
+ }
918
1003
 
919
- if (_request.method == 'JSONP') {
920
- _request.client = jsonpClient;
921
- }
1004
+ /**
1005
+ * Timeout Interceptor.
1006
+ */
922
1007
 
923
- return _request;
924
- }
925
- };
1008
+ function timeout (request, next) {
926
1009
 
927
- var exports$4 = {
928
- request: function request(_request) {
1010
+ var timeout;
929
1011
 
930
- if (isFunction(_request.beforeSend)) {
931
- _request.beforeSend.call(this, _request);
932
- }
1012
+ if (request.timeout) {
1013
+ timeout = setTimeout(function () {
1014
+ request.abort();
1015
+ }, request.timeout);
1016
+ }
933
1017
 
934
- return _request;
935
- }
936
- };
1018
+ next(function (response) {
937
1019
 
938
- /**
939
- * HTTP method override Interceptor.
940
- */
1020
+ clearTimeout(timeout);
1021
+ });
1022
+ }
941
1023
 
942
- var exports$5 = {
943
- request: function request(_request) {
1024
+ /**
1025
+ * XMLHttp client.
1026
+ */
944
1027
 
945
- if (_request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(_request.method)) {
946
- _request.headers['X-HTTP-Method-Override'] = _request.method;
947
- _request.method = 'POST';
948
- }
1028
+ function xhrClient (request) {
1029
+ return new PromiseObj(function (resolve) {
949
1030
 
950
- return _request;
951
- }
952
- };
1031
+ var xhr = new XMLHttpRequest(),
1032
+ handler = function (event) {
953
1033
 
954
- var exports$6 = {
955
- request: function request(_request) {
1034
+ var response = request.respondWith('response' in xhr ? xhr.response : xhr.responseText, {
1035
+ status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
1036
+ statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText)
1037
+ });
956
1038
 
957
- _request.method = _request.method.toUpperCase();
958
- _request.headers = extend({}, Http.headers.common, !_request.crossOrigin ? Http.headers.custom : {}, Http.headers[_request.method.toLowerCase()], _request.headers);
1039
+ each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) {
1040
+ response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1));
1041
+ });
959
1042
 
960
- if (isPlainObject(_request.data) && /^(GET|JSONP)$/i.test(_request.method)) {
961
- extend(_request.params, _request.data);
962
- delete _request.data;
963
- }
1043
+ resolve(response);
1044
+ };
964
1045
 
965
- return _request;
966
- }
967
- };
1046
+ request.abort = function () {
1047
+ return xhr.abort();
1048
+ };
968
1049
 
969
- /**
970
- * Timeout Interceptor.
971
- */
1050
+ if (request.progress) {
1051
+ if (request.method === 'GET') {
1052
+ xhr.addEventListener('progress', request.progress);
1053
+ } else if (/^(POST|PUT)$/i.test(request.method)) {
1054
+ xhr.upload.addEventListener('progress', request.progress);
1055
+ }
1056
+ }
972
1057
 
973
- var exports$7 = function exports() {
1058
+ xhr.open(request.method, request.getUrl(), true);
974
1059
 
975
- var timeout;
1060
+ if ('responseType' in xhr) {
1061
+ xhr.responseType = 'blob';
1062
+ }
976
1063
 
977
- return {
978
- request: function request(_request) {
1064
+ if (request.credentials === true) {
1065
+ xhr.withCredentials = true;
1066
+ }
979
1067
 
980
- if (_request.timeout) {
981
- timeout = setTimeout(function () {
982
- _request.cancel();
983
- }, _request.timeout);
984
- }
1068
+ request.headers.forEach(function (value, name) {
1069
+ xhr.setRequestHeader(name, value);
1070
+ });
985
1071
 
986
- return _request;
987
- },
988
- response: function response(_response) {
1072
+ xhr.timeout = 0;
1073
+ xhr.onload = handler;
1074
+ xhr.onerror = handler;
1075
+ xhr.send(request.getBody());
1076
+ });
1077
+ }
989
1078
 
990
- clearTimeout(timeout);
1079
+ /**
1080
+ * Base client.
1081
+ */
991
1082
 
992
- return _response;
993
- }
994
- };
995
- };
1083
+ function Client (context) {
996
1084
 
997
- function interceptor (handler, vm) {
1085
+ var reqHandlers = [sendRequest],
1086
+ resHandlers = [],
1087
+ handler;
998
1088
 
999
- return function (client) {
1089
+ if (!isObject(context)) {
1090
+ context = null;
1091
+ }
1000
1092
 
1001
- if (isFunction(handler)) {
1002
- handler = handler.call(vm, Promise$1);
1003
- }
1093
+ function Client(request) {
1094
+ return new PromiseObj(function (resolve) {
1004
1095
 
1005
- return function (request) {
1096
+ function exec() {
1006
1097
 
1007
- if (isFunction(handler.request)) {
1008
- request = handler.request.call(vm, request);
1009
- }
1098
+ handler = reqHandlers.pop();
1010
1099
 
1011
- return when(request, function (request) {
1012
- return when(client(request), function (response) {
1100
+ if (isFunction(handler)) {
1101
+ handler.call(context, request, next);
1102
+ } else {
1103
+ warn('Invalid interceptor of type ' + typeof handler + ', must be a function');
1104
+ next();
1105
+ }
1106
+ }
1013
1107
 
1014
- if (isFunction(handler.response)) {
1015
- response = handler.response.call(vm, response);
1016
- }
1108
+ function next(response) {
1017
1109
 
1018
- return response;
1019
- });
1020
- });
1021
- };
1022
- };
1023
- }
1110
+ if (isFunction(response)) {
1111
+
1112
+ resHandlers.unshift(response);
1113
+ } else if (isObject(response)) {
1114
+
1115
+ resHandlers.forEach(function (handler) {
1116
+ response = when(response, function (response) {
1117
+ return handler.call(context, response) || response;
1118
+ });
1119
+ });
1120
+
1121
+ when(response, resolve);
1122
+
1123
+ return;
1124
+ }
1125
+
1126
+ exec();
1127
+ }
1128
+
1129
+ exec();
1130
+ }, context);
1131
+ }
1132
+
1133
+ Client.use = function (handler) {
1134
+ reqHandlers.push(handler);
1135
+ };
1136
+
1137
+ return Client;
1138
+ }
1024
1139
 
1025
- function when(value, fulfilled, rejected) {
1140
+ function sendRequest(request, resolve) {
1026
1141
 
1027
- var promise = Promise$1.resolve(value);
1142
+ var client = request.client || xhrClient;
1028
1143
 
1029
- if (arguments.length < 2) {
1030
- return promise;
1031
- }
1144
+ resolve(client(request));
1145
+ }
1032
1146
 
1033
- return promise.then(fulfilled, rejected);
1147
+ var classCallCheck = function (instance, Constructor) {
1148
+ if (!(instance instanceof Constructor)) {
1149
+ throw new TypeError("Cannot call a class as a function");
1034
1150
  }
1151
+ };
1035
1152
 
1036
- function xhrClient (request) {
1037
- return new Promise$1(function (resolve) {
1153
+ /**
1154
+ * HTTP Headers.
1155
+ */
1038
1156
 
1039
- var xhr = new XMLHttpRequest(),
1040
- response = { request: request },
1041
- handler;
1157
+ var Headers = function () {
1158
+ function Headers(headers) {
1159
+ var _this = this;
1042
1160
 
1043
- request.cancel = function () {
1044
- xhr.abort();
1045
- };
1161
+ classCallCheck(this, Headers);
1046
1162
 
1047
- xhr.open(request.method, Url(request), true);
1048
1163
 
1049
- handler = function handler(event) {
1164
+ this.map = {};
1050
1165
 
1051
- response.data = 'response' in xhr ? xhr.response : xhr.responseText;
1052
- response.status = xhr.status === 1223 ? 204 : xhr.status; // IE9 status bug
1053
- response.statusText = trim(xhr.statusText || '');
1054
- response.headers = xhr.getAllResponseHeaders();
1166
+ each(headers, function (value, name) {
1167
+ return _this.append(name, value);
1168
+ });
1169
+ }
1055
1170
 
1056
- resolve(response);
1057
- };
1171
+ Headers.prototype.has = function has(name) {
1172
+ return getName(this.map, name) !== null;
1173
+ };
1058
1174
 
1059
- xhr.timeout = 0;
1060
- xhr.onload = handler;
1061
- xhr.onabort = handler;
1062
- xhr.onerror = handler;
1063
- xhr.ontimeout = function () {};
1064
- xhr.onprogress = function () {};
1175
+ Headers.prototype.get = function get(name) {
1065
1176
 
1066
- if (isPlainObject(request.xhr)) {
1067
- extend(xhr, request.xhr);
1068
- }
1177
+ var list = this.map[getName(this.map, name)];
1069
1178
 
1070
- if (isPlainObject(request.upload)) {
1071
- extend(xhr.upload, request.upload);
1072
- }
1179
+ return list ? list[0] : null;
1180
+ };
1073
1181
 
1074
- each(request.headers || {}, function (value, header) {
1075
- xhr.setRequestHeader(header, value);
1076
- });
1182
+ Headers.prototype.getAll = function getAll(name) {
1183
+ return this.map[getName(this.map, name)] || [];
1184
+ };
1077
1185
 
1078
- xhr.send(request.data);
1079
- });
1080
- }
1186
+ Headers.prototype.set = function set(name, value) {
1187
+ this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)];
1188
+ };
1081
1189
 
1082
- function Client (request) {
1190
+ Headers.prototype.append = function append(name, value) {
1083
1191
 
1084
- var response = (request.client || xhrClient)(request);
1192
+ var list = this.getAll(name);
1085
1193
 
1086
- return Promise$1.resolve(response).then(function (response) {
1194
+ if (list.length) {
1195
+ list.push(trim(value));
1196
+ } else {
1197
+ this.set(name, value);
1198
+ }
1199
+ };
1087
1200
 
1088
- if (response.headers) {
1201
+ Headers.prototype.delete = function _delete(name) {
1202
+ delete this.map[getName(this.map, name)];
1203
+ };
1089
1204
 
1090
- var headers = parseHeaders(response.headers);
1205
+ Headers.prototype.forEach = function forEach(callback, thisArg) {
1206
+ var _this2 = this;
1091
1207
 
1092
- response.headers = function (name) {
1208
+ each(this.map, function (list, name) {
1209
+ each(list, function (value) {
1210
+ return callback.call(thisArg, value, name, _this2);
1211
+ });
1212
+ });
1213
+ };
1093
1214
 
1094
- if (name) {
1095
- return headers[toLower(name)];
1096
- }
1215
+ return Headers;
1216
+ }();
1097
1217
 
1098
- return headers;
1099
- };
1100
- }
1218
+ function getName(map, name) {
1219
+ return Object.keys(map).reduce(function (prev, curr) {
1220
+ return toLower(name) === toLower(curr) ? curr : prev;
1221
+ }, null);
1222
+ }
1101
1223
 
1102
- response.ok = response.status >= 200 && response.status < 300;
1224
+ function normalizeName(name) {
1103
1225
 
1104
- return response;
1105
- });
1106
- }
1226
+ if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
1227
+ throw new TypeError('Invalid character in header field name');
1228
+ }
1107
1229
 
1108
- function parseHeaders(str) {
1230
+ return trim(name);
1231
+ }
1109
1232
 
1110
- var headers = {},
1111
- value,
1112
- name,
1113
- i;
1233
+ /**
1234
+ * HTTP Response.
1235
+ */
1114
1236
 
1115
- if (isString(str)) {
1116
- each(str.split('\n'), function (row) {
1237
+ var Response = function () {
1238
+ function Response(body, _ref) {
1239
+ var url = _ref.url;
1240
+ var headers = _ref.headers;
1241
+ var status = _ref.status;
1242
+ var statusText = _ref.statusText;
1243
+ classCallCheck(this, Response);
1117
1244
 
1118
- i = row.indexOf(':');
1119
- name = trim(toLower(row.slice(0, i)));
1120
- value = trim(row.slice(i + 1));
1121
1245
 
1122
- if (headers[name]) {
1246
+ this.url = url;
1247
+ this.ok = status >= 200 && status < 300;
1248
+ this.status = status || 0;
1249
+ this.statusText = statusText || '';
1250
+ this.headers = new Headers(headers);
1251
+ this.body = body;
1123
1252
 
1124
- if (isArray(headers[name])) {
1125
- headers[name].push(value);
1126
- } else {
1127
- headers[name] = [headers[name], value];
1128
- }
1129
- } else {
1253
+ if (isString(body)) {
1130
1254
 
1131
- headers[name] = value;
1132
- }
1133
- });
1134
- }
1255
+ this.bodyText = body;
1256
+ } else if (isBlob(body)) {
1135
1257
 
1136
- return headers;
1137
- }
1258
+ this.bodyBlob = body;
1138
1259
 
1139
- /**
1140
- * Service for sending network requests.
1141
- */
1260
+ if (isBlobText(body)) {
1261
+ this.bodyText = blobText(body);
1262
+ }
1263
+ }
1264
+ }
1142
1265
 
1143
- var jsonType = { 'Content-Type': 'application/json' };
1266
+ Response.prototype.blob = function blob() {
1267
+ return when(this.bodyBlob);
1268
+ };
1144
1269
 
1145
- function Http(url, options) {
1270
+ Response.prototype.text = function text() {
1271
+ return when(this.bodyText);
1272
+ };
1146
1273
 
1147
- var self = this || {},
1148
- client = Client,
1149
- request,
1150
- promise;
1274
+ Response.prototype.json = function json() {
1275
+ return when(this.text(), function (text) {
1276
+ return JSON.parse(text);
1277
+ });
1278
+ };
1151
1279
 
1152
- Http.interceptors.forEach(function (handler) {
1153
- client = interceptor(handler, self.$vm)(client);
1154
- });
1280
+ return Response;
1281
+ }();
1155
1282
 
1156
- options = isObject(url) ? url : extend({ url: url }, options);
1157
- request = merge({}, Http.options, self.$options, options);
1158
- promise = client(request).bind(self.$vm).then(function (response) {
1283
+ function blobText(body) {
1284
+ return new PromiseObj(function (resolve) {
1159
1285
 
1160
- return response.ok ? response : Promise$1.reject(response);
1161
- }, function (response) {
1286
+ var reader = new FileReader();
1162
1287
 
1163
- if (response instanceof Error) {
1164
- error(response);
1165
- }
1288
+ reader.readAsText(body);
1289
+ reader.onload = function () {
1290
+ resolve(reader.result);
1291
+ };
1292
+ });
1293
+ }
1166
1294
 
1167
- return Promise$1.reject(response);
1168
- });
1295
+ function isBlobText(body) {
1296
+ return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1;
1297
+ }
1169
1298
 
1170
- if (request.success) {
1171
- promise.success(request.success);
1172
- }
1299
+ /**
1300
+ * HTTP Request.
1301
+ */
1173
1302
 
1174
- if (request.error) {
1175
- promise.error(request.error);
1176
- }
1303
+ var Request = function () {
1304
+ function Request(options) {
1305
+ classCallCheck(this, Request);
1177
1306
 
1178
- return promise;
1179
- }
1180
1307
 
1181
- Http.options = {
1182
- method: 'get',
1183
- data: '',
1184
- params: {},
1185
- headers: {},
1186
- xhr: null,
1187
- upload: null,
1188
- jsonp: 'callback',
1189
- beforeSend: null,
1190
- crossOrigin: null,
1191
- emulateHTTP: false,
1192
- emulateJSON: false,
1193
- timeout: 0
1194
- };
1308
+ this.body = null;
1309
+ this.params = {};
1195
1310
 
1196
- Http.headers = {
1197
- put: jsonType,
1198
- post: jsonType,
1199
- patch: jsonType,
1200
- delete: jsonType,
1201
- common: { 'Accept': 'application/json, text/plain, */*' },
1202
- custom: { 'X-Requested-With': 'XMLHttpRequest' }
1203
- };
1311
+ assign(this, options, {
1312
+ method: toUpper(options.method || 'GET')
1313
+ });
1204
1314
 
1205
- Http.interceptors = [exports$4, exports$7, exports$3, exports$5, exports$2, exports$6, exports$1];
1315
+ if (!(this.headers instanceof Headers)) {
1316
+ this.headers = new Headers(this.headers);
1317
+ }
1318
+ }
1206
1319
 
1207
- ['get', 'put', 'post', 'patch', 'delete', 'jsonp'].forEach(function (method) {
1320
+ Request.prototype.getUrl = function getUrl() {
1321
+ return Url(this);
1322
+ };
1208
1323
 
1209
- Http[method] = function (url, data, success, options) {
1324
+ Request.prototype.getBody = function getBody() {
1325
+ return this.body;
1326
+ };
1210
1327
 
1211
- if (isFunction(data)) {
1212
- options = success;
1213
- success = data;
1214
- data = undefined;
1215
- }
1328
+ Request.prototype.respondWith = function respondWith(body, options) {
1329
+ return new Response(body, assign(options || {}, { url: this.getUrl() }));
1330
+ };
1216
1331
 
1217
- if (isObject(success)) {
1218
- options = success;
1219
- success = undefined;
1220
- }
1332
+ return Request;
1333
+ }();
1221
1334
 
1222
- return this(url, extend({ method: method, data: data, success: success }, options));
1223
- };
1224
- });
1335
+ /**
1336
+ * Service for sending network requests.
1337
+ */
1225
1338
 
1226
- function Resource(url, params, actions, options) {
1339
+ var CUSTOM_HEADERS = { 'X-Requested-With': 'XMLHttpRequest' };
1340
+ var COMMON_HEADERS = { 'Accept': 'application/json, text/plain, */*' };
1341
+ var JSON_CONTENT_TYPE = { 'Content-Type': 'application/json;charset=utf-8' };
1227
1342
 
1228
- var self = this || {},
1229
- resource = {};
1343
+ function Http(options) {
1230
1344
 
1231
- actions = extend({}, Resource.actions, actions);
1345
+ var self = this || {},
1346
+ client = Client(self.$vm);
1232
1347
 
1233
- each(actions, function (action, name) {
1348
+ defaults(options || {}, self.$options, Http.options);
1234
1349
 
1235
- action = merge({ url: url, params: params || {} }, options, action);
1350
+ Http.interceptors.forEach(function (handler) {
1351
+ client.use(handler);
1352
+ });
1236
1353
 
1237
- resource[name] = function () {
1238
- return (self.$http || Http)(opts(action, arguments));
1239
- };
1240
- });
1354
+ return client(new Request(options)).then(function (response) {
1241
1355
 
1242
- return resource;
1243
- }
1356
+ return response.ok ? response : PromiseObj.reject(response);
1357
+ }, function (response) {
1244
1358
 
1245
- function opts(action, args) {
1359
+ if (response instanceof Error) {
1360
+ error(response);
1361
+ }
1246
1362
 
1247
- var options = extend({}, action),
1248
- params = {},
1249
- data,
1250
- success,
1251
- error;
1363
+ return PromiseObj.reject(response);
1364
+ });
1365
+ }
1252
1366
 
1253
- switch (args.length) {
1367
+ Http.options = {};
1254
1368
 
1255
- case 4:
1369
+ Http.headers = {
1370
+ put: JSON_CONTENT_TYPE,
1371
+ post: JSON_CONTENT_TYPE,
1372
+ patch: JSON_CONTENT_TYPE,
1373
+ delete: JSON_CONTENT_TYPE,
1374
+ custom: CUSTOM_HEADERS,
1375
+ common: COMMON_HEADERS
1376
+ };
1256
1377
 
1257
- error = args[3];
1258
- success = args[2];
1378
+ Http.interceptors = [before, timeout, method, body, jsonp, header, cors];
1259
1379
 
1260
- case 3:
1261
- case 2:
1380
+ ['get', 'delete', 'head', 'jsonp'].forEach(function (method) {
1262
1381
 
1263
- if (isFunction(args[1])) {
1382
+ Http[method] = function (url, options) {
1383
+ return this(assign(options || {}, { url: url, method: method }));
1384
+ };
1385
+ });
1264
1386
 
1265
- if (isFunction(args[0])) {
1387
+ ['post', 'put', 'patch'].forEach(function (method) {
1266
1388
 
1267
- success = args[0];
1268
- error = args[1];
1389
+ Http[method] = function (url, body, options) {
1390
+ return this(assign(options || {}, { url: url, method: method, body: body }));
1391
+ };
1392
+ });
1269
1393
 
1270
- break;
1271
- }
1394
+ /**
1395
+ * Service for interacting with RESTful services.
1396
+ */
1272
1397
 
1273
- success = args[1];
1274
- error = args[2];
1275
- } else {
1398
+ function Resource(url, params, actions, options) {
1276
1399
 
1277
- params = args[0];
1278
- data = args[1];
1279
- success = args[2];
1400
+ var self = this || {},
1401
+ resource = {};
1280
1402
 
1281
- break;
1282
- }
1403
+ actions = assign({}, Resource.actions, actions);
1283
1404
 
1284
- case 1:
1405
+ each(actions, function (action, name) {
1285
1406
 
1286
- if (isFunction(args[0])) {
1287
- success = args[0];
1288
- } else if (/^(POST|PUT|PATCH)$/i.test(options.method)) {
1289
- data = args[0];
1290
- } else {
1291
- params = args[0];
1292
- }
1407
+ action = merge({ url: url, params: assign({}, params) }, options, action);
1293
1408
 
1294
- break;
1409
+ resource[name] = function () {
1410
+ return (self.$http || Http)(opts(action, arguments));
1411
+ };
1412
+ });
1295
1413
 
1296
- case 0:
1414
+ return resource;
1415
+ }
1297
1416
 
1298
- break;
1417
+ function opts(action, args) {
1299
1418
 
1300
- default:
1419
+ var options = assign({}, action),
1420
+ params = {},
1421
+ body;
1301
1422
 
1302
- throw 'Expected up to 4 arguments [params, data, success, error], got ' + args.length + ' arguments';
1303
- }
1423
+ switch (args.length) {
1304
1424
 
1305
- options.data = data;
1306
- options.params = extend({}, options.params, params);
1425
+ case 2:
1307
1426
 
1308
- if (success) {
1309
- options.success = success;
1310
- }
1427
+ params = args[0];
1428
+ body = args[1];
1311
1429
 
1312
- if (error) {
1313
- options.error = error;
1314
- }
1430
+ break;
1315
1431
 
1316
- return options;
1317
- }
1432
+ case 1:
1318
1433
 
1319
- Resource.actions = {
1434
+ if (/^(POST|PUT|PATCH)$/i.test(options.method)) {
1435
+ body = args[0];
1436
+ } else {
1437
+ params = args[0];
1438
+ }
1320
1439
 
1321
- get: { method: 'GET' },
1322
- save: { method: 'POST' },
1323
- query: { method: 'GET' },
1324
- update: { method: 'PUT' },
1325
- remove: { method: 'DELETE' },
1326
- delete: { method: 'DELETE' }
1440
+ break;
1327
1441
 
1328
- };
1442
+ case 0:
1329
1443
 
1330
- function plugin(Vue) {
1444
+ break;
1331
1445
 
1332
- if (plugin.installed) {
1333
- return;
1334
- }
1446
+ default:
1335
1447
 
1336
- Util(Vue);
1448
+ throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments';
1449
+ }
1337
1450
 
1338
- Vue.url = Url;
1339
- Vue.http = Http;
1340
- Vue.resource = Resource;
1341
- Vue.Promise = Promise$1;
1451
+ options.body = body;
1452
+ options.params = assign({}, options.params, params);
1342
1453
 
1343
- Object.defineProperties(Vue.prototype, {
1454
+ return options;
1455
+ }
1344
1456
 
1345
- $url: {
1346
- get: function get() {
1347
- return options(Vue.url, this, this.$options.url);
1348
- }
1349
- },
1457
+ Resource.actions = {
1350
1458
 
1351
- $http: {
1352
- get: function get() {
1353
- return options(Vue.http, this, this.$options.http);
1354
- }
1355
- },
1459
+ get: { method: 'GET' },
1460
+ save: { method: 'POST' },
1461
+ query: { method: 'GET' },
1462
+ update: { method: 'PUT' },
1463
+ remove: { method: 'DELETE' },
1464
+ delete: { method: 'DELETE' }
1356
1465
 
1357
- $resource: {
1358
- get: function get() {
1359
- return Vue.resource.bind(this);
1360
- }
1361
- },
1466
+ };
1362
1467
 
1363
- $promise: {
1364
- get: function get() {
1365
- var _this = this;
1468
+ /**
1469
+ * Install plugin.
1470
+ */
1366
1471
 
1367
- return function (executor) {
1368
- return new Vue.Promise(executor, _this);
1369
- };
1370
- }
1371
- }
1472
+ function plugin(Vue) {
1372
1473
 
1373
- });
1374
- }
1474
+ if (plugin.installed) {
1475
+ return;
1476
+ }
1375
1477
 
1376
- if (typeof window !== 'undefined' && window.Vue) {
1377
- window.Vue.use(plugin);
1378
- }
1478
+ Util(Vue);
1479
+
1480
+ Vue.url = Url;
1481
+ Vue.http = Http;
1482
+ Vue.resource = Resource;
1483
+ Vue.Promise = PromiseObj;
1484
+
1485
+ Object.defineProperties(Vue.prototype, {
1486
+
1487
+ $url: {
1488
+ get: function () {
1489
+ return options(Vue.url, this, this.$options.url);
1490
+ }
1491
+ },
1492
+
1493
+ $http: {
1494
+ get: function () {
1495
+ return options(Vue.http, this, this.$options.http);
1496
+ }
1497
+ },
1498
+
1499
+ $resource: {
1500
+ get: function () {
1501
+ return Vue.resource.bind(this);
1502
+ }
1503
+ },
1504
+
1505
+ $promise: {
1506
+ get: function () {
1507
+ var _this = this;
1508
+
1509
+ return function (executor) {
1510
+ return new Vue.Promise(executor, _this);
1511
+ };
1512
+ }
1513
+ }
1514
+
1515
+ });
1516
+ }
1517
+
1518
+ if (typeof window !== 'undefined' && window.Vue) {
1519
+ window.Vue.use(plugin);
1520
+ }
1379
1521
 
1380
- return plugin;
1522
+ return plugin;
1381
1523
 
1382
- }));
1524
+ })));