PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / js / vendor / vue / vue-resource.js

vue-resource.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.1, at assets/src/js/vendor/vue/vue-resource.js

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