Commit 9accca43 authored by Phil Hughes's avatar Phil Hughes

Unminified versions of vue & vue-resource

parent c51cbc1f
...@@ -10,8 +10,11 @@ ...@@ -10,8 +10,11 @@
}, },
computed: { computed: {
allResolved: function () { allResolved: function () {
const discussion = this.discussions[discussionId]; const discussion = this.discussions[this.discussionId];
if (discussion) {
return discussion.isResolved(); return discussion.isResolved();
}
}, },
discussionsCount: function () { discussionsCount: function () {
return CommentsStore.discussionCount(); return CommentsStore.discussionCount();
......
...@@ -4,4 +4,1315 @@ ...@@ -4,4 +4,1315 @@
* Released under the MIT License. * Released under the MIT License.
*/ */
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.VueResource=n()}(this,function(){"use strict";function t(t){this.state=Z,this.value=void 0,this.deferred=[];var n=this;try{t(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(e){n.reject(e)}}function n(t,n){t instanceof nt?this.promise=t:this.promise=new nt(t.bind(n)),this.context=n}function e(t){rt=t.util,ot=t.config.debug||!t.config.silent}function o(t){"undefined"!=typeof console&&ot&&console.warn("[VueResource warn]: "+t)}function r(t){"undefined"!=typeof console&&console.error(t)}function i(t,n){return rt.nextTick(t,n)}function u(t){return t.replace(/^\s*|\s*$/g,"")}function s(t){return"string"==typeof t}function c(t){return t===!0||t===!1}function a(t){return"function"==typeof t}function f(t){return null!==t&&"object"==typeof t}function h(t){return f(t)&&Object.getPrototypeOf(t)==Object.prototype}function p(t){return"undefined"!=typeof FormData&&t instanceof FormData}function l(t,e,o){var r=n.resolve(t);return arguments.length<2?r:r.then(e,o)}function d(t,n,e){return e=e||{},a(e)&&(e=e.call(n)),v(t.bind({$vm:n,$options:e}),t,{$options:e})}function m(t,n){var e,o;if("number"==typeof t.length)for(e=0;e<t.length;e++)n.call(t[e],t[e],e);else if(f(t))for(o in t)t.hasOwnProperty(o)&&n.call(t[o],t[o],o);return t}function v(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){g(t,n,!0)}),t}function y(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){for(var e in n)void 0===t[e]&&(t[e]=n[e])}),t}function b(t){var n=it.slice.call(arguments,1);return n.forEach(function(n){g(t,n)}),t}function g(t,n,e){for(var o in n)e&&(h(n[o])||ut(n[o]))?(h(n[o])&&!h(t[o])&&(t[o]={}),ut(n[o])&&!ut(t[o])&&(t[o]=[]),g(t[o],n[o],e)):void 0!==n[o]&&(t[o]=n[o])}function w(t,n){var e=n(t);return s(t.root)&&!e.match(/^(https?:)?\//)&&(e=t.root+"/"+e),e}function T(t,n){var e=Object.keys(R.options.params),o={},r=n(t);return m(t.params,function(t,n){e.indexOf(n)===-1&&(o[n]=t)}),o=R.params(o),o&&(r+=(r.indexOf("?")==-1?"?":"&")+o),r}function j(t,n,e){var o=E(t),r=o.expand(n);return e&&e.push.apply(e,o.vars),r}function E(t){var n=["+","#",".","/",";","?","&"],e=[];return{vars:e,expand:function(o){return t.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g,function(t,r,i){if(r){var u=null,s=[];if(n.indexOf(r.charAt(0))!==-1&&(u=r.charAt(0),r=r.substr(1)),r.split(/,/g).forEach(function(t){var n=/([^:\*]*)(?::(\d+)|(\*))?/.exec(t);s.push.apply(s,x(o,u,n[1],n[2]||n[3])),e.push(n[1])}),u&&"+"!==u){var c=",";return"?"===u?c="&":"#"!==u&&(c=u),(0!==s.length?u:"")+s.join(c)}return s.join(",")}return $(i)})}}}function x(t,n,e,o){var r=t[e],i=[];if(O(r)&&""!==r)if("string"==typeof r||"number"==typeof r||"boolean"==typeof r)r=r.toString(),o&&"*"!==o&&(r=r.substring(0,parseInt(o,10))),i.push(C(n,r,P(n)?e:null));else if("*"===o)Array.isArray(r)?r.filter(O).forEach(function(t){i.push(C(n,t,P(n)?e:null))}):Object.keys(r).forEach(function(t){O(r[t])&&i.push(C(n,r[t],t))});else{var u=[];Array.isArray(r)?r.filter(O).forEach(function(t){u.push(C(n,t))}):Object.keys(r).forEach(function(t){O(r[t])&&(u.push(encodeURIComponent(t)),u.push(C(n,r[t].toString())))}),P(n)?i.push(encodeURIComponent(e)+"="+u.join(",")):0!==u.length&&i.push(u.join(","))}else";"===n?i.push(encodeURIComponent(e)):""!==r||"&"!==n&&"?"!==n?""===r&&i.push(""):i.push(encodeURIComponent(e)+"=");return i}function O(t){return void 0!==t&&null!==t}function P(t){return";"===t||"&"===t||"?"===t}function C(t,n,e){return n="+"===t||"#"===t?$(n):encodeURIComponent(n),e?encodeURIComponent(e)+"="+n:n}function $(t){return t.split(/(%[0-9A-Fa-f]{2})/g).map(function(t){return/%[0-9A-Fa-f]/.test(t)||(t=encodeURI(t)),t}).join("")}function U(t){var n=[],e=j(t.url,t.params,n);return n.forEach(function(n){delete t.params[n]}),e}function R(t,n){var e,o=this||{},r=t;return s(t)&&(r={url:t,params:n}),r=v({},R.options,o.$options,r),R.transforms.forEach(function(t){e=A(t,e,o.$vm)}),e(r)}function A(t,n,e){return function(o){return t.call(e,o,n)}}function S(t,n,e){var o,r=ut(n),i=h(n);m(n,function(n,u){o=f(n)||ut(n),e&&(u=e+"["+(i||o?u:"")+"]"),!e&&r?t.add(n.name,n.value):o?S(t,n,u):t.add(u,n)})}function k(t){return new n(function(n){var e=new XDomainRequest,o=function(o){var r=t.respondWith(e.responseText,{status:e.status,statusText:e.statusText});n(r)};t.abort=function(){return e.abort()},e.open(t.method,t.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,e.ontimeout=function(){},e.onprogress=function(){},e.send(t.getBody())})}function H(t,n){!c(t.crossOrigin)&&I(t)&&(t.crossOrigin=!0),t.crossOrigin&&(ht||(t.client=k),delete t.emulateHTTP),n()}function I(t){var n=R.parse(R(t));return n.protocol!==ft.protocol||n.host!==ft.host}function L(t,n){t.emulateJSON&&h(t.body)&&(t.body=R.params(t.body),t.headers["Content-Type"]="application/x-www-form-urlencoded"),p(t.body)&&delete t.headers["Content-Type"],h(t.body)&&(t.body=JSON.stringify(t.body)),n(function(t){var n=t.headers["Content-Type"];if(s(n)&&0===n.indexOf("application/json"))try{t.data=t.json()}catch(e){t.data=null}else t.data=t.text()})}function q(t){return new n(function(n){var e,o,r=t.jsonp||"callback",i="_jsonp"+Math.random().toString(36).substr(2),u=null;e=function(e){var r=0;"load"===e.type&&null!==u?r=200:"error"===e.type&&(r=404),n(t.respondWith(u,{status:r})),delete window[i],document.body.removeChild(o)},t.params[r]=i,window[i]=function(t){u=JSON.stringify(t)},o=document.createElement("script"),o.src=t.getUrl(),o.type="text/javascript",o.async=!0,o.onload=e,o.onerror=e,document.body.appendChild(o)})}function N(t,n){"JSONP"==t.method&&(t.client=q),n(function(n){"JSONP"==t.method&&(n.data=n.json())})}function D(t,n){a(t.before)&&t.before.call(this,t),n()}function J(t,n){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers["X-HTTP-Method-Override"]=t.method,t.method="POST"),n()}function M(t,n){t.method=t.method.toUpperCase(),t.headers=st({},V.headers.common,t.crossOrigin?{}:V.headers.custom,V.headers[t.method.toLowerCase()],t.headers),n()}function X(t,n){var e;t.timeout&&(e=setTimeout(function(){t.abort()},t.timeout)),n(function(t){clearTimeout(e)})}function W(t){return new n(function(n){var e=new XMLHttpRequest,o=function(o){var r=t.respondWith("response"in e?e.response:e.responseText,{status:1223===e.status?204:e.status,statusText:1223===e.status?"No Content":u(e.statusText),headers:B(e.getAllResponseHeaders())});n(r)};t.abort=function(){return e.abort()},e.open(t.method,t.getUrl(),!0),e.timeout=0,e.onload=o,e.onerror=o,t.progress&&("GET"===t.method?e.addEventListener("progress",t.progress):/^(POST|PUT)$/i.test(t.method)&&e.upload.addEventListener("progress",t.progress)),t.credentials===!0&&(e.withCredentials=!0),m(t.headers||{},function(t,n){e.setRequestHeader(n,t)}),e.send(t.getBody())})}function B(t){var n,e,o,r={};return m(u(t).split("\n"),function(t){o=t.indexOf(":"),e=u(t.slice(0,o)),n=u(t.slice(o+1)),r[e]?ut(r[e])?r[e].push(n):r[e]=[r[e],n]:r[e]=n}),r}function F(t){function e(e){return new n(function(n){function s(){r=i.pop(),a(r)?r.call(t,e,c):(o("Invalid interceptor of type "+typeof r+", must be a function"),c())}function c(e){if(a(e))u.unshift(e);else if(f(e))return u.forEach(function(n){e=l(e,function(e){return n.call(t,e)||e})}),void l(e,n);s()}s()},t)}var r,i=[G],u=[];return f(t)||(t=null),e.use=function(t){i.push(t)},e}function G(t,n){var e=t.client||W;n(e(t))}function V(t){var e=this||{},o=F(e.$vm);return y(t||{},e.$options,V.options),V.interceptors.forEach(function(t){o.use(t)}),o(new dt(t)).then(function(t){return t.ok?t:n.reject(t)},function(t){return t instanceof Error&&r(t),n.reject(t)})}function _(t,n,e,o){var r=this||{},i={};return e=st({},_.actions,e),m(e,function(e,u){e=v({url:t,params:n||{}},o,e),i[u]=function(){return(r.$http||V)(z(e,arguments))}}),i}function z(t,n){var e,o=st({},t),r={};switch(n.length){case 2:r=n[0],e=n[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?e=n[0]:r=n[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, body], got "+n.length+" arguments"}return o.body=e,o.params=st({},o.params,r),o}function K(t){K.installed||(e(t),t.url=R,t.http=V,t.resource=_,t.Promise=n,Object.defineProperties(t.prototype,{$url:{get:function(){return d(t.url,this,this.$options.url)}},$http:{get:function(){return d(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var n=this;return function(e){return new t.Promise(e,n)}}}}))}var Q=0,Y=1,Z=2;t.reject=function(n){return new t(function(t,e){e(n)})},t.resolve=function(n){return new t(function(t,e){t(n)})},t.all=function(n){return new t(function(e,o){function r(t){return function(o){u[t]=o,i+=1,i===n.length&&e(u)}}var i=0,u=[];0===n.length&&e(u);for(var s=0;s<n.length;s+=1)t.resolve(n[s]).then(r(s),o)})},t.race=function(n){return new t(function(e,o){for(var r=0;r<n.length;r+=1)t.resolve(n[r]).then(e,o)})};var tt=t.prototype;tt.resolve=function(t){var n=this;if(n.state===Z){if(t===n)throw new TypeError("Promise settled with itself.");var e=!1;try{var o=t&&t.then;if(null!==t&&"object"==typeof t&&"function"==typeof o)return void o.call(t,function(t){e||n.resolve(t),e=!0},function(t){e||n.reject(t),e=!0})}catch(r){return void(e||n.reject(r))}n.state=Q,n.value=t,n.notify()}},tt.reject=function(t){var n=this;if(n.state===Z){if(t===n)throw new TypeError("Promise settled with itself.");n.state=Y,n.value=t,n.notify()}},tt.notify=function(){var t=this;i(function(){if(t.state!==Z)for(;t.deferred.length;){var n=t.deferred.shift(),e=n[0],o=n[1],r=n[2],i=n[3];try{t.state===Q?r("function"==typeof e?e.call(void 0,t.value):t.value):t.state===Y&&("function"==typeof o?r(o.call(void 0,t.value)):i(t.value))}catch(u){i(u)}}})},tt.then=function(n,e){var o=this;return new t(function(t,r){o.deferred.push([n,e,t,r]),o.notify()})},tt["catch"]=function(t){return this.then(void 0,t)};var nt=window.Promise||t;n.all=function(t,e){return new n(nt.all(t),e)},n.resolve=function(t,e){return new n(nt.resolve(t),e)},n.reject=function(t,e){return new n(nt.reject(t),e)},n.race=function(t,e){return new n(nt.race(t),e)};var et=n.prototype;et.bind=function(t){return this.context=t,this},et.then=function(t,e){return t&&t.bind&&this.context&&(t=t.bind(this.context)),e&&e.bind&&this.context&&(e=e.bind(this.context)),new n(this.promise.then(t,e),this.context)},et["catch"]=function(t){return t&&t.bind&&this.context&&(t=t.bind(this.context)),new n(this.promise["catch"](t),this.context)},et["finally"]=function(t){return this.then(function(n){return t.call(this),n},function(n){return t.call(this),nt.reject(n)})};var ot=!1,rt={},it=[],ut=Array.isArray,st=Object.assign||b,ct=document.documentMode,at=document.createElement("a");R.options={url:"",root:null,params:{}},R.transforms=[U,T,w],R.params=function(t){var n=[],e=encodeURIComponent;return n.add=function(t,n){a(n)&&(n=n()),null===n&&(n=""),this.push(e(t)+"="+e(n))},S(n,t),n.join("&").replace(/%20/g,"+")},R.parse=function(t){return ct&&(at.href=t,t=at.href),at.href=t,{href:at.href,protocol:at.protocol?at.protocol.replace(/:$/,""):"",port:at.port,host:at.host,hostname:at.hostname,pathname:"/"===at.pathname.charAt(0)?at.pathname:"/"+at.pathname,search:at.search?at.search.replace(/^\?/,""):"",hash:at.hash?at.hash.replace(/^#/,""):""}};var ft=R.parse(location.href),ht="withCredentials"in new XMLHttpRequest,pt=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt=function(){function t(n,e){var o=e.url,r=e.headers,i=e.status,u=e.statusText;pt(this,t),this.url=o,this.body=n,this.headers=r||{},this.status=i||0,this.statusText=u||"",this.ok=i>=200&&i<300}return t.prototype.text=function(){return this.body},t.prototype.blob=function(){return new Blob([this.body])},t.prototype.json=function(){return JSON.parse(this.body)},t}(),dt=function(){function t(n){pt(this,t),this.method="GET",this.body=null,this.params={},this.headers={},st(this,n)}return t.prototype.getUrl=function(){return R(this)},t.prototype.getBody=function(){return this.body},t.prototype.respondWith=function(t,n){return new lt(t,st(n||{},{url:this.getUrl()}))},t}(),mt={"X-Requested-With":"XMLHttpRequest"},vt={Accept:"application/json, text/plain, */*"},yt={"Content-Type":"application/json;charset=utf-8"};return V.options={},V.headers={put:yt,post:yt,patch:yt,"delete":yt,custom:mt,common:vt},V.interceptors=[D,X,J,L,N,M,H],["get","delete","head","jsonp"].forEach(function(t){V[t]=function(n,e){return this(st(e||{},{url:n,method:t}))}}),["post","put","patch"].forEach(function(t){V[t]=function(n,e,o){return this(st(o||{},{url:n,method:t,body:e}))}}),_.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(K),K}); (function (global, factory) {
\ No newline at end of file typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.VueResource = factory());
}(this, function () { 'use strict';
/**
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
*/
var RESOLVED = 0;
var REJECTED = 1;
var PENDING = 2;
function Promise$2(executor) {
this.state = PENDING;
this.value = undefined;
this.deferred = [];
var promise = this;
try {
executor(function (x) {
promise.resolve(x);
}, function (r) {
promise.reject(r);
});
} catch (e) {
promise.reject(e);
}
}
Promise$2.reject = function (r) {
return new Promise$2(function (resolve, reject) {
reject(r);
});
};
Promise$2.resolve = function (x) {
return new Promise$2(function (resolve, reject) {
resolve(x);
});
};
Promise$2.all = function all(iterable) {
return new Promise$2(function (resolve, reject) {
var count = 0,
result = [];
if (iterable.length === 0) {
resolve(result);
}
function resolver(i) {
return function (x) {
result[i] = x;
count += 1;
if (count === iterable.length) {
resolve(result);
}
};
}
for (var i = 0; i < iterable.length; i += 1) {
Promise$2.resolve(iterable[i]).then(resolver(i), reject);
}
});
};
Promise$2.race = function race(iterable) {
return new Promise$2(function (resolve, reject) {
for (var i = 0; i < iterable.length; i += 1) {
Promise$2.resolve(iterable[i]).then(resolve, reject);
}
});
};
var p$1 = Promise$2.prototype;
p$1.resolve = function resolve(x) {
var promise = this;
if (promise.state === PENDING) {
if (x === promise) {
throw new TypeError('Promise settled with itself.');
}
var called = false;
try {
var then = x && x['then'];
if (x !== null && typeof x === 'object' && typeof then === 'function') {
then.call(x, function (x) {
if (!called) {
promise.resolve(x);
}
called = true;
}, function (r) {
if (!called) {
promise.reject(r);
}
called = true;
});
return;
}
} catch (e) {
if (!called) {
promise.reject(e);
}
return;
}
promise.state = RESOLVED;
promise.value = x;
promise.notify();
}
};
p$1.reject = function reject(reason) {
var promise = this;
if (promise.state === PENDING) {
if (reason === promise) {
throw new TypeError('Promise settled with itself.');
}
promise.state = REJECTED;
promise.value = reason;
promise.notify();
}
};
p$1.notify = function notify() {
var promise = this;
nextTick(function () {
if (promise.state !== PENDING) {
while (promise.deferred.length) {
var deferred = promise.deferred.shift(),
onResolved = deferred[0],
onRejected = deferred[1],
resolve = deferred[2],
reject = deferred[3];
try {
if (promise.state === RESOLVED) {
if (typeof onResolved === 'function') {
resolve(onResolved.call(undefined, promise.value));
} else {
resolve(promise.value);
}
} else if (promise.state === REJECTED) {
if (typeof onRejected === 'function') {
resolve(onRejected.call(undefined, promise.value));
} else {
reject(promise.value);
}
}
} catch (e) {
reject(e);
}
}
}
});
};
p$1.then = function then(onResolved, onRejected) {
var promise = this;
return new Promise$2(function (resolve, reject) {
promise.deferred.push([onResolved, onRejected, resolve, reject]);
promise.notify();
});
};
p$1.catch = function (onRejected) {
return this.then(undefined, onRejected);
};
var PromiseObj = window.Promise || Promise$2;
function Promise$1(executor, context) {
if (executor instanceof PromiseObj) {
this.promise = executor;
} else {
this.promise = new PromiseObj(executor.bind(context));
}
this.context = context;
}
Promise$1.all = function (iterable, context) {
return new Promise$1(PromiseObj.all(iterable), context);
};
Promise$1.resolve = function (value, context) {
return new Promise$1(PromiseObj.resolve(value), context);
};
Promise$1.reject = function (reason, context) {
return new Promise$1(PromiseObj.reject(reason), context);
};
Promise$1.race = function (iterable, context) {
return new Promise$1(PromiseObj.race(iterable), context);
};
var p = Promise$1.prototype;
p.bind = function (context) {
this.context = context;
return this;
};
p.then = function (fulfilled, rejected) {
if (fulfilled && fulfilled.bind && this.context) {
fulfilled = fulfilled.bind(this.context);
}
if (rejected && rejected.bind && this.context) {
rejected = rejected.bind(this.context);
}
return new Promise$1(this.promise.then(fulfilled, rejected), this.context);
};
p.catch = function (rejected) {
if (rejected && rejected.bind && this.context) {
rejected = rejected.bind(this.context);
}
return new Promise$1(this.promise.catch(rejected), this.context);
};
p.finally = function (callback) {
return this.then(function (value) {
callback.call(this);
return value;
}, function (reason) {
callback.call(this);
return PromiseObj.reject(reason);
});
};
var debug = false;
var util = {};
var array = [];
function Util (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;
}
function warn(msg) {
if (typeof console !== 'undefined' && debug) {
console.warn('[VueResource warn]: ' + msg);
}
}
function error(msg) {
if (typeof console !== 'undefined') {
console.error(msg);
}
}
function nextTick(cb, ctx) {
return util.nextTick(cb, ctx);
}
function trim(str) {
return str.replace(/^\s*|\s*$/g, '');
}
var isArray = Array.isArray;
function isString(val) {
return typeof val === 'string';
}
function isBoolean(val) {
return val === true || val === false;
}
function isFunction(val) {
return typeof val === 'function';
}
function isObject(obj) {
return obj !== null && typeof obj === 'object';
}
function isPlainObject(obj) {
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
}
function isFormData(obj) {
return typeof FormData !== 'undefined' && obj instanceof FormData;
}
function when(value, fulfilled, rejected) {
var promise = Promise$1.resolve(value);
if (arguments.length < 2) {
return promise;
}
return promise.then(fulfilled, rejected);
}
function options(fn, obj, opts) {
opts = opts || {};
if (isFunction(opts)) {
opts = opts.call(obj);
}
return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
}
function each(obj, iterator) {
var i, key;
if (typeof obj.length == 'number') {
for (i = 0; i < obj.length; i++) {
iterator.call(obj[i], obj[i], i);
}
} else if (isObject(obj)) {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
iterator.call(obj[key], obj[key], key);
}
}
}
return obj;
}
var assign = Object.assign || _assign;
function merge(target) {
var args = array.slice.call(arguments, 1);
args.forEach(function (source) {
_merge(target, source, true);
});
return target;
}
function defaults(target) {
var args = array.slice.call(arguments, 1);
args.forEach(function (source) {
for (var key in source) {
if (target[key] === undefined) {
target[key] = source[key];
}
}
});
return target;
}
function _assign(target) {
var args = array.slice.call(arguments, 1);
args.forEach(function (source) {
_merge(target, source);
});
return target;
}
function _merge(target, source, deep) {
for (var key in source) {
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
target[key] = {};
}
if (isArray(source[key]) && !isArray(target[key])) {
target[key] = [];
}
_merge(target[key], source[key], deep);
} else if (source[key] !== undefined) {
target[key] = source[key];
}
}
}
function root (options, next) {
var url = next(options);
if (isString(options.root) && !url.match(/^(https?:)?\//)) {
url = options.root + '/' + url;
}
return url;
}
function query (options, next) {
var urlParams = Object.keys(Url.options.params),
query = {},
url = next(options);
each(options.params, function (value, key) {
if (urlParams.indexOf(key) === -1) {
query[key] = value;
}
});
query = Url.params(query);
if (query) {
url += (url.indexOf('?') == -1 ? '?' : '&') + query;
}
return url;
}
/**
* URL Template v2.0.6 (https://github.com/bramstein/url-template)
*/
function expand(url, params, variables) {
var tmpl = parse(url),
expanded = tmpl.expand(params);
if (variables) {
variables.push.apply(variables, tmpl.vars);
}
return expanded;
}
function parse(template) {
var operators = ['+', '#', '.', '/', ';', '?', '&'],
variables = [];
return {
vars: variables,
expand: function (context) {
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
if (expression) {
var operator = null,
values = [];
if (operators.indexOf(expression.charAt(0)) !== -1) {
operator = expression.charAt(0);
expression = expression.substr(1);
}
expression.split(/,/g).forEach(function (variable) {
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
variables.push(tmp[1]);
});
if (operator && operator !== '+') {
var separator = ',';
if (operator === '?') {
separator = '&';
} else if (operator !== '#') {
separator = operator;
}
return (values.length !== 0 ? operator : '') + values.join(separator);
} else {
return values.join(',');
}
} else {
return encodeReserved(literal);
}
});
}
};
}
function getValues(context, operator, key, modifier) {
var value = context[key],
result = [];
if (isDefined(value) && value !== '') {
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
value = value.toString();
if (modifier && modifier !== '*') {
value = value.substring(0, parseInt(modifier, 10));
}
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
} else {
if (modifier === '*') {
if (Array.isArray(value)) {
value.filter(isDefined).forEach(function (value) {
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
});
} else {
Object.keys(value).forEach(function (k) {
if (isDefined(value[k])) {
result.push(encodeValue(operator, value[k], k));
}
});
}
} else {
var tmp = [];
if (Array.isArray(value)) {
value.filter(isDefined).forEach(function (value) {
tmp.push(encodeValue(operator, value));
});
} else {
Object.keys(value).forEach(function (k) {
if (isDefined(value[k])) {
tmp.push(encodeURIComponent(k));
tmp.push(encodeValue(operator, value[k].toString()));
}
});
}
if (isKeyOperator(operator)) {
result.push(encodeURIComponent(key) + '=' + tmp.join(','));
} else if (tmp.length !== 0) {
result.push(tmp.join(','));
}
}
}
} else {
if (operator === ';') {
result.push(encodeURIComponent(key));
} else if (value === '' && (operator === '&' || operator === '?')) {
result.push(encodeURIComponent(key) + '=');
} else if (value === '') {
result.push('');
}
}
return result;
}
function isDefined(value) {
return value !== undefined && value !== null;
}
function isKeyOperator(operator) {
return operator === ';' || operator === '&' || operator === '?';
}
function encodeValue(operator, value, key) {
value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value);
if (key) {
return encodeURIComponent(key) + '=' + value;
} else {
return value;
}
}
function encodeReserved(str) {
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
if (!/%[0-9A-Fa-f]/.test(part)) {
part = encodeURI(part);
}
return part;
}).join('');
}
function template (options) {
var variables = [],
url = expand(options.url, options.params, variables);
variables.forEach(function (key) {
delete options.params[key];
});
return url;
}
/**
* Service for URL templating.
*/
var ie = document.documentMode;
var el = document.createElement('a');
function Url(url, params) {
var self = this || {},
options = url,
transform;
if (isString(url)) {
options = { url: url, params: params };
}
options = merge({}, Url.options, self.$options, options);
Url.transforms.forEach(function (handler) {
transform = factory(handler, transform, self.$vm);
});
return transform(options);
}
/**
* Url options.
*/
Url.options = {
url: '',
root: null,
params: {}
};
/**
* Url transforms.
*/
Url.transforms = [template, query, root];
/**
* Encodes a Url parameter string.
*
* @param {Object} obj
*/
Url.params = function (obj) {
var params = [],
escape = encodeURIComponent;
params.add = function (key, value) {
if (isFunction(value)) {
value = value();
}
if (value === null) {
value = '';
}
this.push(escape(key) + '=' + escape(value));
};
serialize(params, obj);
return params.join('&').replace(/%20/g, '+');
};
/**
* Parse a URL and return its components.
*
* @param {String} url
*/
Url.parse = function (url) {
if (ie) {
el.href = url;
url = el.href;
}
el.href = url;
return {
href: el.href,
protocol: el.protocol ? el.protocol.replace(/:$/, '') : '',
port: el.port,
host: el.host,
hostname: el.hostname,
pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname,
search: el.search ? el.search.replace(/^\?/, '') : '',
hash: el.hash ? el.hash.replace(/^#/, '') : ''
};
};
function factory(handler, next, vm) {
return function (options) {
return handler.call(vm, options, next);
};
}
function serialize(params, obj, scope) {
var array = isArray(obj),
plain = isPlainObject(obj),
hash;
each(obj, function (value, key) {
hash = isObject(value) || isArray(value);
if (scope) {
key = scope + '[' + (plain || hash ? key : '') + ']';
}
if (!scope && array) {
params.add(value.name, value.value);
} else if (hash) {
serialize(params, value, key);
} else {
params.add(key, value);
}
});
}
function xdrClient (request) {
return new Promise$1(function (resolve) {
var xdr = new XDomainRequest(),
handler = function (event) {
var response = request.respondWith(xdr.responseText, {
status: xdr.status,
statusText: xdr.statusText
});
resolve(response);
};
request.abort = function () {
return xdr.abort();
};
xdr.open(request.method, request.getUrl(), true);
xdr.timeout = 0;
xdr.onload = handler;
xdr.onerror = handler;
xdr.ontimeout = function () {};
xdr.onprogress = function () {};
xdr.send(request.getBody());
});
}
var ORIGIN_URL = Url.parse(location.href);
var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
function cors (request, next) {
if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
request.crossOrigin = true;
}
if (request.crossOrigin) {
if (!SUPPORTS_CORS) {
request.client = xdrClient;
}
delete request.emulateHTTP;
}
next();
}
function crossOrigin(request) {
var requestUrl = Url.parse(Url(request));
return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host;
}
function body (request, next) {
if (request.emulateJSON && isPlainObject(request.body)) {
request.body = Url.params(request.body);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
if (isFormData(request.body)) {
delete request.headers['Content-Type'];
}
if (isPlainObject(request.body)) {
request.body = JSON.stringify(request.body);
}
next(function (response) {
var contentType = response.headers['Content-Type'];
if (isString(contentType) && contentType.indexOf('application/json') === 0) {
try {
response.data = response.json();
} catch (e) {
response.data = null;
}
} else {
response.data = response.text();
}
});
}
function jsonpClient (request) {
return new Promise$1(function (resolve) {
var name = request.jsonp || 'callback',
callback = '_jsonp' + Math.random().toString(36).substr(2),
body = null,
handler,
script;
handler = function (event) {
var status = 0;
if (event.type === 'load' && body !== null) {
status = 200;
} else if (event.type === 'error') {
status = 404;
}
resolve(request.respondWith(body, { status: status }));
delete window[callback];
document.body.removeChild(script);
};
request.params[name] = callback;
window[callback] = function (result) {
body = JSON.stringify(result);
};
script = document.createElement('script');
script.src = request.getUrl();
script.type = 'text/javascript';
script.async = true;
script.onload = handler;
script.onerror = handler;
document.body.appendChild(script);
});
}
function jsonp (request, next) {
if (request.method == 'JSONP') {
request.client = jsonpClient;
}
next(function (response) {
if (request.method == 'JSONP') {
response.data = response.json();
}
});
}
function before (request, next) {
if (isFunction(request.before)) {
request.before.call(this, request);
}
next();
}
/**
* HTTP method override Interceptor.
*/
function method (request, next) {
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
request.headers['X-HTTP-Method-Override'] = request.method;
request.method = 'POST';
}
next();
}
function header (request, next) {
request.method = request.method.toUpperCase();
request.headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[request.method.toLowerCase()], request.headers);
next();
}
/**
* Timeout Interceptor.
*/
function timeout (request, next) {
var timeout;
if (request.timeout) {
timeout = setTimeout(function () {
request.abort();
}, request.timeout);
}
next(function (response) {
clearTimeout(timeout);
});
}
function xhrClient (request) {
return new Promise$1(function (resolve) {
var xhr = new XMLHttpRequest(),
handler = function (event) {
var response = request.respondWith('response' in xhr ? xhr.response : xhr.responseText, {
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText),
headers: parseHeaders(xhr.getAllResponseHeaders())
});
resolve(response);
};
request.abort = function () {
return xhr.abort();
};
xhr.open(request.method, request.getUrl(), true);
xhr.timeout = 0;
xhr.onload = handler;
xhr.onerror = handler;
if (request.progress) {
if (request.method === 'GET') {
xhr.addEventListener('progress', request.progress);
} else if (/^(POST|PUT)$/i.test(request.method)) {
xhr.upload.addEventListener('progress', request.progress);
}
}
if (request.credentials === true) {
xhr.withCredentials = true;
}
each(request.headers || {}, function (value, header) {
xhr.setRequestHeader(header, value);
});
xhr.send(request.getBody());
});
}
function parseHeaders(str) {
var headers = {},
value,
name,
i;
each(trim(str).split('\n'), function (row) {
i = row.indexOf(':');
name = trim(row.slice(0, i));
value = trim(row.slice(i + 1));
if (headers[name]) {
if (isArray(headers[name])) {
headers[name].push(value);
} else {
headers[name] = [headers[name], value];
}
} else {
headers[name] = value;
}
});
return headers;
}
function Client (context) {
var reqHandlers = [sendRequest],
resHandlers = [],
handler;
if (!isObject(context)) {
context = null;
}
function Client(request) {
return new Promise$1(function (resolve) {
function exec() {
handler = reqHandlers.pop();
if (isFunction(handler)) {
handler.call(context, request, next);
} else {
warn('Invalid interceptor of type ' + typeof handler + ', must be a function');
next();
}
}
function next(response) {
if (isFunction(response)) {
resHandlers.unshift(response);
} else if (isObject(response)) {
resHandlers.forEach(function (handler) {
response = when(response, function (response) {
return handler.call(context, response) || response;
});
});
when(response, resolve);
return;
}
exec();
}
exec();
}, context);
}
Client.use = function (handler) {
reqHandlers.push(handler);
};
return Client;
}
function sendRequest(request, resolve) {
var client = request.client || xhrClient;
resolve(client(request));
}
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
/**
* HTTP Response.
*/
var Response = function () {
function Response(body, _ref) {
var url = _ref.url;
var headers = _ref.headers;
var status = _ref.status;
var statusText = _ref.statusText;
classCallCheck(this, Response);
this.url = url;
this.body = body;
this.headers = headers || {};
this.status = status || 0;
this.statusText = statusText || '';
this.ok = status >= 200 && status < 300;
}
Response.prototype.text = function text() {
return this.body;
};
Response.prototype.blob = function blob() {
return new Blob([this.body]);
};
Response.prototype.json = function json() {
return JSON.parse(this.body);
};
return Response;
}();
var Request = function () {
function Request(options) {
classCallCheck(this, Request);
this.method = 'GET';
this.body = null;
this.params = {};
this.headers = {};
assign(this, options);
}
Request.prototype.getUrl = function getUrl() {
return Url(this);
};
Request.prototype.getBody = function getBody() {
return this.body;
};
Request.prototype.respondWith = function respondWith(body, options) {
return new Response(body, assign(options || {}, { url: this.getUrl() }));
};
return Request;
}();
/**
* Service for sending network requests.
*/
var CUSTOM_HEADERS = { 'X-Requested-With': 'XMLHttpRequest' };
var COMMON_HEADERS = { 'Accept': 'application/json, text/plain, */*' };
var JSON_CONTENT_TYPE = { 'Content-Type': 'application/json;charset=utf-8' };
function Http(options) {
var self = this || {},
client = Client(self.$vm);
defaults(options || {}, self.$options, Http.options);
Http.interceptors.forEach(function (handler) {
client.use(handler);
});
return client(new Request(options)).then(function (response) {
return response.ok ? response : Promise$1.reject(response);
}, function (response) {
if (response instanceof Error) {
error(response);
}
return Promise$1.reject(response);
});
}
Http.options = {};
Http.headers = {
put: JSON_CONTENT_TYPE,
post: JSON_CONTENT_TYPE,
patch: JSON_CONTENT_TYPE,
delete: JSON_CONTENT_TYPE,
custom: CUSTOM_HEADERS,
common: COMMON_HEADERS
};
Http.interceptors = [before, timeout, method, body, jsonp, header, cors];
['get', 'delete', 'head', 'jsonp'].forEach(function (method) {
Http[method] = function (url, options) {
return this(assign(options || {}, { url: url, method: method }));
};
});
['post', 'put', 'patch'].forEach(function (method) {
Http[method] = function (url, body, options) {
return this(assign(options || {}, { url: url, method: method, body: body }));
};
});
function Resource(url, params, actions, options) {
var self = this || {},
resource = {};
actions = assign({}, Resource.actions, actions);
each(actions, function (action, name) {
action = merge({ url: url, params: params || {} }, options, action);
resource[name] = function () {
return (self.$http || Http)(opts(action, arguments));
};
});
return resource;
}
function opts(action, args) {
var options = assign({}, action),
params = {},
body;
switch (args.length) {
case 2:
params = args[0];
body = args[1];
break;
case 1:
if (/^(POST|PUT|PATCH)$/i.test(options.method)) {
body = args[0];
} else {
params = args[0];
}
break;
case 0:
break;
default:
throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments';
}
options.body = body;
options.params = assign({}, options.params, params);
return options;
}
Resource.actions = {
get: { method: 'GET' },
save: { method: 'POST' },
query: { method: 'GET' },
update: { method: 'PUT' },
remove: { method: 'DELETE' },
delete: { method: 'DELETE' }
};
function plugin(Vue) {
if (plugin.installed) {
return;
}
Util(Vue);
Vue.url = Url;
Vue.http = Http;
Vue.resource = Resource;
Vue.Promise = Promise$1;
Object.defineProperties(Vue.prototype, {
$url: {
get: function () {
return options(Vue.url, this, this.$options.url);
}
},
$http: {
get: function () {
return options(Vue.http, this, this.$options.http);
}
},
$resource: {
get: function () {
return Vue.resource.bind(this);
}
},
$promise: {
get: function () {
var _this = this;
return function (executor) {
return new Vue.Promise(executor, _this);
};
}
}
});
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin);
}
return plugin;
}));
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment