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 +4 -4
- data/README.md +8 -1
- data/lib/vuejs/version.rb +1 -1
- data/vendor/assets/CHANGELOG +13 -0
- data/vendor/assets/javascripts/vue-resource.js +1212 -1070
- data/vendor/assets/javascripts/vue-router2.js +1837 -0
- data/vendor/assets/javascripts/vue.js +8884 -8714
- data/vendor/assets/javascripts/vue2.js +7402 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f737043f53f61ba47212bfa3b8351aa6096ffe9
|
4
|
+
data.tar.gz: 0eb0df43f061b60f5f525926d0d78296295cf4be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 (
|
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,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* vue-resource
|
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
|
-
|
13
|
+
/**
|
14
|
+
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
|
15
|
+
*/
|
33
16
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
}
|
44
|
-
}
|
193
|
+
if (typeof Promise === 'undefined') {
|
194
|
+
window.Promise = Promise$1;
|
195
|
+
}
|
45
196
|
|
46
|
-
|
47
|
-
return util.nextTick(cb, ctx);
|
48
|
-
}
|
197
|
+
function PromiseObj(executor, context) {
|
49
198
|
|
50
|
-
|
51
|
-
|
52
|
-
|
199
|
+
if (executor instanceof Promise) {
|
200
|
+
this.promise = executor;
|
201
|
+
} else {
|
202
|
+
this.promise = new Promise(executor.bind(context));
|
203
|
+
}
|
53
204
|
|
54
|
-
|
55
|
-
|
56
|
-
}
|
205
|
+
this.context = context;
|
206
|
+
}
|
57
207
|
|
58
|
-
|
59
|
-
|
60
|
-
|
208
|
+
PromiseObj.all = function (iterable, context) {
|
209
|
+
return new PromiseObj(Promise.all(iterable), context);
|
210
|
+
};
|
61
211
|
|
62
|
-
|
63
|
-
|
64
|
-
|
212
|
+
PromiseObj.resolve = function (value, context) {
|
213
|
+
return new PromiseObj(Promise.resolve(value), context);
|
214
|
+
};
|
65
215
|
|
66
|
-
|
67
|
-
|
68
|
-
|
216
|
+
PromiseObj.reject = function (reason, context) {
|
217
|
+
return new PromiseObj(Promise.reject(reason), context);
|
218
|
+
};
|
69
219
|
|
70
|
-
|
71
|
-
|
72
|
-
|
220
|
+
PromiseObj.race = function (iterable, context) {
|
221
|
+
return new PromiseObj(Promise.race(iterable), context);
|
222
|
+
};
|
73
223
|
|
74
|
-
|
224
|
+
var p = PromiseObj.prototype;
|
75
225
|
|
76
|
-
|
226
|
+
p.bind = function (context) {
|
227
|
+
this.context = context;
|
228
|
+
return this;
|
229
|
+
};
|
77
230
|
|
78
|
-
|
79
|
-
opts = opts.call(obj);
|
80
|
-
}
|
231
|
+
p.then = function (fulfilled, rejected) {
|
81
232
|
|
82
|
-
|
83
|
-
|
233
|
+
if (fulfilled && fulfilled.bind && this.context) {
|
234
|
+
fulfilled = fulfilled.bind(this.context);
|
235
|
+
}
|
84
236
|
|
85
|
-
|
237
|
+
if (rejected && rejected.bind && this.context) {
|
238
|
+
rejected = rejected.bind(this.context);
|
239
|
+
}
|
86
240
|
|
87
|
-
|
241
|
+
return new PromiseObj(this.promise.then(fulfilled, rejected), this.context);
|
242
|
+
};
|
88
243
|
|
89
|
-
|
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
|
-
|
102
|
-
|
246
|
+
if (rejected && rejected.bind && this.context) {
|
247
|
+
rejected = rejected.bind(this.context);
|
248
|
+
}
|
103
249
|
|
104
|
-
|
250
|
+
return new PromiseObj(this.promise.catch(rejected), this.context);
|
251
|
+
};
|
105
252
|
|
106
|
-
|
253
|
+
p.finally = function (callback) {
|
107
254
|
|
108
|
-
|
109
|
-
|
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
|
-
|
113
|
-
|
264
|
+
/**
|
265
|
+
* Utility functions.
|
266
|
+
*/
|
114
267
|
|
115
|
-
|
268
|
+
var debug = false;var util = {};var slice = [].slice;
|
116
269
|
|
117
|
-
var args = array.slice.call(arguments, 1);
|
118
270
|
|
119
|
-
|
120
|
-
|
121
|
-
|
271
|
+
function Util (Vue) {
|
272
|
+
util = Vue.util;
|
273
|
+
debug = Vue.config.debug || !Vue.config.silent;
|
274
|
+
}
|
122
275
|
|
123
|
-
|
124
|
-
|
276
|
+
function warn(msg) {
|
277
|
+
if (typeof console !== 'undefined' && debug) {
|
278
|
+
console.warn('[VueResource warn]: ' + msg);
|
279
|
+
}
|
280
|
+
}
|
125
281
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
288
|
+
function nextTick(cb, ctx) {
|
289
|
+
return util.nextTick(cb, ctx);
|
290
|
+
}
|
143
291
|
|
144
|
-
|
292
|
+
function trim(str) {
|
293
|
+
return str.replace(/^\s*|\s*$/g, '');
|
294
|
+
}
|
145
295
|
|
146
|
-
|
147
|
-
|
148
|
-
|
296
|
+
function toLower(str) {
|
297
|
+
return str ? str.toLowerCase() : '';
|
298
|
+
}
|
149
299
|
|
150
|
-
|
151
|
-
|
300
|
+
function toUpper(str) {
|
301
|
+
return str ? str.toUpperCase() : '';
|
302
|
+
}
|
152
303
|
|
153
|
-
|
304
|
+
var isArray = Array.isArray;
|
154
305
|
|
155
|
-
|
156
|
-
|
157
|
-
|
306
|
+
function isString(val) {
|
307
|
+
return typeof val === 'string';
|
308
|
+
}
|
158
309
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
}
|
163
|
-
});
|
310
|
+
function isBoolean(val) {
|
311
|
+
return val === true || val === false;
|
312
|
+
}
|
164
313
|
|
165
|
-
|
314
|
+
function isFunction(val) {
|
315
|
+
return typeof val === 'function';
|
316
|
+
}
|
166
317
|
|
167
|
-
|
168
|
-
|
169
|
-
|
318
|
+
function isObject(obj) {
|
319
|
+
return obj !== null && typeof obj === 'object';
|
320
|
+
}
|
170
321
|
|
171
|
-
|
172
|
-
|
322
|
+
function isPlainObject(obj) {
|
323
|
+
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
|
324
|
+
}
|
173
325
|
|
174
|
-
|
326
|
+
function isBlob(obj) {
|
327
|
+
return typeof Blob !== 'undefined' && obj instanceof Blob;
|
328
|
+
}
|
175
329
|
|
176
|
-
|
177
|
-
|
330
|
+
function isFormData(obj) {
|
331
|
+
return typeof FormData !== 'undefined' && obj instanceof FormData;
|
332
|
+
}
|
178
333
|
|
179
|
-
|
334
|
+
function when(value, fulfilled, rejected) {
|
180
335
|
|
181
|
-
|
336
|
+
var promise = PromiseObj.resolve(value);
|
182
337
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}
|
338
|
+
if (arguments.length < 2) {
|
339
|
+
return promise;
|
340
|
+
}
|
187
341
|
|
188
|
-
|
189
|
-
|
342
|
+
return promise.then(fulfilled, rejected);
|
343
|
+
}
|
190
344
|
|
191
|
-
|
192
|
-
delete options.params[key];
|
193
|
-
});
|
345
|
+
function options(fn, obj, opts) {
|
194
346
|
|
195
|
-
|
196
|
-
}
|
347
|
+
opts = opts || {};
|
197
348
|
|
198
|
-
|
349
|
+
if (isFunction(opts)) {
|
350
|
+
opts = opts.call(obj);
|
351
|
+
}
|
199
352
|
|
200
|
-
|
201
|
-
|
353
|
+
return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
|
354
|
+
}
|
202
355
|
|
203
|
-
|
356
|
+
function each(obj, iterator) {
|
204
357
|
|
205
|
-
|
206
|
-
}
|
358
|
+
var i, key;
|
207
359
|
|
208
|
-
|
209
|
-
|
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
|
-
|
372
|
+
return obj;
|
373
|
+
}
|
213
374
|
|
214
|
-
|
215
|
-
expanded = tmpl.expand(params);
|
375
|
+
var assign = Object.assign || _assign;
|
216
376
|
|
217
|
-
|
218
|
-
variables.push.apply(variables, tmpl.vars);
|
219
|
-
}
|
377
|
+
function merge(target) {
|
220
378
|
|
221
|
-
|
222
|
-
}
|
379
|
+
var args = slice.call(arguments, 1);
|
223
380
|
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
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
|
-
|
335
|
-
return value !== undefined && value !== null;
|
336
|
-
}
|
388
|
+
function defaults(target) {
|
337
389
|
|
338
|
-
|
339
|
-
return operator === ';' || operator === '&' || operator === '?';
|
340
|
-
}
|
390
|
+
var args = slice.call(arguments, 1);
|
341
391
|
|
342
|
-
|
392
|
+
args.forEach(function (source) {
|
343
393
|
|
344
|
-
|
394
|
+
for (var key in source) {
|
395
|
+
if (target[key] === undefined) {
|
396
|
+
target[key] = source[key];
|
397
|
+
}
|
398
|
+
}
|
399
|
+
});
|
345
400
|
|
346
|
-
|
347
|
-
|
348
|
-
} else {
|
349
|
-
return value;
|
350
|
-
}
|
351
|
-
}
|
401
|
+
return target;
|
402
|
+
}
|
352
403
|
|
353
|
-
|
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
|
-
|
406
|
+
var args = slice.call(arguments, 1);
|
363
407
|
|
364
|
-
|
365
|
-
|
408
|
+
args.forEach(function (source) {
|
409
|
+
_merge(target, source);
|
410
|
+
});
|
366
411
|
|
367
|
-
|
368
|
-
|
369
|
-
});
|
412
|
+
return target;
|
413
|
+
}
|
370
414
|
|
371
|
-
|
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
|
-
|
376
|
-
|
431
|
+
/**
|
432
|
+
* Root Prefix Transform.
|
433
|
+
*/
|
377
434
|
|
378
|
-
|
379
|
-
var el = document.createElement('a');
|
435
|
+
function root (options, next) {
|
380
436
|
|
381
|
-
|
437
|
+
var url = next(options);
|
382
438
|
|
383
|
-
|
384
|
-
|
385
|
-
|
439
|
+
if (isString(options.root) && !url.match(/^(https?:)?\//)) {
|
440
|
+
url = options.root + '/' + url;
|
441
|
+
}
|
386
442
|
|
387
|
-
|
388
|
-
|
389
|
-
}
|
443
|
+
return url;
|
444
|
+
}
|
390
445
|
|
391
|
-
|
446
|
+
/**
|
447
|
+
* Query Parameter Transform.
|
448
|
+
*/
|
392
449
|
|
393
|
-
|
394
|
-
transform = factory(handler, transform, self.$vm);
|
395
|
-
});
|
450
|
+
function query (options, next) {
|
396
451
|
|
397
|
-
|
398
|
-
|
452
|
+
var urlParams = Object.keys(Url.options.params),
|
453
|
+
query = {},
|
454
|
+
url = next(options);
|
399
455
|
|
400
|
-
|
401
|
-
|
402
|
-
|
456
|
+
each(options.params, function (value, key) {
|
457
|
+
if (urlParams.indexOf(key) === -1) {
|
458
|
+
query[key] = value;
|
459
|
+
}
|
460
|
+
});
|
403
461
|
|
404
|
-
|
405
|
-
url: '',
|
406
|
-
root: null,
|
407
|
-
params: {}
|
408
|
-
};
|
462
|
+
query = Url.params(query);
|
409
463
|
|
410
|
-
|
411
|
-
|
412
|
-
|
464
|
+
if (query) {
|
465
|
+
url += (url.indexOf('?') == -1 ? '?' : '&') + query;
|
466
|
+
}
|
413
467
|
|
414
|
-
|
468
|
+
return url;
|
469
|
+
}
|
415
470
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
* @param {Object} obj
|
420
|
-
*/
|
471
|
+
/**
|
472
|
+
* URL Template v2.0.6 (https://github.com/bramstein/url-template)
|
473
|
+
*/
|
421
474
|
|
422
|
-
|
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
|
-
|
425
|
-
escape = encodeURIComponent;
|
629
|
+
function template (options) {
|
426
630
|
|
427
|
-
|
631
|
+
var variables = [],
|
632
|
+
url = expand(options.url, options.params, variables);
|
428
633
|
|
429
|
-
|
430
|
-
|
431
|
-
|
634
|
+
variables.forEach(function (key) {
|
635
|
+
delete options.params[key];
|
636
|
+
});
|
432
637
|
|
433
|
-
|
434
|
-
|
435
|
-
}
|
638
|
+
return url;
|
639
|
+
}
|
436
640
|
|
437
|
-
|
438
|
-
|
641
|
+
/**
|
642
|
+
* Service for URL templating.
|
643
|
+
*/
|
439
644
|
|
440
|
-
|
645
|
+
var ie = document.documentMode;
|
646
|
+
var el = document.createElement('a');
|
441
647
|
|
442
|
-
|
443
|
-
};
|
648
|
+
function Url(url, params) {
|
444
649
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
* @param {String} url
|
449
|
-
*/
|
650
|
+
var self = this || {},
|
651
|
+
options = url,
|
652
|
+
transform;
|
450
653
|
|
451
|
-
|
654
|
+
if (isString(url)) {
|
655
|
+
options = { url: url, params: params };
|
656
|
+
}
|
452
657
|
|
453
|
-
|
454
|
-
el.href = url;
|
455
|
-
url = el.href;
|
456
|
-
}
|
658
|
+
options = merge({}, Url.options, self.$options, options);
|
457
659
|
|
458
|
-
|
660
|
+
Url.transforms.forEach(function (handler) {
|
661
|
+
transform = factory(handler, transform, self.$vm);
|
662
|
+
});
|
459
663
|
|
460
|
-
|
461
|
-
|
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
|
-
|
473
|
-
|
474
|
-
|
475
|
-
};
|
476
|
-
}
|
667
|
+
/**
|
668
|
+
* Url options.
|
669
|
+
*/
|
477
670
|
|
478
|
-
|
671
|
+
Url.options = {
|
672
|
+
url: '',
|
673
|
+
root: null,
|
674
|
+
params: {}
|
675
|
+
};
|
479
676
|
|
480
|
-
|
481
|
-
|
482
|
-
|
677
|
+
/**
|
678
|
+
* Url transforms.
|
679
|
+
*/
|
483
680
|
|
484
|
-
|
681
|
+
Url.transforms = [template, query, root];
|
485
682
|
|
486
|
-
|
683
|
+
/**
|
684
|
+
* Encodes a Url parameter string.
|
685
|
+
*
|
686
|
+
* @param {Object} obj
|
687
|
+
*/
|
487
688
|
|
488
|
-
|
489
|
-
key = scope + '[' + (plain || hash ? key : '') + ']';
|
490
|
-
}
|
689
|
+
Url.params = function (obj) {
|
491
690
|
|
492
|
-
|
493
|
-
|
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
|
-
|
507
|
-
|
508
|
-
|
696
|
+
if (isFunction(value)) {
|
697
|
+
value = value();
|
698
|
+
}
|
509
699
|
|
510
|
-
|
700
|
+
if (value === null) {
|
701
|
+
value = '';
|
702
|
+
}
|
511
703
|
|
512
|
-
|
513
|
-
|
514
|
-
this.deferred = [];
|
704
|
+
this.push(escape(key) + '=' + escape(value));
|
705
|
+
};
|
515
706
|
|
516
|
-
|
707
|
+
serialize(params, obj);
|
517
708
|
|
518
|
-
|
519
|
-
|
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
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
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
|
-
|
692
|
-
|
693
|
-
};
|
773
|
+
function xdrClient (request) {
|
774
|
+
return new PromiseObj(function (resolve) {
|
694
775
|
|
695
|
-
|
696
|
-
|
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
|
-
|
704
|
-
return new Promise$1(PromiseObj.race(iterable), context);
|
705
|
-
};
|
781
|
+
var status = 0;
|
706
782
|
|
707
|
-
|
783
|
+
if (type === 'load') {
|
784
|
+
status = 200;
|
785
|
+
} else if (type === 'error') {
|
786
|
+
status = 500;
|
787
|
+
}
|
708
788
|
|
709
|
-
|
710
|
-
|
711
|
-
return this;
|
712
|
-
};
|
789
|
+
resolve(request.respondWith(xdr.responseText, { status: status }));
|
790
|
+
};
|
713
791
|
|
714
|
-
|
792
|
+
request.abort = function () {
|
793
|
+
return xdr.abort();
|
794
|
+
};
|
715
795
|
|
716
|
-
|
717
|
-
|
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
|
-
|
721
|
-
|
722
|
-
|
806
|
+
/**
|
807
|
+
* CORS Interceptor.
|
808
|
+
*/
|
723
809
|
|
724
|
-
|
810
|
+
var ORIGIN_URL = Url.parse(location.href);
|
811
|
+
var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
|
725
812
|
|
726
|
-
|
727
|
-
};
|
813
|
+
function cors (request, next) {
|
728
814
|
|
729
|
-
|
815
|
+
if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
|
816
|
+
request.crossOrigin = true;
|
817
|
+
}
|
730
818
|
|
731
|
-
|
732
|
-
rejected = rejected.bind(this.context);
|
733
|
-
}
|
819
|
+
if (request.crossOrigin) {
|
734
820
|
|
735
|
-
|
821
|
+
if (!SUPPORTS_CORS) {
|
822
|
+
request.client = xdrClient;
|
823
|
+
}
|
736
824
|
|
737
|
-
|
738
|
-
|
825
|
+
delete request.emulateHTTP;
|
826
|
+
}
|
739
827
|
|
740
|
-
|
828
|
+
next();
|
829
|
+
}
|
741
830
|
|
742
|
-
|
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
|
-
|
833
|
+
var requestUrl = Url.parse(Url(request));
|
752
834
|
|
753
|
-
|
835
|
+
return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host;
|
836
|
+
}
|
754
837
|
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
};
|
838
|
+
/**
|
839
|
+
* Body Interceptor.
|
840
|
+
*/
|
759
841
|
|
760
|
-
|
842
|
+
function body (request, next) {
|
761
843
|
|
762
|
-
|
844
|
+
if (isFormData(request.body)) {
|
763
845
|
|
764
|
-
|
765
|
-
|
766
|
-
});
|
767
|
-
};
|
846
|
+
request.headers.delete('Content-Type');
|
847
|
+
} else if (isObject(request.body) || isArray(request.body)) {
|
768
848
|
|
769
|
-
|
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
|
-
|
857
|
+
next(function (response) {
|
772
858
|
|
773
|
-
|
774
|
-
|
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
|
-
|
778
|
-
};
|
868
|
+
return response.bodyText ? when(response.text(), function (text) {
|
779
869
|
|
780
|
-
|
781
|
-
return new Promise$1(function (resolve) {
|
870
|
+
var type = response.headers.get('Content-Type');
|
782
871
|
|
783
|
-
|
784
|
-
response = { request: request },
|
785
|
-
handler;
|
872
|
+
if (isString(type) && type.indexOf('application/json') === 0) {
|
786
873
|
|
787
|
-
|
788
|
-
|
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
|
-
|
883
|
+
return response;
|
884
|
+
}) : response;
|
885
|
+
});
|
886
|
+
}
|
792
887
|
|
793
|
-
|
888
|
+
/**
|
889
|
+
* JSONP client.
|
890
|
+
*/
|
794
891
|
|
795
|
-
|
796
|
-
|
797
|
-
response.statusText = xdr.statusText || '';
|
892
|
+
function jsonpClient (request) {
|
893
|
+
return new PromiseObj(function (resolve) {
|
798
894
|
|
799
|
-
|
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
|
-
|
803
|
-
|
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
|
-
|
814
|
-
var supportCors = 'withCredentials' in new XMLHttpRequest();
|
905
|
+
var status = 0;
|
815
906
|
|
816
|
-
|
817
|
-
|
907
|
+
if (type === 'load' && body !== null) {
|
908
|
+
status = 200;
|
909
|
+
} else if (type === 'error') {
|
910
|
+
status = 500;
|
911
|
+
}
|
818
912
|
|
819
|
-
|
820
|
-
_request.crossOrigin = crossOrigin(_request);
|
821
|
-
}
|
913
|
+
resolve(request.respondWith(body, { status: status }));
|
822
914
|
|
823
|
-
|
915
|
+
delete window[callback];
|
916
|
+
document.body.removeChild(script);
|
917
|
+
};
|
824
918
|
|
825
|
-
|
826
|
-
_request.client = xdrClient;
|
827
|
-
}
|
919
|
+
request.params[name] = callback;
|
828
920
|
|
829
|
-
|
830
|
-
|
921
|
+
window[callback] = function (result) {
|
922
|
+
body = JSON.stringify(result);
|
923
|
+
};
|
831
924
|
|
832
|
-
|
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
|
-
|
932
|
+
document.body.appendChild(script);
|
933
|
+
});
|
934
|
+
}
|
837
935
|
|
838
|
-
|
936
|
+
/**
|
937
|
+
* JSONP Interceptor.
|
938
|
+
*/
|
839
939
|
|
840
|
-
|
841
|
-
}
|
940
|
+
function jsonp (request, next) {
|
842
941
|
|
843
|
-
|
844
|
-
|
942
|
+
if (request.method == 'JSONP') {
|
943
|
+
request.client = jsonpClient;
|
944
|
+
}
|
845
945
|
|
846
|
-
|
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
|
-
|
852
|
-
delete _request.headers['Content-Type'];
|
853
|
-
}
|
948
|
+
if (request.method == 'JSONP') {
|
854
949
|
|
855
|
-
|
856
|
-
_request.data = JSON.stringify(_request.data);
|
857
|
-
}
|
950
|
+
return when(response.json(), function (json) {
|
858
951
|
|
859
|
-
|
860
|
-
},
|
861
|
-
response: function response(_response) {
|
952
|
+
response.body = json;
|
862
953
|
|
863
|
-
|
864
|
-
|
865
|
-
|
954
|
+
return response;
|
955
|
+
});
|
956
|
+
}
|
957
|
+
});
|
958
|
+
}
|
866
959
|
|
867
|
-
|
868
|
-
|
869
|
-
|
960
|
+
/**
|
961
|
+
* Before Interceptor.
|
962
|
+
*/
|
870
963
|
|
871
|
-
|
872
|
-
return new Promise$1(function (resolve) {
|
964
|
+
function before (request, next) {
|
873
965
|
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
script;
|
966
|
+
if (isFunction(request.before)) {
|
967
|
+
request.before.call(this, request);
|
968
|
+
}
|
878
969
|
|
879
|
-
|
880
|
-
|
881
|
-
handler({ type: 'cancel' });
|
882
|
-
};
|
970
|
+
next();
|
971
|
+
}
|
883
972
|
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
script.async = true;
|
973
|
+
/**
|
974
|
+
* HTTP method override Interceptor.
|
975
|
+
*/
|
888
976
|
|
889
|
-
|
890
|
-
response.data = data;
|
891
|
-
};
|
977
|
+
function method (request, next) {
|
892
978
|
|
893
|
-
|
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
|
-
|
896
|
-
|
897
|
-
} else if (event.type === 'error') {
|
898
|
-
response.status = 404;
|
899
|
-
} else {
|
900
|
-
response.status = 0;
|
901
|
-
}
|
984
|
+
next();
|
985
|
+
}
|
902
986
|
|
903
|
-
|
987
|
+
/**
|
988
|
+
* Header Interceptor.
|
989
|
+
*/
|
904
990
|
|
905
|
-
|
906
|
-
document.body.removeChild(script);
|
907
|
-
};
|
991
|
+
function header (request, next) {
|
908
992
|
|
909
|
-
|
910
|
-
script.onerror = handler;
|
993
|
+
var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]);
|
911
994
|
|
912
|
-
|
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
|
-
|
917
|
-
|
1001
|
+
next();
|
1002
|
+
}
|
918
1003
|
|
919
|
-
|
920
|
-
|
921
|
-
|
1004
|
+
/**
|
1005
|
+
* Timeout Interceptor.
|
1006
|
+
*/
|
922
1007
|
|
923
|
-
|
924
|
-
}
|
925
|
-
};
|
1008
|
+
function timeout (request, next) {
|
926
1009
|
|
927
|
-
|
928
|
-
request: function request(_request) {
|
1010
|
+
var timeout;
|
929
1011
|
|
930
|
-
|
931
|
-
|
932
|
-
|
1012
|
+
if (request.timeout) {
|
1013
|
+
timeout = setTimeout(function () {
|
1014
|
+
request.abort();
|
1015
|
+
}, request.timeout);
|
1016
|
+
}
|
933
1017
|
|
934
|
-
|
935
|
-
}
|
936
|
-
};
|
1018
|
+
next(function (response) {
|
937
1019
|
|
938
|
-
|
939
|
-
|
940
|
-
|
1020
|
+
clearTimeout(timeout);
|
1021
|
+
});
|
1022
|
+
}
|
941
1023
|
|
942
|
-
|
943
|
-
|
1024
|
+
/**
|
1025
|
+
* XMLHttp client.
|
1026
|
+
*/
|
944
1027
|
|
945
|
-
|
946
|
-
|
947
|
-
_request.method = 'POST';
|
948
|
-
}
|
1028
|
+
function xhrClient (request) {
|
1029
|
+
return new PromiseObj(function (resolve) {
|
949
1030
|
|
950
|
-
|
951
|
-
|
952
|
-
};
|
1031
|
+
var xhr = new XMLHttpRequest(),
|
1032
|
+
handler = function (event) {
|
953
1033
|
|
954
|
-
|
955
|
-
|
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
|
-
|
958
|
-
|
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
|
-
|
961
|
-
|
962
|
-
delete _request.data;
|
963
|
-
}
|
1043
|
+
resolve(response);
|
1044
|
+
};
|
964
1045
|
|
965
|
-
|
966
|
-
|
967
|
-
|
1046
|
+
request.abort = function () {
|
1047
|
+
return xhr.abort();
|
1048
|
+
};
|
968
1049
|
|
969
|
-
|
970
|
-
|
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
|
-
|
1058
|
+
xhr.open(request.method, request.getUrl(), true);
|
974
1059
|
|
975
|
-
|
1060
|
+
if ('responseType' in xhr) {
|
1061
|
+
xhr.responseType = 'blob';
|
1062
|
+
}
|
976
1063
|
|
977
|
-
|
978
|
-
|
1064
|
+
if (request.credentials === true) {
|
1065
|
+
xhr.withCredentials = true;
|
1066
|
+
}
|
979
1067
|
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
}, _request.timeout);
|
984
|
-
}
|
1068
|
+
request.headers.forEach(function (value, name) {
|
1069
|
+
xhr.setRequestHeader(name, value);
|
1070
|
+
});
|
985
1071
|
|
986
|
-
|
987
|
-
|
988
|
-
|
1072
|
+
xhr.timeout = 0;
|
1073
|
+
xhr.onload = handler;
|
1074
|
+
xhr.onerror = handler;
|
1075
|
+
xhr.send(request.getBody());
|
1076
|
+
});
|
1077
|
+
}
|
989
1078
|
|
990
|
-
|
1079
|
+
/**
|
1080
|
+
* Base client.
|
1081
|
+
*/
|
991
1082
|
|
992
|
-
|
993
|
-
}
|
994
|
-
};
|
995
|
-
};
|
1083
|
+
function Client (context) {
|
996
1084
|
|
997
|
-
|
1085
|
+
var reqHandlers = [sendRequest],
|
1086
|
+
resHandlers = [],
|
1087
|
+
handler;
|
998
1088
|
|
999
|
-
|
1089
|
+
if (!isObject(context)) {
|
1090
|
+
context = null;
|
1091
|
+
}
|
1000
1092
|
|
1001
|
-
|
1002
|
-
|
1003
|
-
}
|
1093
|
+
function Client(request) {
|
1094
|
+
return new PromiseObj(function (resolve) {
|
1004
1095
|
|
1005
|
-
|
1096
|
+
function exec() {
|
1006
1097
|
|
1007
|
-
|
1008
|
-
request = handler.request.call(vm, request);
|
1009
|
-
}
|
1098
|
+
handler = reqHandlers.pop();
|
1010
1099
|
|
1011
|
-
|
1012
|
-
|
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
|
-
|
1015
|
-
response = handler.response.call(vm, response);
|
1016
|
-
}
|
1108
|
+
function next(response) {
|
1017
1109
|
|
1018
|
-
|
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
|
-
|
1140
|
+
function sendRequest(request, resolve) {
|
1026
1141
|
|
1027
|
-
|
1142
|
+
var client = request.client || xhrClient;
|
1028
1143
|
|
1029
|
-
|
1030
|
-
|
1031
|
-
}
|
1144
|
+
resolve(client(request));
|
1145
|
+
}
|
1032
1146
|
|
1033
|
-
|
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
|
-
|
1037
|
-
|
1153
|
+
/**
|
1154
|
+
* HTTP Headers.
|
1155
|
+
*/
|
1038
1156
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1157
|
+
var Headers = function () {
|
1158
|
+
function Headers(headers) {
|
1159
|
+
var _this = this;
|
1042
1160
|
|
1043
|
-
|
1044
|
-
xhr.abort();
|
1045
|
-
};
|
1161
|
+
classCallCheck(this, Headers);
|
1046
1162
|
|
1047
|
-
xhr.open(request.method, Url(request), true);
|
1048
1163
|
|
1049
|
-
|
1164
|
+
this.map = {};
|
1050
1165
|
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1166
|
+
each(headers, function (value, name) {
|
1167
|
+
return _this.append(name, value);
|
1168
|
+
});
|
1169
|
+
}
|
1055
1170
|
|
1056
|
-
|
1057
|
-
|
1171
|
+
Headers.prototype.has = function has(name) {
|
1172
|
+
return getName(this.map, name) !== null;
|
1173
|
+
};
|
1058
1174
|
|
1059
|
-
|
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
|
-
|
1067
|
-
extend(xhr, request.xhr);
|
1068
|
-
}
|
1177
|
+
var list = this.map[getName(this.map, name)];
|
1069
1178
|
|
1070
|
-
|
1071
|
-
|
1072
|
-
}
|
1179
|
+
return list ? list[0] : null;
|
1180
|
+
};
|
1073
1181
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1182
|
+
Headers.prototype.getAll = function getAll(name) {
|
1183
|
+
return this.map[getName(this.map, name)] || [];
|
1184
|
+
};
|
1077
1185
|
|
1078
|
-
|
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
|
-
|
1190
|
+
Headers.prototype.append = function append(name, value) {
|
1083
1191
|
|
1084
|
-
|
1192
|
+
var list = this.getAll(name);
|
1085
1193
|
|
1086
|
-
|
1194
|
+
if (list.length) {
|
1195
|
+
list.push(trim(value));
|
1196
|
+
} else {
|
1197
|
+
this.set(name, value);
|
1198
|
+
}
|
1199
|
+
};
|
1087
1200
|
|
1088
|
-
|
1201
|
+
Headers.prototype.delete = function _delete(name) {
|
1202
|
+
delete this.map[getName(this.map, name)];
|
1203
|
+
};
|
1089
1204
|
|
1090
|
-
|
1205
|
+
Headers.prototype.forEach = function forEach(callback, thisArg) {
|
1206
|
+
var _this2 = this;
|
1091
1207
|
|
1092
|
-
|
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
|
-
|
1095
|
-
|
1096
|
-
}
|
1215
|
+
return Headers;
|
1216
|
+
}();
|
1097
1217
|
|
1098
|
-
|
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
|
-
|
1224
|
+
function normalizeName(name) {
|
1103
1225
|
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1226
|
+
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
|
1227
|
+
throw new TypeError('Invalid character in header field name');
|
1228
|
+
}
|
1107
1229
|
|
1108
|
-
|
1230
|
+
return trim(name);
|
1231
|
+
}
|
1109
1232
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
i;
|
1233
|
+
/**
|
1234
|
+
* HTTP Response.
|
1235
|
+
*/
|
1114
1236
|
|
1115
|
-
|
1116
|
-
|
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
|
-
|
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
|
-
|
1125
|
-
headers[name].push(value);
|
1126
|
-
} else {
|
1127
|
-
headers[name] = [headers[name], value];
|
1128
|
-
}
|
1129
|
-
} else {
|
1253
|
+
if (isString(body)) {
|
1130
1254
|
|
1131
|
-
|
1132
|
-
|
1133
|
-
});
|
1134
|
-
}
|
1255
|
+
this.bodyText = body;
|
1256
|
+
} else if (isBlob(body)) {
|
1135
1257
|
|
1136
|
-
|
1137
|
-
}
|
1258
|
+
this.bodyBlob = body;
|
1138
1259
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1260
|
+
if (isBlobText(body)) {
|
1261
|
+
this.bodyText = blobText(body);
|
1262
|
+
}
|
1263
|
+
}
|
1264
|
+
}
|
1142
1265
|
|
1143
|
-
|
1266
|
+
Response.prototype.blob = function blob() {
|
1267
|
+
return when(this.bodyBlob);
|
1268
|
+
};
|
1144
1269
|
|
1145
|
-
|
1270
|
+
Response.prototype.text = function text() {
|
1271
|
+
return when(this.bodyText);
|
1272
|
+
};
|
1146
1273
|
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1274
|
+
Response.prototype.json = function json() {
|
1275
|
+
return when(this.text(), function (text) {
|
1276
|
+
return JSON.parse(text);
|
1277
|
+
});
|
1278
|
+
};
|
1151
1279
|
|
1152
|
-
|
1153
|
-
|
1154
|
-
});
|
1280
|
+
return Response;
|
1281
|
+
}();
|
1155
1282
|
|
1156
|
-
|
1157
|
-
|
1158
|
-
promise = client(request).bind(self.$vm).then(function (response) {
|
1283
|
+
function blobText(body) {
|
1284
|
+
return new PromiseObj(function (resolve) {
|
1159
1285
|
|
1160
|
-
|
1161
|
-
}, function (response) {
|
1286
|
+
var reader = new FileReader();
|
1162
1287
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1288
|
+
reader.readAsText(body);
|
1289
|
+
reader.onload = function () {
|
1290
|
+
resolve(reader.result);
|
1291
|
+
};
|
1292
|
+
});
|
1293
|
+
}
|
1166
1294
|
|
1167
|
-
|
1168
|
-
|
1295
|
+
function isBlobText(body) {
|
1296
|
+
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1;
|
1297
|
+
}
|
1169
1298
|
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1299
|
+
/**
|
1300
|
+
* HTTP Request.
|
1301
|
+
*/
|
1173
1302
|
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1303
|
+
var Request = function () {
|
1304
|
+
function Request(options) {
|
1305
|
+
classCallCheck(this, Request);
|
1177
1306
|
|
1178
|
-
return promise;
|
1179
|
-
}
|
1180
1307
|
|
1181
|
-
|
1182
|
-
|
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
|
-
|
1197
|
-
|
1198
|
-
|
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
|
-
|
1315
|
+
if (!(this.headers instanceof Headers)) {
|
1316
|
+
this.headers = new Headers(this.headers);
|
1317
|
+
}
|
1318
|
+
}
|
1206
1319
|
|
1207
|
-
|
1320
|
+
Request.prototype.getUrl = function getUrl() {
|
1321
|
+
return Url(this);
|
1322
|
+
};
|
1208
1323
|
|
1209
|
-
|
1324
|
+
Request.prototype.getBody = function getBody() {
|
1325
|
+
return this.body;
|
1326
|
+
};
|
1210
1327
|
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
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
|
-
|
1218
|
-
|
1219
|
-
success = undefined;
|
1220
|
-
}
|
1332
|
+
return Request;
|
1333
|
+
}();
|
1221
1334
|
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1335
|
+
/**
|
1336
|
+
* Service for sending network requests.
|
1337
|
+
*/
|
1225
1338
|
|
1226
|
-
|
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
|
-
|
1229
|
-
resource = {};
|
1343
|
+
function Http(options) {
|
1230
1344
|
|
1231
|
-
|
1345
|
+
var self = this || {},
|
1346
|
+
client = Client(self.$vm);
|
1232
1347
|
|
1233
|
-
|
1348
|
+
defaults(options || {}, self.$options, Http.options);
|
1234
1349
|
|
1235
|
-
|
1350
|
+
Http.interceptors.forEach(function (handler) {
|
1351
|
+
client.use(handler);
|
1352
|
+
});
|
1236
1353
|
|
1237
|
-
|
1238
|
-
return (self.$http || Http)(opts(action, arguments));
|
1239
|
-
};
|
1240
|
-
});
|
1354
|
+
return client(new Request(options)).then(function (response) {
|
1241
1355
|
|
1242
|
-
|
1243
|
-
|
1356
|
+
return response.ok ? response : PromiseObj.reject(response);
|
1357
|
+
}, function (response) {
|
1244
1358
|
|
1245
|
-
|
1359
|
+
if (response instanceof Error) {
|
1360
|
+
error(response);
|
1361
|
+
}
|
1246
1362
|
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
success,
|
1251
|
-
error;
|
1363
|
+
return PromiseObj.reject(response);
|
1364
|
+
});
|
1365
|
+
}
|
1252
1366
|
|
1253
|
-
|
1367
|
+
Http.options = {};
|
1254
1368
|
|
1255
|
-
|
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
|
-
|
1258
|
-
success = args[2];
|
1378
|
+
Http.interceptors = [before, timeout, method, body, jsonp, header, cors];
|
1259
1379
|
|
1260
|
-
|
1261
|
-
case 2:
|
1380
|
+
['get', 'delete', 'head', 'jsonp'].forEach(function (method) {
|
1262
1381
|
|
1263
|
-
|
1382
|
+
Http[method] = function (url, options) {
|
1383
|
+
return this(assign(options || {}, { url: url, method: method }));
|
1384
|
+
};
|
1385
|
+
});
|
1264
1386
|
|
1265
|
-
|
1387
|
+
['post', 'put', 'patch'].forEach(function (method) {
|
1266
1388
|
|
1267
|
-
|
1268
|
-
|
1389
|
+
Http[method] = function (url, body, options) {
|
1390
|
+
return this(assign(options || {}, { url: url, method: method, body: body }));
|
1391
|
+
};
|
1392
|
+
});
|
1269
1393
|
|
1270
|
-
|
1271
|
-
|
1394
|
+
/**
|
1395
|
+
* Service for interacting with RESTful services.
|
1396
|
+
*/
|
1272
1397
|
|
1273
|
-
|
1274
|
-
error = args[2];
|
1275
|
-
} else {
|
1398
|
+
function Resource(url, params, actions, options) {
|
1276
1399
|
|
1277
|
-
|
1278
|
-
|
1279
|
-
success = args[2];
|
1400
|
+
var self = this || {},
|
1401
|
+
resource = {};
|
1280
1402
|
|
1281
|
-
|
1282
|
-
}
|
1403
|
+
actions = assign({}, Resource.actions, actions);
|
1283
1404
|
|
1284
|
-
|
1405
|
+
each(actions, function (action, name) {
|
1285
1406
|
|
1286
|
-
|
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
|
-
|
1409
|
+
resource[name] = function () {
|
1410
|
+
return (self.$http || Http)(opts(action, arguments));
|
1411
|
+
};
|
1412
|
+
});
|
1295
1413
|
|
1296
|
-
|
1414
|
+
return resource;
|
1415
|
+
}
|
1297
1416
|
|
1298
|
-
|
1417
|
+
function opts(action, args) {
|
1299
1418
|
|
1300
|
-
|
1419
|
+
var options = assign({}, action),
|
1420
|
+
params = {},
|
1421
|
+
body;
|
1301
1422
|
|
1302
|
-
|
1303
|
-
}
|
1423
|
+
switch (args.length) {
|
1304
1424
|
|
1305
|
-
|
1306
|
-
options.params = extend({}, options.params, params);
|
1425
|
+
case 2:
|
1307
1426
|
|
1308
|
-
|
1309
|
-
|
1310
|
-
}
|
1427
|
+
params = args[0];
|
1428
|
+
body = args[1];
|
1311
1429
|
|
1312
|
-
|
1313
|
-
options.error = error;
|
1314
|
-
}
|
1430
|
+
break;
|
1315
1431
|
|
1316
|
-
|
1317
|
-
}
|
1432
|
+
case 1:
|
1318
1433
|
|
1319
|
-
|
1434
|
+
if (/^(POST|PUT|PATCH)$/i.test(options.method)) {
|
1435
|
+
body = args[0];
|
1436
|
+
} else {
|
1437
|
+
params = args[0];
|
1438
|
+
}
|
1320
1439
|
|
1321
|
-
|
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
|
-
|
1444
|
+
break;
|
1331
1445
|
|
1332
|
-
|
1333
|
-
return;
|
1334
|
-
}
|
1446
|
+
default:
|
1335
1447
|
|
1336
|
-
|
1448
|
+
throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments';
|
1449
|
+
}
|
1337
1450
|
|
1338
|
-
|
1339
|
-
|
1340
|
-
Vue.resource = Resource;
|
1341
|
-
Vue.Promise = Promise$1;
|
1451
|
+
options.body = body;
|
1452
|
+
options.params = assign({}, options.params, params);
|
1342
1453
|
|
1343
|
-
|
1454
|
+
return options;
|
1455
|
+
}
|
1344
1456
|
|
1345
|
-
|
1346
|
-
get: function get() {
|
1347
|
-
return options(Vue.url, this, this.$options.url);
|
1348
|
-
}
|
1349
|
-
},
|
1457
|
+
Resource.actions = {
|
1350
1458
|
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
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
|
-
|
1358
|
-
get: function get() {
|
1359
|
-
return Vue.resource.bind(this);
|
1360
|
-
}
|
1361
|
-
},
|
1466
|
+
};
|
1362
1467
|
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1468
|
+
/**
|
1469
|
+
* Install plugin.
|
1470
|
+
*/
|
1366
1471
|
|
1367
|
-
|
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
|
-
|
1377
|
-
|
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
|
-
|
1522
|
+
return plugin;
|
1381
1523
|
|
1382
|
-
}));
|
1524
|
+
})));
|