-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
1 lines (1 loc) · 2.5 KB
/
index.min.js
1
Tny("http").provider("$$httpErrorHandler",function(){function t(t){console.log(t.status)}return{set:function(e){t=e||Tny.noop},get:function(){return t}}}),Tny("http").provider("$$httpHeaders",function(){var t={};return{setHeader:function(e,r){t[e]=r},getHeaders:function(){return t}}}),Tny("http").provider("$$httpInterceptors",function(){function t(t){if(!t.pre&&!t.post)throw'HTTP interceptors must have at least one "pre" or "post" function'}var e={};return{getInterceptors:function(){return e},addInterceptor:function(r,n){t(n),e[r]=n},removeInterceptor:function(t){delete e[t]}}}),Tny("http").factory("$httpJsonInterceptor",["$$httpInterceptors",function(t){function e(t,e){"JSON"===t.dataType.toUpperCase()&&"GET"!==t.method&&(e.setRequestHeader("Content-type","application/json;charset=utf-8"),t.data=JSON.stringify(t.data))}function r(t,e,r){var n;if("JSON"===e.dataType.toUpperCase())try{n=JSON.parse(t)}catch(o){}return n||t}return function(){t.addInterceptor("jsonDataTypeFormatter",{pre:e,post:r})}}]),Tny("http").service("$http",["$$httpHeaders","$$httpInterceptors","$$httpErrorHandler",function(t,e,r){function n(){if("undefined"!=typeof XMLHttpRequest)return new XMLHttpRequest;for(var t,e=["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"],r=0;r<e.length;r++)try{t=new ActiveXObject(e[r]);break}catch(n){}return t}function o(t,e){if(!e)return t;var r=[];for(var n in e)r.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t+(r.length?"?"+r.join("&"):"")}function a(t,e){if(e)for(key in e)e.hasOwnProperty(key)&&t.setRequestHeader(key,e[key])}function p(t,r){var n=e.getInterceptors();for(var o in n)n[o].pre(t,r)}function c(t,r){var n=e.getInterceptors(),o=r.responseText;for(var a in n)o=n[a].post(o,t,r)||o;t.callback(o,r)}function i(t,e){e.onreadystatechange=function(){if(4==e.readyState)if(e.status>=200&&e.status<207)c(t,e);else{var n=t.error(e);n!==!1&&r.get()(e)}}}this.send=function(e){var r={},c={callback:Tny.noop,error:Tny.noop,method:"GET",data:"",async:!0,dataType:"JSON",headers:{}};if(r.callback=e.callback||c.callback,r.error=e.error||c.error,r.method=e.method||c.method,r.data=e.data||c.data,r.async=e.async||c.async,r.dataType=e.dataType||c.dataType,r.headers=e.headers||c.headers,r.url=e.url,!r.url)throw"HTTP requires URL";"GET"==r.method&&(r.url=o(r.url,r.data));var s=n();s.open(r.method,r.url,r.async),p(r,s),a(t.getHeaders()),a(r.headers),i(r,s),s.send(r.data)}}]),Tny("http").run(["$httpJsonInterceptor",function(t){t()}]);