vuejs-rails 1.0.26 → 2.0.1

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